Skip to content

Commit 284a0be

Browse files
Initial attempt at fixing issue facebook#23870 by overriding getChildVisibleRect() in ReactViewGroup
1 parent 3b91a7e commit 284a0be

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

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

+48
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import android.view.MotionEvent;
2222
import android.view.View;
2323
import android.view.ViewGroup;
24+
import android.view.ViewParent;
2425
import android.view.ViewStructure;
2526
import android.view.animation.Animation;
2627
import com.facebook.common.logging.FLog;
@@ -427,6 +428,53 @@ private void updateSubviewClipStatus(View subview) {
427428
}
428429
}
429430

431+
@Override
432+
public boolean getChildVisibleRect(View child, Rect r, android.graphics.Point offset) {
433+
// This is based on the Android ViewGroup implementation, modified to clip child rects
434+
// if overflow is set to ViewProps.HIDDEN. This effectively solves Issue #23870 which
435+
// appears to have been introduced by FLAG_CLIP_CHILDREN being forced false
436+
// regardless of whether clipping is desired.
437+
438+
final RectF rect = new RectF();
439+
rect.set(r);
440+
441+
child.getMatrix().mapRect(rect);
442+
443+
final int dx = child.getLeft() - getScrollX();
444+
int dy = child.getTop() - getScrollY();
445+
446+
rect.offset(dx, dy);
447+
448+
if (offset != null) {
449+
float[] position = new float[2];
450+
position[0] = offset.x;
451+
position[1] = offset.y;
452+
child.getMatrix().mapPoints(position);
453+
offset.x = Math.round(position[0]) + dx;
454+
offset.y = Math.round(position[1]) + dy;
455+
}
456+
457+
final int width = getRight() - getLeft();
458+
final int height = getBottom() - getTop();
459+
460+
boolean rectIsVisible = true;
461+
462+
ViewParent parent = getParent();
463+
String overflow = getOverflow();
464+
if (parent == null ||
465+
(overflow != null && overflow.equals(ViewProps.HIDDEN))) {
466+
rectIsVisible = rect.intersect(0, 0, width, height);
467+
}
468+
469+
r.set((int) Math.floor(rect.left), (int) Math.floor(rect.top),
470+
(int) Math.ceil(rect.right), (int) Math.ceil(rect.bottom));
471+
472+
if (rectIsVisible && parent != null) {
473+
rectIsVisible = parent.getChildVisibleRect(this, r, offset);
474+
}
475+
return rectIsVisible;
476+
}
477+
430478
@Override
431479
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
432480
super.onSizeChanged(w, h, oldw, oldh);

0 commit comments

Comments
 (0)