Skip to content

Commit 70ddf46

Browse files
Saadnajmifacebook-github-bot
authored andcommitted
Revert "Fix Deadlock in RCTi18nUtil (iOS) (#31032)" (#32574)
Summary: This reverts commit fcead14. This should close #32509 . There was a bug where il8nManager.forceRTL() wouldn't work on app launch, and required an app restart. That was caused by an earlier change (#31032) which should not be necessary (the deadlock it was attempting to fix was actually caused by separate code). ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [iOS] [Fixed] - Fixed bug where forceRTL did not work on app launch Pull Request resolved: #32574 Test Plan: Simple revert back to previously working code. Reviewed By: RSNara Differential Revision: D32315034 Pulled By: GijsWeterings fbshipit-source-id: dae6c1f0a2481e53f2f1e80f1ac083947681ef99
1 parent c180627 commit 70ddf46

File tree

2 files changed

+53
-15
lines changed

2 files changed

+53
-15
lines changed

React/Modules/RCTI18nUtil.h

+6-14
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,11 @@
1818
+ (instancetype)sharedInstance;
1919

2020
- (BOOL)isRTL;
21-
22-
/**
23-
* Should be used very early during app start up
24-
* Before the bridge is initialized
25-
*/
26-
@property (atomic, setter=allowRTL:) BOOL isRTLAllowed;
27-
28-
/**
29-
* Could be used to test RTL layout with English
30-
* Used for development and testing purpose
31-
*/
32-
@property (atomic, setter=forceRTL:) BOOL isRTLForced;
33-
34-
@property (atomic, setter=swapLeftAndRightInRTL:) BOOL doLeftAndRightSwapInRTL;
21+
- (BOOL)isRTLAllowed;
22+
- (void)allowRTL:(BOOL)value;
23+
- (BOOL)isRTLForced;
24+
- (void)forceRTL:(BOOL)value;
25+
- (BOOL)doLeftAndRightSwapInRTL;
26+
- (void)swapLeftAndRightInRTL:(BOOL)value;
3527

3628
@end

React/Modules/RCTI18nUtil.m

+47-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ + (instancetype)sharedInstance
1818
dispatch_once(&onceToken, ^{
1919
sharedInstance = [self new];
2020
[sharedInstance swapLeftAndRightInRTL:true];
21-
[sharedInstance allowRTL:true];
2221
});
2322

2423
return sharedInstance;
@@ -41,6 +40,53 @@ - (BOOL)isRTL
4140
return NO;
4241
}
4342

43+
/**
44+
* Should be used very early during app start up
45+
* Before the bridge is initialized
46+
* @return whether the app allows RTL layout, default is true
47+
*/
48+
- (BOOL)isRTLAllowed
49+
{
50+
NSNumber *value = [[NSUserDefaults standardUserDefaults] objectForKey:@"RCTI18nUtil_allowRTL"];
51+
if (value == nil) {
52+
return YES;
53+
}
54+
return [value boolValue];
55+
}
56+
57+
- (void)allowRTL:(BOOL)rtlStatus
58+
{
59+
[[NSUserDefaults standardUserDefaults] setBool:rtlStatus forKey:@"RCTI18nUtil_allowRTL"];
60+
[[NSUserDefaults standardUserDefaults] synchronize];
61+
}
62+
63+
/**
64+
* Could be used to test RTL layout with English
65+
* Used for development and testing purpose
66+
*/
67+
- (BOOL)isRTLForced
68+
{
69+
BOOL rtlStatus = [[NSUserDefaults standardUserDefaults] boolForKey:@"RCTI18nUtil_forceRTL"];
70+
return rtlStatus;
71+
}
72+
73+
- (void)forceRTL:(BOOL)rtlStatus
74+
{
75+
[[NSUserDefaults standardUserDefaults] setBool:rtlStatus forKey:@"RCTI18nUtil_forceRTL"];
76+
[[NSUserDefaults standardUserDefaults] synchronize];
77+
}
78+
79+
- (BOOL)doLeftAndRightSwapInRTL
80+
{
81+
return [[NSUserDefaults standardUserDefaults] boolForKey:@"RCTI18nUtil_makeRTLFlipLeftAndRightStyles"];
82+
}
83+
84+
- (void)swapLeftAndRightInRTL:(BOOL)value
85+
{
86+
[[NSUserDefaults standardUserDefaults] setBool:value forKey:@"RCTI18nUtil_makeRTLFlipLeftAndRightStyles"];
87+
[[NSUserDefaults standardUserDefaults] synchronize];
88+
}
89+
4490
// Check if the current device language is RTL
4591
- (BOOL)isDevicePreferredLanguageRTL
4692
{

0 commit comments

Comments
 (0)