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 4e89e9dbf59b9b..dbdb26a479c78f 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 @@ -21,6 +21,7 @@ import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; +import android.view.ViewParent; import android.view.ViewStructure; import android.view.animation.Animation; import com.facebook.common.logging.FLog; @@ -427,6 +428,53 @@ private void updateSubviewClipStatus(View subview) { } } + @Override + public boolean getChildVisibleRect(View child, Rect r, android.graphics.Point offset) { + // This is based on the Android ViewGroup implementation, modified to clip child rects + // if overflow is set to ViewProps.HIDDEN. This effectively solves Issue #23870 which + // appears to have been introduced by FLAG_CLIP_CHILDREN being forced false + // regardless of whether clipping is desired. + + final RectF rect = new RectF(); + rect.set(r); + + child.getMatrix().mapRect(rect); + + final int dx = child.getLeft() - getScrollX(); + int dy = child.getTop() - getScrollY(); + + rect.offset(dx, dy); + + if (offset != null) { + float[] position = new float[2]; + position[0] = offset.x; + position[1] = offset.y; + child.getMatrix().mapPoints(position); + offset.x = Math.round(position[0]) + dx; + offset.y = Math.round(position[1]) + dy; + } + + final int width = getRight() - getLeft(); + final int height = getBottom() - getTop(); + + boolean rectIsVisible = true; + + ViewParent parent = getParent(); + String overflow = getOverflow(); + if (parent == null || + (overflow != null && overflow.equals(ViewProps.HIDDEN))) { + rectIsVisible = rect.intersect(0, 0, width, height); + } + + r.set((int) Math.floor(rect.left), (int) Math.floor(rect.top), + (int) Math.ceil(rect.right), (int) Math.ceil(rect.bottom)); + + if (rectIsVisible && parent != null) { + rectIsVisible = parent.getChildVisibleRect(this, r, offset); + } + return rectIsVisible; + } + @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh);