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 3, 2023
1 parent b31ea17 commit df31494
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 df31494

Please sign in to comment.