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:
Joshua Gross authored and Facebook Github Bot committed 2019-11-05 13:18:59 -08:00
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);
}