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 477526d86..b32855b14 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 @@ -109,6 +109,7 @@ public class ReactViewBackgroundDrawable extends Drawable { private @Nullable float[] mBorderCornerRadii; private final Context mContext; + private int mLayoutDirection; public enum BorderRadiusLocation { TOP_LEFT, @@ -290,6 +291,25 @@ public class ReactViewBackgroundDrawable extends Drawable { invalidateSelf(); } + /** Similar to Drawable.getLayoutDirection, but available in APIs < 23. */ + public int getResolvedLayoutDirection() { + return mLayoutDirection; + } + + /** Similar to Drawable.setLayoutDirection, but available in APIs < 23. */ + public boolean setResolvedLayoutDirection(int layoutDirection) { + if (mLayoutDirection != layoutDirection) { + mLayoutDirection = layoutDirection; + return onResolvedLayoutDirectionChanged(layoutDirection); + } + return false; + } + + /** Similar to Drawable.onLayoutDirectionChanged, but available in APIs < 23. */ + public boolean onResolvedLayoutDirectionChanged(int layoutDirection) { + return false; + } + @VisibleForTesting public int getColor() { return mColor; @@ -323,8 +343,8 @@ public class ReactViewBackgroundDrawable extends Drawable { int colorRight = getBorderColor(Spacing.RIGHT); int colorBottom = getBorderColor(Spacing.BOTTOM); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - final boolean isRTL = getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + final boolean isRTL = getResolvedLayoutDirection() == View.LAYOUT_DIRECTION_RTL; int colorStart = getBorderColor(Spacing.START); int colorEnd = getBorderColor(Spacing.END); @@ -478,13 +498,13 @@ public class ReactViewBackgroundDrawable extends Drawable { float bottomRightRadius = getBorderRadiusOrDefaultTo(borderRadius, BorderRadiusLocation.BOTTOM_RIGHT); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - final boolean isRTL = getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + final boolean isRTL = getResolvedLayoutDirection() == View.LAYOUT_DIRECTION_RTL; float topStartRadius = getBorderRadius(BorderRadiusLocation.TOP_START); float topEndRadius = getBorderRadius(BorderRadiusLocation.TOP_END); float bottomStartRadius = getBorderRadius(BorderRadiusLocation.BOTTOM_START); float bottomEndRadius = getBorderRadius(BorderRadiusLocation.BOTTOM_END); - + if (I18nUtil.getInstance().doLeftAndRightSwapInRTL(mContext)) { if (YogaConstants.isUndefined(topStartRadius)) { topStartRadius = topLeftRadius; @@ -930,8 +950,8 @@ public class ReactViewBackgroundDrawable extends Drawable { int colorRight = getBorderColor(Spacing.RIGHT); int colorBottom = getBorderColor(Spacing.BOTTOM); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - final boolean isRTL = getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + final boolean isRTL = getResolvedLayoutDirection() == View.LAYOUT_DIRECTION_RTL; int colorStart = getBorderColor(Spacing.START); int colorEnd = getBorderColor(Spacing.END); @@ -1140,8 +1160,8 @@ public class ReactViewBackgroundDrawable extends Drawable { float borderLeftWidth = getBorderWidthOrDefaultTo(borderWidth, Spacing.LEFT); float borderRightWidth = getBorderWidthOrDefaultTo(borderWidth, Spacing.RIGHT); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && mBorderWidth != null) { - final boolean isRTL = getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && mBorderWidth != null) { + final boolean isRTL = getResolvedLayoutDirection() == View.LAYOUT_DIRECTION_RTL; float borderStartWidth = mBorderWidth.getRaw(Spacing.START); float borderEndWidth = mBorderWidth.getRaw(Spacing.END); 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 592f328e9..8e80168a3 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 @@ -129,9 +129,9 @@ public class ReactViewGroup extends ViewGroup implements @Override public void onRtlPropertiesChanged(int layoutDirection) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { if (mReactBackgroundDrawable != null) { - mReactBackgroundDrawable.setLayoutDirection(mLayoutDirection); + mReactBackgroundDrawable.setResolvedLayoutDirection(mLayoutDirection); } } } @@ -589,12 +589,12 @@ public class ReactViewGroup extends ViewGroup implements updateBackgroundDrawable(layerDrawable); } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { mLayoutDirection = I18nUtil.getInstance().isRTL(getContext()) ? LAYOUT_DIRECTION_RTL : LAYOUT_DIRECTION_LTR; - mReactBackgroundDrawable.setLayoutDirection(mLayoutDirection); + mReactBackgroundDrawable.setResolvedLayoutDirection(mLayoutDirection); } } return mReactBackgroundDrawable; @@ -671,7 +671,7 @@ public class ReactViewGroup extends ViewGroup implements mReactBackgroundDrawable.getBorderRadiusOrDefaultTo( borderRadius, ReactViewBackgroundDrawable.BorderRadiusLocation.BOTTOM_RIGHT); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { final boolean isRTL = mLayoutDirection == View.LAYOUT_DIRECTION_RTL; float topStartBorderRadius = mReactBackgroundDrawable.getBorderRadius(