Skip to content

Commit cf99b1d

Browse files
committed
fix(android-legacy): refresh the VMI snapshot eagerly when binding changes
The snapshot getter's posted-refresh design broke the read-after-bind contract: autoplay-false-trigger's issue #156 guard binds via the dataBind prop and does a one-shot getViewModelInstance() read, which returned the stale (null) snapshot on android-legacy (iOS still reads synchronously). Binding always happens on the main thread, so refresh the snapshot right where it changes (bindViewModelInstance and bindToStateMachine) — a JS read after binding then sees a fresh value with no blocking and no polling needed.
1 parent 7677a56 commit cf99b1d

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ class RiveReactNativeView(context: ThemedReactContext) : FrameLayout(context) {
165165
if (!stateMachines.isNullOrEmpty()) {
166166
stateMachines.first().viewModelInstance = vmi
167167
}
168+
// Keep the snapshot fresh at the moment binding changes so a JS-side
169+
// read right after binding sees the instance without waiting for a
170+
// posted refresh (guards the read-after-bind contract, issue #156).
171+
lastKnownViewModelInstance = readViewModelInstanceOnMain()
168172
}
169173

170174
// Cache maintained on the main thread: the controller's state-machine list
@@ -381,6 +385,9 @@ class RiveReactNativeView(context: ThemedReactContext) : FrameLayout(context) {
381385
}
382386
}
383387
}
388+
// Keep the snapshot fresh at the moment binding changes — see
389+
// lastKnownViewModelInstance.
390+
lastKnownViewModelInstance = readViewModelInstanceOnMain()
384391
}
385392

386393
private fun convertEventProperties(properties: Map<String, Any>?): Map<String, EventPropertiesOutput>? {

0 commit comments

Comments
 (0)