Skip to content

Commit 98547d4

Browse files
RSNarafacebook-github-bot
authored andcommitted
Implement gating support for direction-aware API changes
Reviewed By: achen1 Differential Revision: D6045083 fbshipit-source-id: 857a43029ad88d2324ec77145a1e30d92b5e8fae
1 parent f788831 commit 98547d4

File tree

6 files changed

+41
-1
lines changed

6 files changed

+41
-1
lines changed

Libraries/ReactNative/I18nManager.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@
1414

1515
type I18nManagerStatus = {
1616
isRTL: boolean,
17+
doesRTLFlipLeftAndRightStyles: boolean,
1718
allowRTL: (allowRTL: boolean) => {},
1819
forceRTL: (forceRTL: boolean) => {},
20+
makeRTLFlipLeftAndRightStyles: (flipStyles: boolean) => {},
1921
};
2022

2123
const I18nManager: I18nManagerStatus = require('NativeModules').I18nManager || {
2224
isRTL: false,
25+
doesRTLFlipLeftAndRightStyles: true,
2326
allowRTL: () => {},
2427
forceRTL: () => {},
28+
makeRTLFlipLeftAndRightStyles: () => {},
2529
};
2630

2731
module.exports = I18nManager;

React/Modules/RCTI18nManager.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,16 @@ + (BOOL)requiresMainQueueSetup
2929
[[RCTI18nUtil sharedInstance] forceRTL:value];
3030
}
3131

32+
RCT_EXPORT_METHOD(makeRTLFlipLeftAndRightStyles:(BOOL)value)
33+
{
34+
[[RCTI18nUtil sharedInstance] makeRTLFlipLeftAndRightStyles:value];
35+
}
36+
3237
- (NSDictionary *)constantsToExport
3338
{
3439
return @{
35-
@"isRTL": @([[RCTI18nUtil sharedInstance] isRTL])
40+
@"isRTL": @([[RCTI18nUtil sharedInstance] isRTL]),
41+
@"doesRTLFlipLeftAndRightStyles": @([[RCTI18nUtil sharedInstance] doesRTLFlipLeftAndRightStyles])
3642
};
3743
}
3844

React/Modules/RCTI18nUtil.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,7 @@
2424
- (void)allowRTL:(BOOL)value;
2525
- (BOOL)isRTLForced;
2626
- (void)forceRTL:(BOOL)value;
27+
- (BOOL)doesRTLFlipLeftAndRightStyles;
28+
- (void)makeRTLFlipLeftAndRightStyles:(BOOL)value;
2729

2830
@end

React/Modules/RCTI18nUtil.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ + (instancetype)sharedInstance
1919
static dispatch_once_t onceToken;
2020
dispatch_once(&onceToken, ^{
2121
sharedInstance = [self new];
22+
[sharedInstance makeRTLFlipLeftAndRightStyles: true];
2223
});
2324

2425
return sharedInstance;
@@ -78,6 +79,17 @@ - (void)forceRTL:(BOOL)rtlStatus
7879
[[NSUserDefaults standardUserDefaults] synchronize];
7980
}
8081

82+
- (BOOL)doesRTLFlipLeftAndRightStyles
83+
{
84+
return [[NSUserDefaults standardUserDefaults] boolForKey:@"RCTI18nUtil_makeRTLFlipLeftAndRightStyles"];
85+
}
86+
87+
- (void)makeRTLFlipLeftAndRightStyles:(BOOL)value
88+
{
89+
[[NSUserDefaults standardUserDefaults] setBool:value forKey:@"RCTI18nUtil_makeRTLFlipLeftAndRightStyles"];
90+
[[NSUserDefaults standardUserDefaults] synchronize];
91+
}
92+
8193
// Check if the current device language is RTL
8294
- (BOOL)isDevicePreferredLanguageRTL
8395
{

ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nManagerModule.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public Map<String, Object> getConstants() {
4545

4646
final Map<String, Object> constants = MapBuilder.newHashMap();
4747
constants.put("isRTL", sharedI18nUtilInstance.isRTL(context));
48+
constants.put("doesRTLFlipLeftAndRightStyles", sharedI18nUtilInstance.doesRTLFlipLeftAndRightStyles(context));
4849
constants.put("localeIdentifier", locale.toString());
4950
return constants;
5051
}
@@ -58,4 +59,9 @@ public void allowRTL(boolean value) {
5859
public void forceRTL(boolean value) {
5960
sharedI18nUtilInstance.forceRTL(getContext(), value);
6061
}
62+
63+
@ReactMethod
64+
public void makeRTLFlipLeftAndRightStyles(boolean value) {
65+
sharedI18nUtilInstance.makeRTLFlipLeftAndRightStyles(getContext(), value);
66+
}
6167
}

ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nUtil.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public class I18nUtil {
2626
"RCTI18nUtil_allowRTL";
2727
private static final String KEY_FOR_PREFS_FORCERTL =
2828
"RCTI18nUtil_forceRTL";
29+
private static final String KEY_FOR_PERFS_MAKE_RTL_FLIP_LEFT_AND_RIGHT_STYLES =
30+
"RCTI18nUtil_makeRTLFlipLeftAndRightStyles";
2931

3032
private I18nUtil() {
3133
// Exists only to defeat instantiation.
@@ -65,6 +67,14 @@ public void allowRTL(Context context, boolean allowRTL) {
6567
setPref(context, KEY_FOR_PREFS_ALLOWRTL, allowRTL);
6668
}
6769

70+
public boolean doesRTLFlipLeftAndRightStyles(Context context) {
71+
return isPrefSet(context, KEY_FOR_PERFS_MAKE_RTL_FLIP_LEFT_AND_RIGHT_STYLES, true);
72+
}
73+
74+
public void makeRTLFlipLeftAndRightStyles(Context context, boolean flip) {
75+
setPref(context, KEY_FOR_PERFS_MAKE_RTL_FLIP_LEFT_AND_RIGHT_STYLES, flip);
76+
}
77+
6878
/**
6979
* Could be used to test RTL layout with English
7080
* Used for development and testing purpose

0 commit comments

Comments
 (0)