-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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 crash in getChildDrawingOrder #40859
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -11,9 +11,13 @@ | |||||||||
import android.view.ViewGroup; | ||||||||||
import androidx.annotation.Nullable; | ||||||||||
import java.util.ArrayList; | ||||||||||
import java.util.Arrays; | ||||||||||
import java.util.Collections; | ||||||||||
import java.util.Comparator; | ||||||||||
|
||||||||||
import com.facebook.common.logging.FLog; | ||||||||||
import com.facebook.react.common.ReactConstants; | ||||||||||
|
||||||||||
/** Helper to handle implementing ViewGroups with custom drawing order based on z-index. */ | ||||||||||
public class ViewGroupDrawingOrderHelper { | ||||||||||
private final ViewGroup mViewGroup; | ||||||||||
|
@@ -65,6 +69,20 @@ public boolean shouldEnableCustomDrawingOrder() { | |||||||||
* ViewGroup#getChildDrawingOrder}. | ||||||||||
*/ | ||||||||||
public int getChildDrawingOrder(int childCount, int index) { | ||||||||||
if (mDrawingOrderIndices != null | ||||||||||
&& (index >= mDrawingOrderIndices.length || mDrawingOrderIndices[index] >= childCount)) { | ||||||||||
FLog.w(ReactConstants.TAG, | ||||||||||
"getChildDrawingOrder index out of bounds! please check your operations of addding and " + | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FLog takes a format string. Let's also not make this too verbose, you can always attach a debugger to inspect the full state.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
done |
||||||||||
"removing subview.Force updates here to prevent crash." | ||||||||||
+ " viewId:" + mViewGroup.getId() | ||||||||||
+ " childCount:" + childCount | ||||||||||
+ " index:" + index | ||||||||||
+ " mDrawingOrderIndices:" + Arrays.toString(mDrawingOrderIndices) | ||||||||||
+ " mNumberOfChildrenWithZIndex:" + mNumberOfChildrenWithZIndex | ||||||||||
); | ||||||||||
update(); | ||||||||||
} | ||||||||||
|
||||||||||
if (mDrawingOrderIndices == null) { | ||||||||||
ArrayList<View> viewsToSort = new ArrayList<>(); | ||||||||||
for (int i = 0; i < childCount; i++) { | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this ever expected to happen under normal conditions? Can we log a warning here that
mDrawingOrderIndices
is out-of-sync?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will not happen under normal circumstances, but it is not ruled out that some third-party components may add or remove subview in the working thread.