|
91 | 91 | import java.util.Map;
|
92 | 92 | import java.util.Queue;
|
93 | 93 | import java.util.concurrent.CopyOnWriteArrayList;
|
94 |
| -import java.util.concurrent.atomic.AtomicBoolean; |
95 | 94 |
|
96 | 95 | /**
|
97 | 96 | * We instruct ProGuard not to strip out any fields or methods, because many of these methods are
|
@@ -173,7 +172,8 @@ public class FabricUIManager implements UIManager, LifecycleEventListener {
|
173 | 172 | @NonNull
|
174 | 173 | private final CopyOnWriteArrayList<UIManagerListener> mListeners = new CopyOnWriteArrayList<>();
|
175 | 174 |
|
176 |
| - @NonNull private final AtomicBoolean mMountNotificationScheduled = new AtomicBoolean(false); |
| 175 | + private boolean mMountNotificationScheduled = false; |
| 176 | + private final List<Integer> mMountedSurfaceIds = new ArrayList<>(); |
177 | 177 |
|
178 | 178 | @ThreadConfined(UI)
|
179 | 179 | @NonNull
|
@@ -1203,54 +1203,55 @@ public Map<String, Long> getPerformanceCounters() {
|
1203 | 1203 | }
|
1204 | 1204 |
|
1205 | 1205 | private class MountItemDispatchListener implements MountItemDispatcher.ItemDispatchListener {
|
| 1206 | + @UiThread |
| 1207 | + @ThreadConfined(UI) |
1206 | 1208 | @Override
|
1207 | 1209 | public void willMountItems(@Nullable List<MountItem> mountItems) {
|
1208 | 1210 | for (UIManagerListener listener : mListeners) {
|
1209 | 1211 | listener.willMountItems(FabricUIManager.this);
|
1210 | 1212 | }
|
1211 | 1213 | }
|
1212 | 1214 |
|
| 1215 | + @UiThread |
| 1216 | + @ThreadConfined(UI) |
1213 | 1217 | @Override
|
1214 | 1218 | public void didMountItems(@Nullable List<MountItem> mountItems) {
|
1215 | 1219 | for (UIManagerListener listener : mListeners) {
|
1216 | 1220 | listener.didMountItems(FabricUIManager.this);
|
1217 | 1221 | }
|
1218 | 1222 |
|
1219 |
| - if (!ReactFeatureFlags.enableMountHooks) { |
| 1223 | + if (!ReactFeatureFlags.enableMountHooks || mountItems == null || mountItems.isEmpty()) { |
1220 | 1224 | return;
|
1221 | 1225 | }
|
1222 | 1226 |
|
1223 |
| - boolean mountNotificationScheduled = mMountNotificationScheduled.getAndSet(true); |
1224 |
| - if (!mountNotificationScheduled) { |
| 1227 | + // Collect surface IDs for all the mount items |
| 1228 | + for (MountItem mountItem : mountItems) { |
| 1229 | + if (mountItem != null && !mMountedSurfaceIds.contains(mountItem.getSurfaceId())) { |
| 1230 | + mMountedSurfaceIds.add(mountItem.getSurfaceId()); |
| 1231 | + } |
| 1232 | + } |
| 1233 | + |
| 1234 | + if (!mMountNotificationScheduled && !mMountedSurfaceIds.isEmpty()) { |
1225 | 1235 | // Notify mount when the effects are visible and prevent mount hooks to
|
1226 | 1236 | // delay paint.
|
1227 | 1237 | UiThreadUtil.getUiThreadHandler()
|
1228 | 1238 | .postAtFrontOfQueue(
|
1229 | 1239 | new Runnable() {
|
1230 | 1240 | @Override
|
1231 | 1241 | public void run() {
|
1232 |
| - mMountNotificationScheduled.set(false); |
1233 |
| - |
1234 |
| - if (mDestroyed) { |
1235 |
| - return; |
1236 |
| - } |
| 1242 | + mMountNotificationScheduled = false; |
1237 | 1243 |
|
1238 | 1244 | final @Nullable Binding binding = mBinding;
|
1239 |
| - if (mountItems == null || binding == null) { |
| 1245 | + if (binding == null || mDestroyed) { |
| 1246 | + mMountedSurfaceIds.clear(); |
1240 | 1247 | return;
|
1241 | 1248 | }
|
1242 | 1249 |
|
1243 |
| - // Collect surface IDs for all the mount items |
1244 |
| - List<Integer> surfaceIds = new ArrayList<>(); |
1245 |
| - for (MountItem mountItem : mountItems) { |
1246 |
| - if (mountItem != null && !surfaceIds.contains(mountItem.getSurfaceId())) { |
1247 |
| - surfaceIds.add(mountItem.getSurfaceId()); |
1248 |
| - } |
1249 |
| - } |
1250 |
| - |
1251 |
| - for (int surfaceId : surfaceIds) { |
| 1250 | + for (int surfaceId : mMountedSurfaceIds) { |
1252 | 1251 | binding.reportMount(surfaceId);
|
1253 | 1252 | }
|
| 1253 | + |
| 1254 | + mMountedSurfaceIds.clear(); |
1254 | 1255 | }
|
1255 | 1256 | });
|
1256 | 1257 | }
|
|
0 commit comments