Skip to content

Commit

Permalink
Rename I18nManager Left/Right swap methods
Browse files Browse the repository at this point in the history
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 efa4d3c
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 38 deletions.
8 changes: 4 additions & 4 deletions Libraries/ReactNative/I18nManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
6 changes: 3 additions & 3 deletions React/Modules/RCTI18nManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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])
};
}

Expand Down
4 changes: 2 additions & 2 deletions React/Modules/RCTI18nUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions React/Modules/RCTI18nUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down
14 changes: 7 additions & 7 deletions React/Views/RCTShadowView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions React/Views/RCTView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -45,7 +42,8 @@ public Map<String, Object> getConstants() {

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;
}
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit efa4d3c

Please sign in to comment.