|
53 | 53 | * Backing for a React View. Has support for borders, but since borders aren't common, lazy
|
54 | 54 | * initializes most of the storage needed for them.
|
55 | 55 | */
|
| 56 | +@TargetApi(Build.VERSION_CODES.KITKAT) |
56 | 57 | public class ReactViewGroup extends ViewGroup
|
57 | 58 | implements ReactInterceptingViewGroup,
|
58 | 59 | ReactClippingViewGroup,
|
@@ -145,10 +146,8 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
|
145 | 146 |
|
146 | 147 | @Override
|
147 | 148 | public void onRtlPropertiesChanged(int layoutDirection) {
|
148 |
| - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { |
149 |
| - if (mReactBackgroundDrawable != null) { |
150 |
| - mReactBackgroundDrawable.setResolvedLayoutDirection(mLayoutDirection); |
151 |
| - } |
| 149 | + if (mReactBackgroundDrawable != null) { |
| 150 | + mReactBackgroundDrawable.setResolvedLayoutDirection(mLayoutDirection); |
152 | 151 | }
|
153 | 152 | }
|
154 | 153 |
|
@@ -256,33 +255,11 @@ public void setBorderColor(int position, float rgb, float alpha) {
|
256 | 255 | public void setBorderRadius(float borderRadius) {
|
257 | 256 | ReactViewBackgroundDrawable backgroundDrawable = getOrCreateReactViewBackground();
|
258 | 257 | backgroundDrawable.setRadius(borderRadius);
|
259 |
| - |
260 |
| - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { |
261 |
| - final int UPDATED_LAYER_TYPE = |
262 |
| - backgroundDrawable.hasRoundedBorders() |
263 |
| - ? View.LAYER_TYPE_SOFTWARE |
264 |
| - : View.LAYER_TYPE_HARDWARE; |
265 |
| - |
266 |
| - if (UPDATED_LAYER_TYPE != getLayerType()) { |
267 |
| - setLayerType(UPDATED_LAYER_TYPE, null); |
268 |
| - } |
269 |
| - } |
270 | 258 | }
|
271 | 259 |
|
272 | 260 | public void setBorderRadius(float borderRadius, int position) {
|
273 | 261 | ReactViewBackgroundDrawable backgroundDrawable = getOrCreateReactViewBackground();
|
274 | 262 | backgroundDrawable.setRadius(borderRadius, position);
|
275 |
| - |
276 |
| - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { |
277 |
| - final int UPDATED_LAYER_TYPE = |
278 |
| - backgroundDrawable.hasRoundedBorders() |
279 |
| - ? View.LAYER_TYPE_SOFTWARE |
280 |
| - : View.LAYER_TYPE_HARDWARE; |
281 |
| - |
282 |
| - if (UPDATED_LAYER_TYPE != getLayerType()) { |
283 |
| - setLayerType(UPDATED_LAYER_TYPE, null); |
284 |
| - } |
285 |
| - } |
286 | 263 | }
|
287 | 264 |
|
288 | 265 | public void setBorderStyle(@Nullable String style) {
|
@@ -656,13 +633,9 @@ private ReactViewBackgroundDrawable getOrCreateReactViewBackground() {
|
656 | 633 | updateBackgroundDrawable(layerDrawable);
|
657 | 634 | }
|
658 | 635 |
|
659 |
| - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { |
660 |
| - mLayoutDirection = |
661 |
| - I18nUtil.getInstance().isRTL(getContext()) |
662 |
| - ? LAYOUT_DIRECTION_RTL |
663 |
| - : LAYOUT_DIRECTION_LTR; |
664 |
| - mReactBackgroundDrawable.setResolvedLayoutDirection(mLayoutDirection); |
665 |
| - } |
| 636 | + mLayoutDirection = |
| 637 | + I18nUtil.getInstance().isRTL(getContext()) ? LAYOUT_DIRECTION_RTL : LAYOUT_DIRECTION_LTR; |
| 638 | + mReactBackgroundDrawable.setResolvedLayoutDirection(mLayoutDirection); |
666 | 639 | }
|
667 | 640 | return mReactBackgroundDrawable;
|
668 | 641 | }
|
@@ -764,76 +737,74 @@ private void dispatchOverflowDraw(Canvas canvas) {
|
764 | 737 | mReactBackgroundDrawable.getBorderRadiusOrDefaultTo(
|
765 | 738 | borderRadius, ReactViewBackgroundDrawable.BorderRadiusLocation.BOTTOM_RIGHT);
|
766 | 739 |
|
767 |
| - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { |
768 |
| - final boolean isRTL = mLayoutDirection == View.LAYOUT_DIRECTION_RTL; |
769 |
| - float topStartBorderRadius = |
770 |
| - mReactBackgroundDrawable.getBorderRadius( |
771 |
| - ReactViewBackgroundDrawable.BorderRadiusLocation.TOP_START); |
772 |
| - float topEndBorderRadius = |
773 |
| - mReactBackgroundDrawable.getBorderRadius( |
774 |
| - ReactViewBackgroundDrawable.BorderRadiusLocation.TOP_END); |
775 |
| - float bottomStartBorderRadius = |
776 |
| - mReactBackgroundDrawable.getBorderRadius( |
777 |
| - ReactViewBackgroundDrawable.BorderRadiusLocation.BOTTOM_START); |
778 |
| - float bottomEndBorderRadius = |
779 |
| - mReactBackgroundDrawable.getBorderRadius( |
780 |
| - ReactViewBackgroundDrawable.BorderRadiusLocation.BOTTOM_END); |
781 |
| - |
782 |
| - if (I18nUtil.getInstance().doLeftAndRightSwapInRTL(getContext())) { |
783 |
| - if (YogaConstants.isUndefined(topStartBorderRadius)) { |
784 |
| - topStartBorderRadius = topLeftBorderRadius; |
785 |
| - } |
786 |
| - |
787 |
| - if (YogaConstants.isUndefined(topEndBorderRadius)) { |
788 |
| - topEndBorderRadius = topRightBorderRadius; |
789 |
| - } |
790 |
| - |
791 |
| - if (YogaConstants.isUndefined(bottomStartBorderRadius)) { |
792 |
| - bottomStartBorderRadius = bottomLeftBorderRadius; |
793 |
| - } |
794 |
| - |
795 |
| - if (YogaConstants.isUndefined(bottomEndBorderRadius)) { |
796 |
| - bottomEndBorderRadius = bottomRightBorderRadius; |
797 |
| - } |
798 |
| - |
799 |
| - final float directionAwareTopLeftRadius = |
800 |
| - isRTL ? topEndBorderRadius : topStartBorderRadius; |
801 |
| - final float directionAwareTopRightRadius = |
802 |
| - isRTL ? topStartBorderRadius : topEndBorderRadius; |
803 |
| - final float directionAwareBottomLeftRadius = |
804 |
| - isRTL ? bottomEndBorderRadius : bottomStartBorderRadius; |
805 |
| - final float directionAwareBottomRightRadius = |
806 |
| - isRTL ? bottomStartBorderRadius : bottomEndBorderRadius; |
| 740 | + final boolean isRTL = mLayoutDirection == View.LAYOUT_DIRECTION_RTL; |
| 741 | + float topStartBorderRadius = |
| 742 | + mReactBackgroundDrawable.getBorderRadius( |
| 743 | + ReactViewBackgroundDrawable.BorderRadiusLocation.TOP_START); |
| 744 | + float topEndBorderRadius = |
| 745 | + mReactBackgroundDrawable.getBorderRadius( |
| 746 | + ReactViewBackgroundDrawable.BorderRadiusLocation.TOP_END); |
| 747 | + float bottomStartBorderRadius = |
| 748 | + mReactBackgroundDrawable.getBorderRadius( |
| 749 | + ReactViewBackgroundDrawable.BorderRadiusLocation.BOTTOM_START); |
| 750 | + float bottomEndBorderRadius = |
| 751 | + mReactBackgroundDrawable.getBorderRadius( |
| 752 | + ReactViewBackgroundDrawable.BorderRadiusLocation.BOTTOM_END); |
| 753 | + |
| 754 | + if (I18nUtil.getInstance().doLeftAndRightSwapInRTL(getContext())) { |
| 755 | + if (YogaConstants.isUndefined(topStartBorderRadius)) { |
| 756 | + topStartBorderRadius = topLeftBorderRadius; |
| 757 | + } |
807 | 758 |
|
| 759 | + if (YogaConstants.isUndefined(topEndBorderRadius)) { |
| 760 | + topEndBorderRadius = topRightBorderRadius; |
| 761 | + } |
| 762 | + |
| 763 | + if (YogaConstants.isUndefined(bottomStartBorderRadius)) { |
| 764 | + bottomStartBorderRadius = bottomLeftBorderRadius; |
| 765 | + } |
| 766 | + |
| 767 | + if (YogaConstants.isUndefined(bottomEndBorderRadius)) { |
| 768 | + bottomEndBorderRadius = bottomRightBorderRadius; |
| 769 | + } |
| 770 | + |
| 771 | + final float directionAwareTopLeftRadius = |
| 772 | + isRTL ? topEndBorderRadius : topStartBorderRadius; |
| 773 | + final float directionAwareTopRightRadius = |
| 774 | + isRTL ? topStartBorderRadius : topEndBorderRadius; |
| 775 | + final float directionAwareBottomLeftRadius = |
| 776 | + isRTL ? bottomEndBorderRadius : bottomStartBorderRadius; |
| 777 | + final float directionAwareBottomRightRadius = |
| 778 | + isRTL ? bottomStartBorderRadius : bottomEndBorderRadius; |
| 779 | + |
| 780 | + topLeftBorderRadius = directionAwareTopLeftRadius; |
| 781 | + topRightBorderRadius = directionAwareTopRightRadius; |
| 782 | + bottomLeftBorderRadius = directionAwareBottomLeftRadius; |
| 783 | + bottomRightBorderRadius = directionAwareBottomRightRadius; |
| 784 | + } else { |
| 785 | + final float directionAwareTopLeftRadius = |
| 786 | + isRTL ? topEndBorderRadius : topStartBorderRadius; |
| 787 | + final float directionAwareTopRightRadius = |
| 788 | + isRTL ? topStartBorderRadius : topEndBorderRadius; |
| 789 | + final float directionAwareBottomLeftRadius = |
| 790 | + isRTL ? bottomEndBorderRadius : bottomStartBorderRadius; |
| 791 | + final float directionAwareBottomRightRadius = |
| 792 | + isRTL ? bottomStartBorderRadius : bottomEndBorderRadius; |
| 793 | + |
| 794 | + if (!YogaConstants.isUndefined(directionAwareTopLeftRadius)) { |
808 | 795 | topLeftBorderRadius = directionAwareTopLeftRadius;
|
| 796 | + } |
| 797 | + |
| 798 | + if (!YogaConstants.isUndefined(directionAwareTopRightRadius)) { |
809 | 799 | topRightBorderRadius = directionAwareTopRightRadius;
|
| 800 | + } |
| 801 | + |
| 802 | + if (!YogaConstants.isUndefined(directionAwareBottomLeftRadius)) { |
810 | 803 | bottomLeftBorderRadius = directionAwareBottomLeftRadius;
|
| 804 | + } |
| 805 | + |
| 806 | + if (!YogaConstants.isUndefined(directionAwareBottomRightRadius)) { |
811 | 807 | bottomRightBorderRadius = directionAwareBottomRightRadius;
|
812 |
| - } else { |
813 |
| - final float directionAwareTopLeftRadius = |
814 |
| - isRTL ? topEndBorderRadius : topStartBorderRadius; |
815 |
| - final float directionAwareTopRightRadius = |
816 |
| - isRTL ? topStartBorderRadius : topEndBorderRadius; |
817 |
| - final float directionAwareBottomLeftRadius = |
818 |
| - isRTL ? bottomEndBorderRadius : bottomStartBorderRadius; |
819 |
| - final float directionAwareBottomRightRadius = |
820 |
| - isRTL ? bottomStartBorderRadius : bottomEndBorderRadius; |
821 |
| - |
822 |
| - if (!YogaConstants.isUndefined(directionAwareTopLeftRadius)) { |
823 |
| - topLeftBorderRadius = directionAwareTopLeftRadius; |
824 |
| - } |
825 |
| - |
826 |
| - if (!YogaConstants.isUndefined(directionAwareTopRightRadius)) { |
827 |
| - topRightBorderRadius = directionAwareTopRightRadius; |
828 |
| - } |
829 |
| - |
830 |
| - if (!YogaConstants.isUndefined(directionAwareBottomLeftRadius)) { |
831 |
| - bottomLeftBorderRadius = directionAwareBottomLeftRadius; |
832 |
| - } |
833 |
| - |
834 |
| - if (!YogaConstants.isUndefined(directionAwareBottomRightRadius)) { |
835 |
| - bottomRightBorderRadius = directionAwareBottomRightRadius; |
836 |
| - } |
837 | 808 | }
|
838 | 809 | }
|
839 | 810 |
|
|
0 commit comments