|
7 | 7 | package com.facebook.react.uimanager;
|
8 | 8 |
|
9 | 9 | import android.graphics.Rect;
|
| 10 | +import android.graphics.RectF; |
10 | 11 | import android.view.View;
|
11 | 12 | import android.view.ViewParent;
|
12 | 13 | import javax.annotation.concurrent.NotThreadSafe;
|
@@ -55,4 +56,51 @@ public static void calculateClippingRect(View view, Rect outputRect) {
|
55 | 56 | }
|
56 | 57 | view.getDrawingRect(outputRect);
|
57 | 58 | }
|
| 59 | + |
| 60 | + public static boolean getChildVisibleRectHelper( |
| 61 | + View child, Rect r, android.graphics.Point offset, View parent, String overflow) { |
| 62 | + // This is based on the Android ViewGroup implementation, modified to clip child rects |
| 63 | + // if overflow is set to ViewProps.HIDDEN. This effectively solves Issue #23870 which |
| 64 | + // appears to have been introduced by FLAG_CLIP_CHILDREN being forced false |
| 65 | + // regardless of whether clipping is desired. |
| 66 | + final RectF rect = new RectF(); |
| 67 | + rect.set(r); |
| 68 | + |
| 69 | + child.getMatrix().mapRect(rect); |
| 70 | + |
| 71 | + final int dx = child.getLeft() - parent.getScrollX(); |
| 72 | + final int dy = child.getTop() - parent.getScrollY(); |
| 73 | + |
| 74 | + rect.offset(dx, dy); |
| 75 | + |
| 76 | + if (offset != null) { |
| 77 | + float[] position = new float[2]; |
| 78 | + position[0] = offset.x; |
| 79 | + position[1] = offset.y; |
| 80 | + child.getMatrix().mapPoints(position); |
| 81 | + offset.x = Math.round(position[0]) + dx; |
| 82 | + offset.y = Math.round(position[1]) + dy; |
| 83 | + } |
| 84 | + |
| 85 | + final int width = parent.getRight() - parent.getLeft(); |
| 86 | + final int height = parent.getBottom() - parent.getTop(); |
| 87 | + |
| 88 | + boolean rectIsVisible = true; |
| 89 | + |
| 90 | + ViewParent grandparent = parent.getParent(); |
| 91 | + if (grandparent == null || ViewProps.HIDDEN.equals(overflow)) { |
| 92 | + rectIsVisible = rect.intersect(0, 0, width, height); |
| 93 | + } |
| 94 | + |
| 95 | + r.set( |
| 96 | + (int) Math.floor(rect.left), |
| 97 | + (int) Math.floor(rect.top), |
| 98 | + (int) Math.ceil(rect.right), |
| 99 | + (int) Math.ceil(rect.bottom)); |
| 100 | + |
| 101 | + if (rectIsVisible && grandparent != null) { |
| 102 | + rectIsVisible = grandparent.getChildVisibleRect(parent, r, offset); |
| 103 | + } |
| 104 | + return rectIsVisible; |
| 105 | + } |
58 | 106 | }
|
0 commit comments