Implement gating support for direction-aware API changes

Reviewed By: achen1

Differential Revision: D6045083

fbshipit-source-id: 857a43029ad88d2324ec77145a1e30d92b5e8fae
This commit is contained in:
Ramanpreet Nara
2017-10-18 19:29:36 -07:00
committed by Facebook Github Bot
parent f7888310d4
commit 98547d4bcf
6 changed files with 41 additions and 1 deletions

View File

@@ -45,6 +45,7 @@ public class I18nManagerModule extends ContextBaseJavaModule {
final Map<String, Object> constants = MapBuilder.newHashMap();
constants.put("isRTL", sharedI18nUtilInstance.isRTL(context));
constants.put("doesRTLFlipLeftAndRightStyles", sharedI18nUtilInstance.doesRTLFlipLeftAndRightStyles(context));
constants.put("localeIdentifier", locale.toString());
return constants;
}
@@ -58,4 +59,9 @@ public class I18nManagerModule extends ContextBaseJavaModule {
public void forceRTL(boolean value) {
sharedI18nUtilInstance.forceRTL(getContext(), value);
}
@ReactMethod
public void makeRTLFlipLeftAndRightStyles(boolean value) {
sharedI18nUtilInstance.makeRTLFlipLeftAndRightStyles(getContext(), value);
}
}

View File

@@ -26,6 +26,8 @@ public class I18nUtil {
"RCTI18nUtil_allowRTL";
private static final String KEY_FOR_PREFS_FORCERTL =
"RCTI18nUtil_forceRTL";
private static final String KEY_FOR_PERFS_MAKE_RTL_FLIP_LEFT_AND_RIGHT_STYLES =
"RCTI18nUtil_makeRTLFlipLeftAndRightStyles";
private I18nUtil() {
// Exists only to defeat instantiation.
@@ -65,6 +67,14 @@ public class I18nUtil {
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
* Used for development and testing purpose