Permalink
Browse files

Fix updating a view z-index on Android

Summary:
If the z-index was updated after the initial mount, changes would not be reflected because we did not recalculate the z-index mapped child views and redraw the view. This adds code to do that and call it whenever we update z-index.

**Test plan**
Tested by reproducing the bug with 2 overlapping views that change z-index every second. Made sure it now works properly and z-index changes are reflected.
Closes #15203

Differential Revision: D5564832

Pulled By: achen1

fbshipit-source-id: 5b6c20147211ce0b7e8954d60f8614eafe128fb4
  • Loading branch information...
janicduplessis authored and ide committed Aug 10, 2017
1 parent 373f7ed commit 28c7535a75ceb4edf06a0ecfd8130c448fae9627
@@ -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;
@@ -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).updateDrawingOrder();
}
}
@ReactProp(name = PROP_RENDER_TO_HARDWARE_TEXTURE)
@@ -12,4 +12,10 @@
* @return The child view index considering z-index
*/
int getZIndexMappedChildIndex(int index);
/**
* Redraw the view based on updated child z-index. This should be called after updating one of its child
* z-index.
*/
void updateDrawingOrder();
}
@@ -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;
}
}
@@ -419,6 +419,13 @@ public int getZIndexMappedChildIndex(int index) {
}
}
@Override
public void updateDrawingOrder() {
mDrawingOrderHelper.update();
setChildrenDrawingOrderEnabled(mDrawingOrderHelper.shouldEnableCustomDrawingOrder());
invalidate();
}
@Override
public PointerEvents getPointerEvents() {
return mPointerEvents;

0 comments on commit 28c7535

Please sign in to comment.