From ef30ff33ed1a7f6306ad6d6d6fd34106a206dc6f Mon Sep 17 00:00:00 2001 From: Saad Najmi Date: Fri, 26 Feb 2021 11:39:00 -0600 Subject: [PATCH] Fix Deadlock in RCTi18nUtil (iOS) (#733) * Initial Commit * Fix typo * Fix default initialization of isRTLAllowed and documentation * use BOOL, remove superfluous readwrite decorator * Fix another typo * Add TODO Marker --- React/Modules/RCTI18nUtil.h | 21 ++++++++++----- React/Modules/RCTI18nUtil.m | 51 ++----------------------------------- 2 files changed, 17 insertions(+), 55 deletions(-) diff --git a/React/Modules/RCTI18nUtil.h b/React/Modules/RCTI18nUtil.h index f3a1550e5ec778..79e2f5ba2643e7 100644 --- a/React/Modules/RCTI18nUtil.h +++ b/React/Modules/RCTI18nUtil.h @@ -18,11 +18,20 @@ + (instancetype)sharedInstance; - (BOOL)isRTL; -- (BOOL)isRTLAllowed; -- (void)allowRTL:(BOOL)value; -- (BOOL)isRTLForced; -- (void)forceRTL:(BOOL)value; -- (BOOL)doLeftAndRightSwapInRTL; -- (void)swapLeftAndRightInRTL:(BOOL)value; +// [ TODO(macOS#4904077) +/** + * 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; +// ]TODO(macOS#4904077) @end diff --git a/React/Modules/RCTI18nUtil.m b/React/Modules/RCTI18nUtil.m index d5c1a2080d195f..9f426d26836b94 100644 --- a/React/Modules/RCTI18nUtil.m +++ b/React/Modules/RCTI18nUtil.m @@ -17,7 +17,8 @@ + (instancetype)sharedInstance static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ sharedInstance = [self new]; - [sharedInstance swapLeftAndRightInRTL: true]; + [sharedInstance swapLeftAndRightInRTL:true]; + [sharedInstance allowRTL:true]; // TODO(macOS#4904077) }); return sharedInstance; @@ -40,54 +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 {