diff --git a/packages/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/NativeProxy.java b/packages/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/NativeProxy.java index ff87a3a83e23..d2313751eb34 100644 --- a/packages/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/NativeProxy.java +++ b/packages/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/NativeProxy.java @@ -15,6 +15,7 @@ import com.facebook.react.common.annotations.FrameworkAPI; import com.facebook.react.fabric.FabricUIManager; import com.facebook.react.turbomodule.core.CallInvokerHolderImpl; +import com.facebook.react.uimanager.IllegalViewOperationException; import com.facebook.react.uimanager.UIManagerHelper; import com.facebook.react.uimanager.common.UIManagerType; import com.facebook.soloader.SoLoader; @@ -305,7 +306,19 @@ public boolean preserveMountedTags(int[] tags) { } for (int i = 0; i < tags.length; i++) { - if (mFabricUIManager.resolveView(tags[i]) == null) { + try { + if (mFabricUIManager.resolveView(tags[i]) == null) { + tags[i] = -1; + } + } catch (IllegalViewOperationException e) { + // `resolveView` is expected to return `null` for a tag without a + // mounted view, but it instead throws when the tag's `ViewState` is + // already registered while the Android view hasn't been created yet. + // This happens when a view is mid-preallocation and a third-party view + // manager (e.g. lottie-react-native) dispatches an event synchronously + // from within `createView`, re-entering this code path. Treat it the + // same as a missing view. + // See https://github.com/software-mansion/react-native-reanimated/issues/9636. tags[i] = -1; } }