mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Add UI-Thread assertions in methods that mutate Views
Summary: As part of `T54997838` we're auditing where removeView could possibly be called in a background thread, and adding annotations to indicate places where we don't think it's possible. Changelog: [internal] Reviewed By: makovkastar Differential Revision: D18320461 fbshipit-source-id: 84b6b9e293d903f835fc42bc98614efb54158986
This commit is contained in:
1 parent
3281714312
commit
a7f56e73e4
4 files changed
+38
No files matched your search
@@ -10,6 +10,7 @@ package com.facebook.react.uimanager;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.facebook.react.bridge.UiThreadUtil;
|
||||
import java.util.List;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
@@ -44,6 +45,8 @@ public abstract class ViewGroupManager<T extends ViewGroup>
|
||||
* @param views the set of views to add
|
||||
*/
|
||||
public void addViews(T parent, List<View> views) {
|
||||
UiThreadUtil.assertOnUiThread();
|
||||
|
||||
for (int i = 0, size = views.size(); i < size; i++) {
|
||||
addView(parent, views.get(i), i);
|
||||
}
|
||||
@@ -66,10 +69,14 @@ public abstract class ViewGroupManager<T extends ViewGroup>
|
||||
}
|
||||
|
||||
public void removeViewAt(T parent, int index) {
|
||||
UiThreadUtil.assertOnUiThread();
|
||||
|
||||
parent.removeViewAt(index);
|
||||
}
|
||||
|
||||
public void removeView(T parent, View view) {
|
||||
UiThreadUtil.assertOnUiThread();
|
||||
|
||||
for (int i = 0; i < getChildCount(parent); i++) {
|
||||
if (getChildAt(parent, i) == view) {
|
||||
removeViewAt(parent, i);
|
||||
@@ -79,6 +86,8 @@ public abstract class ViewGroupManager<T extends ViewGroup>
|
||||
}
|
||||
|
||||
public void removeAllViews(T parent) {
|
||||
UiThreadUtil.assertOnUiThread();
|
||||
|
||||
for (int i = getChildCount(parent) - 1; i >= 0; i--) {
|
||||
removeViewAt(parent, i);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user