Skip to content

Commit 445c227

Browse files
mfazekasclaude
andcommitted
fix(android): play state machine after binding mode reload
- Add isFirstConfigure flag to track initial load - Call play(stateMachineName, isStateMachine: true) after reload - Only play on subsequent reloads, not on first configure - Ensures state machine restarts with new binding iOS note: iOS already calls baseViewModel.play() in applyDataBinding() which handles non-first updates through the didSet mechanism 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 1b53f03 commit 445c227

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

android/src/main/java/com/rive/RiveReactNativeView.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class RiveReactNativeView(context: ThemedReactContext) : FrameLayout(context) {
4747
private var eventListeners: MutableList<RiveFileController.RiveEventListener> = mutableListOf()
4848
private val viewReadyDeferred = CompletableDeferred<Boolean>()
4949
private var _activeStateMachineName: String? = null
50+
private var isFirstConfigure = true
5051

5152
init {
5253
riveAnimationView = RiveAnimationView(context)
@@ -59,6 +60,8 @@ class RiveReactNativeView(context: ThemedReactContext) : FrameLayout(context) {
5960
}
6061

6162
fun configure(config: ViewConfiguration, reload: Boolean = false) {
63+
val wasFirstConfigure = isFirstConfigure
64+
6265
if (reload) {
6366
riveAnimationView?.setRiveFile(
6467
config.riveFile,
@@ -70,6 +73,15 @@ class RiveReactNativeView(context: ThemedReactContext) : FrameLayout(context) {
7073
fit = config.fit
7174
)
7275
_activeStateMachineName = getSafeStateMachineName()
76+
77+
// Play state machine after reload (but not on first configure)
78+
if (!wasFirstConfigure) {
79+
_activeStateMachineName?.let { smName ->
80+
riveAnimationView?.play(smName, isStateMachine = true)
81+
}
82+
}
83+
84+
isFirstConfigure = false
7385
} else {
7486
riveAnimationView?.alignment = config.alignment
7587
riveAnimationView?.fit = config.fit

ios/RiveReactNativeView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class RiveReactNativeView: UIView, RiveStateMachineDelegate {
3232
private var baseViewModel: RiveViewModel?
3333
private var eventListeners: [(UnifiedRiveEvent) -> Void] = []
3434
private var viewReadyContinuation: CheckedContinuation<Void, Never>?
35+
private var isFirstConfigure = true
3536
private var isViewReady = false
3637
private weak var viewSource: RiveViewSource?
3738

0 commit comments

Comments
 (0)