From efa4d3c2228ac08712f1578c4a1411a1f51e137c Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Tue, 24 Oct 2017 20:32:17 -0700 Subject: [PATCH] Rename I18nManager Left/Right swap methods Reviewed By: fkgozali Differential Revision: D6140072 fbshipit-source-id: 282dc614c036de8f217a729f21a1bbe92b8afd7d --- Libraries/ReactNative/I18nManager.js | 8 ++++---- React/Modules/RCTI18nManager.m | 6 +++--- React/Modules/RCTI18nUtil.h | 4 ++-- React/Modules/RCTI18nUtil.m | 6 +++--- React/Views/RCTShadowView.m | 14 +++++++------- React/Views/RCTView.m | 6 +++--- .../modules/i18nmanager/I18nManagerModule.java | 10 ++++------ .../react/modules/i18nmanager/I18nUtil.java | 6 ++---- .../facebook/react/uimanager/LayoutShadowNode.java | 2 +- .../views/view/ReactViewBackgroundDrawable.java | 8 ++++---- .../facebook/react/views/view/ReactViewGroup.java | 2 +- 11 files changed, 34 insertions(+), 38 deletions(-) diff --git a/Libraries/ReactNative/I18nManager.js b/Libraries/ReactNative/I18nManager.js index e682e8a77be..7c6ad67a4e2 100644 --- a/Libraries/ReactNative/I18nManager.js +++ b/Libraries/ReactNative/I18nManager.js @@ -14,18 +14,18 @@ type I18nManagerStatus = { isRTL: boolean, - doesRTLFlipLeftAndRightStyles: boolean, + doLeftAndRightSwapInRTL: boolean, allowRTL: (allowRTL: boolean) => {}, forceRTL: (forceRTL: boolean) => {}, - makeRTLFlipLeftAndRightStyles: (flipStyles: boolean) => {}, + swapLeftAndRightInRTL: (flipStyles: boolean) => {}, }; const I18nManager: I18nManagerStatus = require('NativeModules').I18nManager || { isRTL: false, - doesRTLFlipLeftAndRightStyles: true, + doLeftAndRightSwapInRTL: true, allowRTL: () => {}, forceRTL: () => {}, - makeRTLFlipLeftAndRightStyles: () => {}, + swapLeftAndRightInRTL: () => {}, }; module.exports = I18nManager; diff --git a/React/Modules/RCTI18nManager.m b/React/Modules/RCTI18nManager.m index f5ba41f6d78..72e2ae3a29d 100644 --- a/React/Modules/RCTI18nManager.m +++ b/React/Modules/RCTI18nManager.m @@ -29,16 +29,16 @@ RCT_EXPORT_METHOD(forceRTL:(BOOL)value) [[RCTI18nUtil sharedInstance] forceRTL:value]; } -RCT_EXPORT_METHOD(makeRTLFlipLeftAndRightStyles:(BOOL)value) +RCT_EXPORT_METHOD(swapLeftAndRightInRTL:(BOOL)value) { - [[RCTI18nUtil sharedInstance] makeRTLFlipLeftAndRightStyles:value]; + [[RCTI18nUtil sharedInstance] swapLeftAndRightInRTL:value]; } - (NSDictionary *)constantsToExport { return @{ @"isRTL": @([[RCTI18nUtil sharedInstance] isRTL]), - @"doesRTLFlipLeftAndRightStyles": @([[RCTI18nUtil sharedInstance] doesRTLFlipLeftAndRightStyles]) + @"doLeftAndRightSwapInRTL": @([[RCTI18nUtil sharedInstance] doLeftAndRightSwapInRTL]) }; } diff --git a/React/Modules/RCTI18nUtil.h b/React/Modules/RCTI18nUtil.h index cdabbbed350..8157f4192ea 100644 --- a/React/Modules/RCTI18nUtil.h +++ b/React/Modules/RCTI18nUtil.h @@ -24,7 +24,7 @@ - (void)allowRTL:(BOOL)value; - (BOOL)isRTLForced; - (void)forceRTL:(BOOL)value; -- (BOOL)doesRTLFlipLeftAndRightStyles; -- (void)makeRTLFlipLeftAndRightStyles:(BOOL)value; +- (BOOL)doLeftAndRightSwapInRTL; +- (void)swapLeftAndRightInRTL:(BOOL)value; @end diff --git a/React/Modules/RCTI18nUtil.m b/React/Modules/RCTI18nUtil.m index 4c35d1c3fd1..9a6eb3b1f06 100644 --- a/React/Modules/RCTI18nUtil.m +++ b/React/Modules/RCTI18nUtil.m @@ -19,7 +19,7 @@ static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ sharedInstance = [self new]; - [sharedInstance makeRTLFlipLeftAndRightStyles: true]; + [sharedInstance swapLeftAndRightInRTL: true]; }); return sharedInstance; @@ -79,12 +79,12 @@ [[NSUserDefaults standardUserDefaults] synchronize]; } -- (BOOL)doesRTLFlipLeftAndRightStyles +- (BOOL)doLeftAndRightSwapInRTL { return [[NSUserDefaults standardUserDefaults] boolForKey:@"RCTI18nUtil_makeRTLFlipLeftAndRightStyles"]; } -- (void)makeRTLFlipLeftAndRightStyles:(BOOL)value +- (void)swapLeftAndRightInRTL:(BOOL)value { [[NSUserDefaults standardUserDefaults] setBool:value forKey:@"RCTI18nUtil_makeRTLFlipLeftAndRightStyles"]; [[NSUserDefaults standardUserDefaults] synchronize]; diff --git a/React/Views/RCTShadowView.m b/React/Views/RCTShadowView.m index 65789c48782..56c363f9657 100644 --- a/React/Views/RCTShadowView.m +++ b/React/Views/RCTShadowView.m @@ -103,7 +103,7 @@ switch (ygvalue.unit) { \ } static void RCTProcessMetaPropsPadding(const YGValue metaProps[META_PROP_COUNT], YGNodeRef node) { - if (![[RCTI18nUtil sharedInstance] doesRTLFlipLeftAndRightStyles]) { + if (![[RCTI18nUtil sharedInstance] doLeftAndRightSwapInRTL]) { RCT_SET_YGVALUE(metaProps[META_PROP_START], YGNodeStyleSetPadding, node, YGEdgeStart); RCT_SET_YGVALUE(metaProps[META_PROP_END], YGNodeStyleSetPadding, node, YGEdgeEnd); RCT_SET_YGVALUE(metaProps[META_PROP_LEFT], YGNodeStyleSetPadding, node, YGEdgeLeft); @@ -122,7 +122,7 @@ static void RCTProcessMetaPropsPadding(const YGValue metaProps[META_PROP_COUNT], } static void RCTProcessMetaPropsMargin(const YGValue metaProps[META_PROP_COUNT], YGNodeRef node) { - if (![[RCTI18nUtil sharedInstance] doesRTLFlipLeftAndRightStyles]) { + if (![[RCTI18nUtil sharedInstance] doLeftAndRightSwapInRTL]) { RCT_SET_YGVALUE_AUTO(metaProps[META_PROP_START], YGNodeStyleSetMargin, node, YGEdgeStart); RCT_SET_YGVALUE_AUTO(metaProps[META_PROP_END], YGNodeStyleSetMargin, node, YGEdgeEnd); RCT_SET_YGVALUE_AUTO(metaProps[META_PROP_LEFT], YGNodeStyleSetMargin, node, YGEdgeLeft); @@ -141,7 +141,7 @@ static void RCTProcessMetaPropsMargin(const YGValue metaProps[META_PROP_COUNT], } static void RCTProcessMetaPropsBorder(const YGValue metaProps[META_PROP_COUNT], YGNodeRef node) { - if (![[RCTI18nUtil sharedInstance] doesRTLFlipLeftAndRightStyles]) { + if (![[RCTI18nUtil sharedInstance] doLeftAndRightSwapInRTL]) { YGNodeStyleSetBorder(node, YGEdgeStart, metaProps[META_PROP_START].value); YGNodeStyleSetBorder(node, YGEdgeEnd, metaProps[META_PROP_END].value); YGNodeStyleSetBorder(node, YGEdgeLeft, metaProps[META_PROP_LEFT].value); @@ -644,25 +644,25 @@ RCT_POSITION_PROPERTY(End, end, YGEdgeEnd) - (void)setLeft:(YGValue)value { - YGEdge edge = [[RCTI18nUtil sharedInstance] doesRTLFlipLeftAndRightStyles] ? YGEdgeStart : YGEdgeLeft; + YGEdge edge = [[RCTI18nUtil sharedInstance] doLeftAndRightSwapInRTL] ? YGEdgeStart : YGEdgeLeft; RCT_SET_YGVALUE(value, YGNodeStyleSetPosition, _yogaNode, edge); [self dirtyText]; } - (YGValue)left { - YGEdge edge = [[RCTI18nUtil sharedInstance] doesRTLFlipLeftAndRightStyles] ? YGEdgeStart : YGEdgeLeft; + YGEdge edge = [[RCTI18nUtil sharedInstance] doLeftAndRightSwapInRTL] ? YGEdgeStart : YGEdgeLeft; return YGNodeStyleGetPosition(_yogaNode, edge); } - (void)setRight:(YGValue)value { - YGEdge edge = [[RCTI18nUtil sharedInstance] doesRTLFlipLeftAndRightStyles] ? YGEdgeEnd : YGEdgeRight; + YGEdge edge = [[RCTI18nUtil sharedInstance] doLeftAndRightSwapInRTL] ? YGEdgeEnd : YGEdgeRight; RCT_SET_YGVALUE(value, YGNodeStyleSetPosition, _yogaNode, edge); [self dirtyText]; } - (YGValue)right { - YGEdge edge = [[RCTI18nUtil sharedInstance] doesRTLFlipLeftAndRightStyles] ? YGEdgeEnd : YGEdgeRight; + YGEdge edge = [[RCTI18nUtil sharedInstance] doLeftAndRightSwapInRTL] ? YGEdgeEnd : YGEdgeRight; return YGNodeStyleGetPosition(_yogaNode, edge); } diff --git a/React/Views/RCTView.m b/React/Views/RCTView.m index 9559a36e39b..c14a6cd3ad7 100644 --- a/React/Views/RCTView.m +++ b/React/Views/RCTView.m @@ -443,7 +443,7 @@ static CGFloat RCTDefaultIfNegativeTo(CGFloat defaultValue, CGFloat x) { const CGFloat borderWidth = MAX(0, _borderWidth); const BOOL isRTL = _reactLayoutDirection == UIUserInterfaceLayoutDirectionRightToLeft; - if ([[RCTI18nUtil sharedInstance] doesRTLFlipLeftAndRightStyles]) { + if ([[RCTI18nUtil sharedInstance] doLeftAndRightSwapInRTL]) { const CGFloat borderStartWidth = RCTDefaultIfNegativeTo(_borderLeftWidth, _borderStartWidth); const CGFloat borderEndWidth = RCTDefaultIfNegativeTo(_borderRightWidth, _borderEndWidth); @@ -479,7 +479,7 @@ static CGFloat RCTDefaultIfNegativeTo(CGFloat defaultValue, CGFloat x) { CGFloat bottomLeftRadius; CGFloat bottomRightRadius; - if ([[RCTI18nUtil sharedInstance] doesRTLFlipLeftAndRightStyles]) { + if ([[RCTI18nUtil sharedInstance] doLeftAndRightSwapInRTL]) { const CGFloat topStartRadius = RCTDefaultIfNegativeTo(_borderTopLeftRadius, _borderTopStartRadius); const CGFloat topEndRadius = RCTDefaultIfNegativeTo(_borderTopRightRadius, _borderTopEndRadius); const CGFloat bottomStartRadius = RCTDefaultIfNegativeTo(_borderBottomLeftRadius, _borderBottomStartRadius); @@ -526,7 +526,7 @@ static CGFloat RCTDefaultIfNegativeTo(CGFloat defaultValue, CGFloat x) { { const BOOL isRTL = _reactLayoutDirection == UIUserInterfaceLayoutDirectionRightToLeft; - if ([[RCTI18nUtil sharedInstance] doesRTLFlipLeftAndRightStyles]) { + if ([[RCTI18nUtil sharedInstance] doLeftAndRightSwapInRTL]) { const CGColorRef borderStartColor = _borderStartColor ?: _borderLeftColor; const CGColorRef borderEndColor = _borderEndColor ?: _borderRightColor; diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nManagerModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nManagerModule.java index 5b8eb1ded1d..4124dbecd11 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nManagerModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nManagerModule.java @@ -10,14 +10,11 @@ package com.facebook.react.modules.i18nmanager; import android.content.Context; - import com.facebook.react.bridge.ContextBaseJavaModule; import com.facebook.react.bridge.NativeModule; -import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactMethod; import com.facebook.react.common.MapBuilder; import com.facebook.react.module.annotations.ReactModule; - import java.util.Locale; import java.util.Map; @@ -45,7 +42,8 @@ public class I18nManagerModule extends ContextBaseJavaModule { final Map constants = MapBuilder.newHashMap(); constants.put("isRTL", sharedI18nUtilInstance.isRTL(context)); - constants.put("doesRTLFlipLeftAndRightStyles", sharedI18nUtilInstance.doesRTLFlipLeftAndRightStyles(context)); + constants.put( + "doLeftAndRightSwapInRTL", sharedI18nUtilInstance.doLeftAndRightSwapInRTL(context)); constants.put("localeIdentifier", locale.toString()); return constants; } @@ -61,7 +59,7 @@ public class I18nManagerModule extends ContextBaseJavaModule { } @ReactMethod - public void makeRTLFlipLeftAndRightStyles(boolean value) { - sharedI18nUtilInstance.makeRTLFlipLeftAndRightStyles(getContext(), value); + public void swapLeftAndRightInRTL(boolean value) { + sharedI18nUtilInstance.swapLeftAndRightInRTL(getContext(), value); } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nUtil.java b/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nUtil.java index 496ac0f8888..1a2ecf11e50 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nUtil.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nUtil.java @@ -11,10 +11,8 @@ package com.facebook.react.modules.i18nmanager; import android.content.Context; import android.content.SharedPreferences; -import android.content.SharedPreferences.Editor; import android.support.v4.text.TextUtilsCompat; import android.support.v4.view.ViewCompat; - import java.util.Locale; public class I18nUtil { @@ -67,11 +65,11 @@ public class I18nUtil { setPref(context, KEY_FOR_PREFS_ALLOWRTL, allowRTL); } - public boolean doesRTLFlipLeftAndRightStyles(Context context) { + public boolean doLeftAndRightSwapInRTL(Context context) { return isPrefSet(context, KEY_FOR_PERFS_MAKE_RTL_FLIP_LEFT_AND_RIGHT_STYLES, true); } - public void makeRTLFlipLeftAndRightStyles(Context context, boolean flip) { + public void swapLeftAndRightInRTL(Context context, boolean flip) { setPref(context, KEY_FOR_PERFS_MAKE_RTL_FLIP_LEFT_AND_RIGHT_STYLES, flip); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/LayoutShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/LayoutShadowNode.java index 6af26e8d7c3..46716716691 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/LayoutShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/LayoutShadowNode.java @@ -680,7 +680,7 @@ public class LayoutShadowNode extends ReactShadowNodeImpl { } private int maybeTransformLeftRightToStartEnd(int spacingType) { - if (!I18nUtil.getInstance().doesRTLFlipLeftAndRightStyles(getThemedContext())) { + if (!I18nUtil.getInstance().doLeftAndRightSwapInRTL(getThemedContext())) { return spacingType; } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewBackgroundDrawable.java b/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewBackgroundDrawable.java index a638642dc33..477526d86ac 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewBackgroundDrawable.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewBackgroundDrawable.java @@ -328,7 +328,7 @@ public class ReactViewBackgroundDrawable extends Drawable { int colorStart = getBorderColor(Spacing.START); int colorEnd = getBorderColor(Spacing.END); - if (I18nUtil.getInstance().doesRTLFlipLeftAndRightStyles(mContext)) { + if (I18nUtil.getInstance().doLeftAndRightSwapInRTL(mContext)) { if (!isBorderColorDefined(Spacing.START)) { colorStart = colorLeft; } @@ -485,7 +485,7 @@ public class ReactViewBackgroundDrawable extends Drawable { float bottomStartRadius = getBorderRadius(BorderRadiusLocation.BOTTOM_START); float bottomEndRadius = getBorderRadius(BorderRadiusLocation.BOTTOM_END); - if (I18nUtil.getInstance().doesRTLFlipLeftAndRightStyles(mContext)) { + if (I18nUtil.getInstance().doLeftAndRightSwapInRTL(mContext)) { if (YogaConstants.isUndefined(topStartRadius)) { topStartRadius = topLeftRadius; } @@ -935,7 +935,7 @@ public class ReactViewBackgroundDrawable extends Drawable { int colorStart = getBorderColor(Spacing.START); int colorEnd = getBorderColor(Spacing.END); - if (I18nUtil.getInstance().doesRTLFlipLeftAndRightStyles(mContext)) { + if (I18nUtil.getInstance().doLeftAndRightSwapInRTL(mContext)) { if (!isBorderColorDefined(Spacing.START)) { colorStart = colorLeft; } @@ -1145,7 +1145,7 @@ public class ReactViewBackgroundDrawable extends Drawable { float borderStartWidth = mBorderWidth.getRaw(Spacing.START); float borderEndWidth = mBorderWidth.getRaw(Spacing.END); - if (I18nUtil.getInstance().doesRTLFlipLeftAndRightStyles(mContext)) { + if (I18nUtil.getInstance().doLeftAndRightSwapInRTL(mContext)) { if (YogaConstants.isUndefined(borderStartWidth)) { borderStartWidth = borderLeftWidth; } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.java b/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.java index 413627e181e..5eb69711286 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.java @@ -685,7 +685,7 @@ public class ReactViewGroup extends ViewGroup implements mReactBackgroundDrawable.getBorderRadius( ReactViewBackgroundDrawable.BorderRadiusLocation.BOTTOM_END); - if (I18nUtil.getInstance().doesRTLFlipLeftAndRightStyles(getContext())) { + if (I18nUtil.getInstance().doLeftAndRightSwapInRTL(getContext())) { if (YogaConstants.isUndefined(topStartBorderRadius)) { topStartBorderRadius = topLeftBorderRadius; }