Rename I18nManager Left/Right swap methods

Reviewed By: fkgozali

Differential Revision: D6140072

fbshipit-source-id: 282dc614c036de8f217a729f21a1bbe92b8afd7d
This commit is contained in:
Ramanpreet Nara 2017-10-24 20:32:17 -07:00 committed by Facebook Github Bot
parent 90a42396b9
commit efa4d3c222
11 changed files with 34 additions and 38 deletions

View File

@ -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;

View File

@ -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])
};
}

View File

@ -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

View File

@ -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];

View File

@ -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);
}

View File

@ -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;

View File

@ -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<String, Object> 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);
}
}

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}