Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Deadlock in RCTi18nUtil (iOS) #733

Merged
merged 6 commits into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions React/Modules/RCTI18nUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,21 @@
+ (instancetype)sharedInstance;

- (BOOL)isRTL;
- (BOOL)isRTLAllowed;
- (void)allowRTL:(BOOL)value;
- (BOOL)isRTLForced;
- (void)forceRTL:(BOOL)value;
- (BOOL)doLeftAndRightSwapInRTL;
- (void)swapLeftAndRightInRTL:(BOOL)value;

/**
* Should be used very early during app start up
* Before the bridge is initialized
*/
@property(atomic, setter=allowRTL:) BOOL isRTLAllowed;

/**
* Could be used to test RTL layout with English
* Used for development and testing purpose
*/
@property(atomic, setter=forceRTL:) BOOL isRTLForced;

@property(atomic, setter=swapLeftAndRightInRTL:) BOOL doLeftAndRightSwapInRTL;



@end
48 changes: 1 addition & 47 deletions React/Modules/RCTI18nUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ + (instancetype)sharedInstance
dispatch_once(&onceToken, ^{
sharedInstance = [self new];
[sharedInstance swapLeftAndRightInRTL:true];
[sharedInstance allowRTL:true];
});

return sharedInstance;
Expand All @@ -40,53 +41,6 @@ - (BOOL)isRTL
return NO;
}

/**
* Should be used very early during app start up
* Before the bridge is initialized
* @return whether the app allows RTL layout, default is true
*/
- (BOOL)isRTLAllowed
{
NSNumber *value = [[NSUserDefaults standardUserDefaults] objectForKey:@"RCTI18nUtil_allowRTL"];
if (value == nil) {
return YES;
}
return [value boolValue];
}

- (void)allowRTL:(BOOL)rtlStatus
{
[[NSUserDefaults standardUserDefaults] setBool:rtlStatus forKey:@"RCTI18nUtil_allowRTL"];
[[NSUserDefaults standardUserDefaults] synchronize];
}

/**
* Could be used to test RTL layout with English
* Used for development and testing purpose
*/
- (BOOL)isRTLForced
{
BOOL rtlStatus = [[NSUserDefaults standardUserDefaults] boolForKey:@"RCTI18nUtil_forceRTL"];
return rtlStatus;
}

- (void)forceRTL:(BOOL)rtlStatus
{
[[NSUserDefaults standardUserDefaults] setBool:rtlStatus forKey:@"RCTI18nUtil_forceRTL"];
[[NSUserDefaults standardUserDefaults] synchronize];
}

- (BOOL)doLeftAndRightSwapInRTL
{
return [[NSUserDefaults standardUserDefaults] boolForKey:@"RCTI18nUtil_makeRTLFlipLeftAndRightStyles"];
}

- (void)swapLeftAndRightInRTL:(BOOL)value
{
[[NSUserDefaults standardUserDefaults] setBool:value forKey:@"RCTI18nUtil_makeRTLFlipLeftAndRightStyles"];
[[NSUserDefaults standardUserDefaults] synchronize];
}

// Check if the current device language is RTL
- (BOOL)isDevicePreferredLanguageRTL
{
Expand Down