diff --git a/android/src/main/java/com/rivereactnative/RiveReactNativeView.kt b/android/src/main/java/com/rivereactnative/RiveReactNativeView.kt index 5f13727..6e7de2e 100644 --- a/android/src/main/java/com/rivereactnative/RiveReactNativeView.kt +++ b/android/src/main/java/com/rivereactnative/RiveReactNativeView.kt @@ -114,6 +114,12 @@ class RiveReactNativeView(private val context: ThemedReactContext) : FrameLayout addView(riveAnimationView) } + @OptIn(ControllerStateManagement::class) + fun dispose() { + removeView(riveAnimationView) + controllerState?.dispose(); + } + @OptIn(ControllerStateManagement::class) override fun onAttachedToWindow() { // The below solves: https://github.com/rive-app/rive-react-native/issues/198 diff --git a/android/src/main/java/com/rivereactnative/RiveReactNativeViewManager.kt b/android/src/main/java/com/rivereactnative/RiveReactNativeViewManager.kt index c0cbe9e..c730240 100644 --- a/android/src/main/java/com/rivereactnative/RiveReactNativeViewManager.kt +++ b/android/src/main/java/com/rivereactnative/RiveReactNativeViewManager.kt @@ -1,6 +1,5 @@ package com.rivereactnative -import android.util.Log import com.facebook.react.bridge.ReadableArray import com.facebook.react.common.MapBuilder import com.facebook.react.uimanager.SimpleViewManager @@ -115,6 +114,11 @@ class RiveReactNativeViewManager : SimpleViewManager() { return RiveReactNativeView(reactContext) } + override fun onDropViewInstance(view: RiveReactNativeView) { + view.dispose(); + super.onDropViewInstance(view) + } + override fun onAfterUpdateTransaction(view: RiveReactNativeView) { super.onAfterUpdateTransaction(view) view.update()