From 0e4b65af7cd4c38e138ebf65c4e10ae09afa8351 Mon Sep 17 00:00:00 2001 From: Gordon Hayes Date: Tue, 3 Oct 2023 18:12:37 +0200 Subject: [PATCH] fix: dispose controller state on view drop --- .../main/java/com/rivereactnative/RiveReactNativeView.kt | 6 ++++++ .../java/com/rivereactnative/RiveReactNativeViewManager.kt | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) 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()