diff --git a/React/Modules/RCTI18nUtil.h b/React/Modules/RCTI18nUtil.h index 79828eb74958a1..f3a1550e5ec778 100644 --- a/React/Modules/RCTI18nUtil.h +++ b/React/Modules/RCTI18nUtil.h @@ -18,19 +18,11 @@ + (instancetype)sharedInstance; - (BOOL)isRTL; - -/** - * 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; +- (BOOL)isRTLAllowed; +- (void)allowRTL:(BOOL)value; +- (BOOL)isRTLForced; +- (void)forceRTL:(BOOL)value; +- (BOOL)doLeftAndRightSwapInRTL; +- (void)swapLeftAndRightInRTL:(BOOL)value; @end diff --git a/React/Modules/RCTI18nUtil.m b/React/Modules/RCTI18nUtil.m index 17207d053635d3..eb26f7fe23e68d 100644 --- a/React/Modules/RCTI18nUtil.m +++ b/React/Modules/RCTI18nUtil.m @@ -18,7 +18,6 @@ + (instancetype)sharedInstance dispatch_once(&onceToken, ^{ sharedInstance = [self new]; [sharedInstance swapLeftAndRightInRTL:true]; - [sharedInstance allowRTL:true]; }); return sharedInstance; @@ -41,6 +40,53 @@ - (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 {