Implement gating support for direction-aware API changes
Reviewed By: achen1 Differential Revision: D6045083 fbshipit-source-id: 857a43029ad88d2324ec77145a1e30d92b5e8fae
This commit is contained in:
parent
f7888310d4
commit
98547d4bcf
|
@ -14,14 +14,18 @@
|
||||||
|
|
||||||
type I18nManagerStatus = {
|
type I18nManagerStatus = {
|
||||||
isRTL: boolean,
|
isRTL: boolean,
|
||||||
|
doesRTLFlipLeftAndRightStyles: boolean,
|
||||||
allowRTL: (allowRTL: boolean) => {},
|
allowRTL: (allowRTL: boolean) => {},
|
||||||
forceRTL: (forceRTL: boolean) => {},
|
forceRTL: (forceRTL: boolean) => {},
|
||||||
|
makeRTLFlipLeftAndRightStyles: (flipStyles: boolean) => {},
|
||||||
};
|
};
|
||||||
|
|
||||||
const I18nManager: I18nManagerStatus = require('NativeModules').I18nManager || {
|
const I18nManager: I18nManagerStatus = require('NativeModules').I18nManager || {
|
||||||
isRTL: false,
|
isRTL: false,
|
||||||
|
doesRTLFlipLeftAndRightStyles: true,
|
||||||
allowRTL: () => {},
|
allowRTL: () => {},
|
||||||
forceRTL: () => {},
|
forceRTL: () => {},
|
||||||
|
makeRTLFlipLeftAndRightStyles: () => {},
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = I18nManager;
|
module.exports = I18nManager;
|
||||||
|
|
|
@ -29,10 +29,16 @@ RCT_EXPORT_METHOD(forceRTL:(BOOL)value)
|
||||||
[[RCTI18nUtil sharedInstance] forceRTL:value];
|
[[RCTI18nUtil sharedInstance] forceRTL:value];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RCT_EXPORT_METHOD(makeRTLFlipLeftAndRightStyles:(BOOL)value)
|
||||||
|
{
|
||||||
|
[[RCTI18nUtil sharedInstance] makeRTLFlipLeftAndRightStyles:value];
|
||||||
|
}
|
||||||
|
|
||||||
- (NSDictionary *)constantsToExport
|
- (NSDictionary *)constantsToExport
|
||||||
{
|
{
|
||||||
return @{
|
return @{
|
||||||
@"isRTL": @([[RCTI18nUtil sharedInstance] isRTL])
|
@"isRTL": @([[RCTI18nUtil sharedInstance] isRTL]),
|
||||||
|
@"doesRTLFlipLeftAndRightStyles": @([[RCTI18nUtil sharedInstance] doesRTLFlipLeftAndRightStyles])
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,5 +24,7 @@
|
||||||
- (void)allowRTL:(BOOL)value;
|
- (void)allowRTL:(BOOL)value;
|
||||||
- (BOOL)isRTLForced;
|
- (BOOL)isRTLForced;
|
||||||
- (void)forceRTL:(BOOL)value;
|
- (void)forceRTL:(BOOL)value;
|
||||||
|
- (BOOL)doesRTLFlipLeftAndRightStyles;
|
||||||
|
- (void)makeRTLFlipLeftAndRightStyles:(BOOL)value;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
static dispatch_once_t onceToken;
|
static dispatch_once_t onceToken;
|
||||||
dispatch_once(&onceToken, ^{
|
dispatch_once(&onceToken, ^{
|
||||||
sharedInstance = [self new];
|
sharedInstance = [self new];
|
||||||
|
[sharedInstance makeRTLFlipLeftAndRightStyles: true];
|
||||||
});
|
});
|
||||||
|
|
||||||
return sharedInstance;
|
return sharedInstance;
|
||||||
|
@ -78,6 +79,17 @@
|
||||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL)doesRTLFlipLeftAndRightStyles
|
||||||
|
{
|
||||||
|
return [[NSUserDefaults standardUserDefaults] boolForKey:@"RCTI18nUtil_makeRTLFlipLeftAndRightStyles"];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)makeRTLFlipLeftAndRightStyles:(BOOL)value
|
||||||
|
{
|
||||||
|
[[NSUserDefaults standardUserDefaults] setBool:value forKey:@"RCTI18nUtil_makeRTLFlipLeftAndRightStyles"];
|
||||||
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||||
|
}
|
||||||
|
|
||||||
// Check if the current device language is RTL
|
// Check if the current device language is RTL
|
||||||
- (BOOL)isDevicePreferredLanguageRTL
|
- (BOOL)isDevicePreferredLanguageRTL
|
||||||
{
|
{
|
||||||
|
|
|
@ -45,6 +45,7 @@ public class I18nManagerModule extends ContextBaseJavaModule {
|
||||||
|
|
||||||
final Map<String, Object> constants = MapBuilder.newHashMap();
|
final Map<String, Object> constants = MapBuilder.newHashMap();
|
||||||
constants.put("isRTL", sharedI18nUtilInstance.isRTL(context));
|
constants.put("isRTL", sharedI18nUtilInstance.isRTL(context));
|
||||||
|
constants.put("doesRTLFlipLeftAndRightStyles", sharedI18nUtilInstance.doesRTLFlipLeftAndRightStyles(context));
|
||||||
constants.put("localeIdentifier", locale.toString());
|
constants.put("localeIdentifier", locale.toString());
|
||||||
return constants;
|
return constants;
|
||||||
}
|
}
|
||||||
|
@ -58,4 +59,9 @@ public class I18nManagerModule extends ContextBaseJavaModule {
|
||||||
public void forceRTL(boolean value) {
|
public void forceRTL(boolean value) {
|
||||||
sharedI18nUtilInstance.forceRTL(getContext(), value);
|
sharedI18nUtilInstance.forceRTL(getContext(), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ReactMethod
|
||||||
|
public void makeRTLFlipLeftAndRightStyles(boolean value) {
|
||||||
|
sharedI18nUtilInstance.makeRTLFlipLeftAndRightStyles(getContext(), value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,8 @@ public class I18nUtil {
|
||||||
"RCTI18nUtil_allowRTL";
|
"RCTI18nUtil_allowRTL";
|
||||||
private static final String KEY_FOR_PREFS_FORCERTL =
|
private static final String KEY_FOR_PREFS_FORCERTL =
|
||||||
"RCTI18nUtil_forceRTL";
|
"RCTI18nUtil_forceRTL";
|
||||||
|
private static final String KEY_FOR_PERFS_MAKE_RTL_FLIP_LEFT_AND_RIGHT_STYLES =
|
||||||
|
"RCTI18nUtil_makeRTLFlipLeftAndRightStyles";
|
||||||
|
|
||||||
private I18nUtil() {
|
private I18nUtil() {
|
||||||
// Exists only to defeat instantiation.
|
// Exists only to defeat instantiation.
|
||||||
|
@ -65,6 +67,14 @@ public class I18nUtil {
|
||||||
setPref(context, KEY_FOR_PREFS_ALLOWRTL, allowRTL);
|
setPref(context, KEY_FOR_PREFS_ALLOWRTL, allowRTL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean doesRTLFlipLeftAndRightStyles(Context context) {
|
||||||
|
return isPrefSet(context, KEY_FOR_PERFS_MAKE_RTL_FLIP_LEFT_AND_RIGHT_STYLES, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void makeRTLFlipLeftAndRightStyles(Context context, boolean flip) {
|
||||||
|
setPref(context, KEY_FOR_PERFS_MAKE_RTL_FLIP_LEFT_AND_RIGHT_STYLES, flip);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Could be used to test RTL layout with English
|
* Could be used to test RTL layout with English
|
||||||
* Used for development and testing purpose
|
* Used for development and testing purpose
|
||||||
|
|
Loading…
Reference in New Issue