mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-03 22:48:25 +08:00
Add directional clipping command manager.
Summary: Add directional aware clipping to DrawCommandManager. Currently not attached to FlatViewGroup logic, with the plan to keep this unattached until we are clipping the way we want to in the final state. Reviewed By: ahmedre Differential Revision: D3622253
This commit is contained in:
committed by
Ahmed El-Helw
parent
f850e61fdb
commit
e96f6fa585
@@ -71,6 +71,10 @@ import com.facebook.react.views.view.ReactClippingViewGroupHelper;
|
||||
return mClippedSubviews.containsKey(id);
|
||||
}
|
||||
|
||||
private boolean isNotClipped(int id) {
|
||||
return !mClippedSubviews.containsKey(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mountViews(ViewResolver viewResolver, int[] viewsToAdd, int[] viewsToDetach) {
|
||||
for (int viewToAdd : viewsToAdd) {
|
||||
@@ -94,7 +98,7 @@ import com.facebook.react.views.view.ReactClippingViewGroupHelper;
|
||||
ensureViewHasNoParent(view);
|
||||
if (drawView.mWasMounted) {
|
||||
// The DrawView has been mounted before.
|
||||
if (!isClipped(drawView.reactTag)) {
|
||||
if (isNotClipped(drawView.reactTag)) {
|
||||
// The DrawView is not clipped. Attach it.
|
||||
mFlatViewGroup.attachViewToParent(view);
|
||||
}
|
||||
@@ -118,7 +122,7 @@ import com.facebook.react.views.view.ReactClippingViewGroupHelper;
|
||||
}
|
||||
} else {
|
||||
// View should be clipped.
|
||||
if (!isClipped(drawView.reactTag)) {
|
||||
if (isNotClipped(drawView.reactTag)) {
|
||||
// View was onscreen.
|
||||
mFlatViewGroup.removeDetachedView(view);
|
||||
clip(drawView.reactTag, view);
|
||||
@@ -147,31 +151,13 @@ import com.facebook.react.views.view.ReactClippingViewGroupHelper;
|
||||
return animation != null && !animation.hasEnded();
|
||||
}
|
||||
|
||||
// Return true if a view is currently onscreen.
|
||||
boolean withinBounds(View view) {
|
||||
if (view instanceof FlatViewGroup) {
|
||||
FlatViewGroup flatChildView = (FlatViewGroup) view;
|
||||
return mClippingRect.intersects(
|
||||
flatChildView.getLeft() + flatChildView.mLogicalAdjustments.left,
|
||||
flatChildView.getTop() + flatChildView.mLogicalAdjustments.top,
|
||||
flatChildView.getRight() + flatChildView.mLogicalAdjustments.right,
|
||||
flatChildView.getBottom() + flatChildView.mLogicalAdjustments.bottom);
|
||||
} else {
|
||||
return mClippingRect.intersects(
|
||||
view.getLeft(),
|
||||
view.getTop(),
|
||||
view.getRight(),
|
||||
view.getBottom());
|
||||
}
|
||||
}
|
||||
|
||||
// Return true if a DrawView is currently onscreen.
|
||||
boolean withinBounds(DrawView drawView) {
|
||||
return mClippingRect.intersects(
|
||||
Math.round(drawView.getLeft()),
|
||||
Math.round(drawView.getTop()),
|
||||
Math.round(drawView.getRight()),
|
||||
Math.round(drawView.getBottom()));
|
||||
drawView.mLogicalLeft,
|
||||
drawView.mLogicalTop,
|
||||
drawView.mLogicalRight,
|
||||
drawView.mLogicalBottom);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -192,7 +178,7 @@ import com.facebook.react.views.view.ReactClippingViewGroupHelper;
|
||||
if (view == null) {
|
||||
// Not clipped, visible
|
||||
view = mFlatViewGroup.getChildAt(index++);
|
||||
if (!animating(view) && !withinBounds(view)) {
|
||||
if (!animating(view) && !withinBounds(drawView)) {
|
||||
// Now off the screen. Don't invalidate in this case, as the canvas should not be
|
||||
// redrawn unless new elements are coming onscreen.
|
||||
clip(drawView.reactTag, view);
|
||||
@@ -201,7 +187,7 @@ import com.facebook.react.views.view.ReactClippingViewGroupHelper;
|
||||
} else {
|
||||
// Clipped, invisible. We obviously aren't animating here, as if we were then we would not
|
||||
// have clipped in the first place.
|
||||
if (withinBounds(view)) {
|
||||
if (withinBounds(drawView)) {
|
||||
// Now on the screen. Invalidate as we have a new element to draw.
|
||||
unclip(drawView.reactTag);
|
||||
mFlatViewGroup.addViewInLayout(view, index++);
|
||||
@@ -228,7 +214,7 @@ import com.facebook.react.views.view.ReactClippingViewGroupHelper;
|
||||
public void draw(Canvas canvas) {
|
||||
for (DrawCommand drawCommand : mDrawCommands) {
|
||||
if (drawCommand instanceof DrawView) {
|
||||
if (!isClipped(((DrawView) drawCommand).reactTag)) {
|
||||
if (isNotClipped(((DrawView) drawCommand).reactTag)) {
|
||||
drawCommand.draw(mFlatViewGroup, canvas);
|
||||
}
|
||||
// else, don't draw, and don't increment index
|
||||
@@ -242,7 +228,7 @@ import com.facebook.react.views.view.ReactClippingViewGroupHelper;
|
||||
void debugDraw(Canvas canvas) {
|
||||
for (DrawCommand drawCommand : mDrawCommands) {
|
||||
if (drawCommand instanceof DrawView) {
|
||||
if (!isClipped(((DrawView) drawCommand).reactTag)) {
|
||||
if (isNotClipped(((DrawView) drawCommand).reactTag)) {
|
||||
drawCommand.debugDraw(mFlatViewGroup, canvas);
|
||||
}
|
||||
// else, don't draw, and don't increment index
|
||||
|
||||
Reference in New Issue
Block a user