Skip to content

Commit b81c8b5

Browse files
yungstersfacebook-github-bot
authored andcommitted
RN: Add Support for overflow on Android (Take 2)
Summary: Adds support for the `overflow` style property on React Native for Android. This is the second attempt to do this. See 6110a4c (D8666509) for the first attempt. Similar to the first attempt, this sets `setClipChildren(false)` by default on all `ViewGroup` instances. However, this differs in how it implements `overflow: hidden`. Instead of conditionally setting `setClipChildren`, this manually clips children to the `ViewGroup`'s bounds (which was incidentally what we were doing for background + border radius already). Reviewed By: achen1 Differential Revision: D8690805 fbshipit-source-id: 58757825cd9d138c18c8758918d85b4ca1915f87
1 parent cfce6ee commit b81c8b5

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewProps.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public class ViewProps {
2424
public static final String ALIGN_ITEMS = "alignItems";
2525
public static final String ALIGN_SELF = "alignSelf";
2626
public static final String ALIGN_CONTENT = "alignContent";
27-
public static final String OVERFLOW = "overflow";
2827
public static final String DISPLAY = "display";
2928
public static final String BOTTOM = "bottom";
3029
public static final String COLLAPSABLE = "collapsable";
@@ -74,9 +73,6 @@ public class ViewProps {
7473
public static final String MIN_HEIGHT = "minHeight";
7574
public static final String MAX_HEIGHT = "maxHeight";
7675

77-
public static final String HIDDEN = "hidden";
78-
public static final String VISIBLE = "visible";
79-
8076
public static final String ASPECT_RATIO = "aspectRatio";
8177

8278
// Props that sometimes may prevent us from collapsing views
@@ -103,6 +99,10 @@ public class ViewProps {
10399
public static final String TEXT_DECORATION_LINE = "textDecorationLine";
104100
public static final String TEXT_BREAK_STRATEGY = "textBreakStrategy";
105101
public static final String OPACITY = "opacity";
102+
public static final String OVERFLOW = "overflow";
103+
104+
public static final String HIDDEN = "hidden";
105+
public static final String VISIBLE = "visible";
106106

107107
public static final String ALLOW_FONT_SCALING = "allowFontScaling";
108108
public static final String INCLUDE_FONT_PADDING = "includeFontPadding";
@@ -169,7 +169,6 @@ public class ViewProps {
169169
FLEX_SHRINK,
170170
FLEX_WRAP,
171171
JUSTIFY_CONTENT,
172-
OVERFLOW,
173172
ALIGN_CONTENT,
174173
DISPLAY,
175174

@@ -257,6 +256,8 @@ public static boolean isLayoutOnly(ReadableMap map, String prop) {
257256
return map.isNull(BORDER_RIGHT_WIDTH) || map.getDouble(BORDER_RIGHT_WIDTH) == 0d;
258257
case BORDER_BOTTOM_WIDTH:
259258
return map.isNull(BORDER_BOTTOM_WIDTH) || map.getDouble(BORDER_BOTTOM_WIDTH) == 0d;
259+
case OVERFLOW:
260+
return map.isNull(OVERFLOW) || VISIBLE.equals(map.getString(OVERFLOW));
260261
default:
261262
return false;
262263
}

ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.java

+13-7
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public void onLayoutChange(
113113

114114
public ReactViewGroup(Context context) {
115115
super(context);
116+
setClipChildren(false);
116117
mDrawingOrderHelper = new ViewGroupDrawingOrderHelper(this);
117118
}
118119

@@ -689,12 +690,14 @@ private void dispatchOverflowDraw(Canvas canvas) {
689690
}
690691
break;
691692
case ViewProps.HIDDEN:
692-
if (mReactBackgroundDrawable != null) {
693-
float left = 0f;
694-
float top = 0f;
695-
float right = getWidth();
696-
float bottom = getHeight();
693+
float left = 0f;
694+
float top = 0f;
695+
float right = getWidth();
696+
float bottom = getHeight();
697+
698+
boolean hasClipPath = false;
697699

700+
if (mReactBackgroundDrawable != null) {
698701
final RectF borderWidth = mReactBackgroundDrawable.getDirectionAwareBorderInsets();
699702

700703
if (borderWidth.top > 0
@@ -817,10 +820,13 @@ private void dispatchOverflowDraw(Canvas canvas) {
817820
},
818821
Path.Direction.CW);
819822
canvas.clipPath(mPath);
820-
} else {
821-
canvas.clipRect(new RectF(left, top, right, bottom));
823+
hasClipPath = true;
822824
}
823825
}
826+
827+
if (!hasClipPath) {
828+
canvas.clipRect(new RectF(left, top, right, bottom));
829+
}
824830
break;
825831
default:
826832
break;

0 commit comments

Comments
 (0)