Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix updating a view z-index on Android #15203

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.graphics.Color;
import android.os.Build;
import android.view.View;
import android.view.ViewParent;

import com.facebook.react.R;
import com.facebook.react.bridge.ReadableArray;
Expand Down Expand Up @@ -80,6 +81,10 @@ public void setElevation(T view, float elevation) {
public void setZIndex(T view, float zIndex) {
int integerZIndex = Math.round(zIndex);
ViewGroupManager.setViewZIndex(view, integerZIndex);
ViewParent parent = view.getParent();
if (parent != null && parent instanceof ReactZIndexedViewGroup) {
((ReactZIndexedViewGroup) parent).updateZIndex();
}
}

@ReactProp(name = PROP_RENDER_TO_HARDWARE_TEXTURE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ public interface ReactZIndexedViewGroup {
* @return The child view index considering z-index
*/
int getZIndexMappedChildIndex(int index);

/**
* Redraw the view based on updated z-index. This should be called after updating one of it's child
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"it's child z-index" -> "its child z-indexes"

* z-index.
*/
void updateZIndex();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that name of this method is a bit too short. Maybe updateViewParentZIndex() would be better as I suppose this method belongs to parent not child.

Copy link
Contributor Author

@janicduplessis janicduplessis Jul 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I had a hard time figuring out a name. updateViewParentZIndex would not work in this case because it doesn't update the parent, it redraws the view based on the updated z-index of its children.

}
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,17 @@ public int compare(View view1, View view2) {
}
return mDrawingOrderIndices[index];
}

/**
* Recheck all children for z-index changes.
*/
public void update() {
mNumberOfChildrenWithZIndex = 0;
for (int i = 0; i < mViewGroup.getChildCount(); i++) {
if (ViewGroupManager.getViewZIndex(mViewGroup.getChildAt(i)) != null) {
mNumberOfChildrenWithZIndex++;
}
}
mDrawingOrderIndices = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,13 @@ public int getZIndexMappedChildIndex(int index) {
}
}

@Override
public void updateZIndex() {
mDrawingOrderHelper.update();
setChildrenDrawingOrderEnabled(mDrawingOrderHelper.shouldEnableCustomDrawingOrder());
invalidate();
}

@Override
public PointerEvents getPointerEvents() {
return mPointerEvents;
Expand Down