Skip to content

Commit

Permalink
fix: dispose controller state on view drop
Browse files Browse the repository at this point in the history
  • Loading branch information
HayesGordon committed Oct 12, 2023
1 parent ca655cc commit 0e4b65a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -115,6 +114,11 @@ class RiveReactNativeViewManager : SimpleViewManager<RiveReactNativeView>() {
return RiveReactNativeView(reactContext)
}

override fun onDropViewInstance(view: RiveReactNativeView) {
view.dispose();
super.onDropViewInstance(view)
}

override fun onAfterUpdateTransaction(view: RiveReactNativeView) {
super.onAfterUpdateTransaction(view)
view.update()
Expand Down

0 comments on commit 0e4b65a

Please sign in to comment.