Permalink
Browse files

Rename I18nManager Left/Right swap methods

Reviewed By: fkgozali

Differential Revision: D6140072

fbshipit-source-id: 282dc614c036de8f217a729f21a1bbe92b8afd7d
  • Loading branch information...
RSNara authored and facebook-github-bot committed Oct 25, 2017
1 parent 90a4239 commit efa4d3c2228ac08712f1578c4a1411a1f51e137c
@@ -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;
@@ -29,16 +29,16 @@ + (BOOL)requiresMainQueueSetup
[[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])
};
}
@@ -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
@@ -19,7 +19,7 @@ + (instancetype)sharedInstance
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [self new];
[sharedInstance makeRTLFlipLeftAndRightStyles: true];
[sharedInstance swapLeftAndRightInRTL: true];
});
return sharedInstance;
@@ -79,12 +79,12 @@ - (void)forceRTL:(BOOL)rtlStatus
[[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];
@@ -103,7 +103,7 @@ static void RCTPrint(YGNodeRef node)
}
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 @@ - (YGValue)getProp \
- (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
@@ -443,7 +443,7 @@ - (UIEdgeInsets)bordersAsInsets
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 @@ - (RCTCornerRadii)cornerRadii
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 @@ - (RCTBorderColors)borderColors
{
const BOOL isRTL = _reactLayoutDirection == UIUserInterfaceLayoutDirectionRightToLeft;
if ([[RCTI18nUtil sharedInstance] doesRTLFlipLeftAndRightStyles]) {
if ([[RCTI18nUtil sharedInstance] doLeftAndRightSwapInRTL]) {
const CGColorRef borderStartColor = _borderStartColor ?: _borderLeftColor;
const CGColorRef borderEndColor = _borderEndColor ?: _borderRightColor;
@@ -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 String getName() {
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 void forceRTL(boolean value) {
}
@ReactMethod
public void makeRTLFlipLeftAndRightStyles(boolean value) {
sharedI18nUtilInstance.makeRTLFlipLeftAndRightStyles(getContext(), value);
public void swapLeftAndRightInRTL(boolean value) {
sharedI18nUtilInstance.swapLeftAndRightInRTL(getContext(), value);
}
}
@@ -11,10 +11,8 @@
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 void allowRTL(Context context, boolean allowRTL) {
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);
}
@@ -680,7 +680,7 @@ public void setPositionValues(int index, Dynamic position) {
}
private int maybeTransformLeftRightToStartEnd(int spacingType) {
if (!I18nUtil.getInstance().doesRTLFlipLeftAndRightStyles(getThemedContext())) {
if (!I18nUtil.getInstance().doLeftAndRightSwapInRTL(getThemedContext())) {
return spacingType;
}
@@ -328,7 +328,7 @@ private void drawRoundedBackgroundWithBorders(Canvas canvas) {
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 @@ private void updatePath() {
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 @@ private void drawRectangularBackgroundWithBorders(Canvas canvas) {
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 RectF getDirectionAwareBorderInsets() {
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;
}
@@ -685,7 +685,7 @@ protected void dispatchDraw(Canvas canvas) {
mReactBackgroundDrawable.getBorderRadius(
ReactViewBackgroundDrawable.BorderRadiusLocation.BOTTOM_END);
if (I18nUtil.getInstance().doesRTLFlipLeftAndRightStyles(getContext())) {
if (I18nUtil.getInstance().doLeftAndRightSwapInRTL(getContext())) {
if (YogaConstants.isUndefined(topStartBorderRadius)) {
topStartBorderRadius = topLeftBorderRadius;
}

0 comments on commit efa4d3c

Please sign in to comment.