Skip to content

Commit

Permalink
Initial attempt at fixing issue facebook#23870 by overriding getChild…
Browse files Browse the repository at this point in the history
…VisibleRect() in ReactViewGroup
  • Loading branch information
davidbiedenbach committed Sep 4, 2019
1 parent 7c73f2b commit 363cba3
Showing 1 changed file with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 363cba3

Please sign in to comment.