Skip to content

Commit 1f325e7

Browse files
authored
fix(android): fix triggerInput crash on Android (#69)
triggerInput was incorrectly validating triggers as booleans, causing 'State machine input is not a boolean' error. Now uses proper InputType.Trigger validation. Also marks legacy state machine input methods as @deprecated.
1 parent 148c363 commit 1f325e7

3 files changed

Lines changed: 22 additions & 6 deletions

File tree

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import app.rive.runtime.kotlin.core.RiveOpenURLEvent
1717
import app.rive.runtime.kotlin.core.SMIBoolean
1818
import app.rive.runtime.kotlin.core.SMIInput
1919
import app.rive.runtime.kotlin.core.SMINumber
20+
import app.rive.runtime.kotlin.core.SMITrigger
2021
import app.rive.runtime.kotlin.core.ViewModelInstance
2122
import app.rive.runtime.kotlin.core.errors.ViewModelException
2223
import com.margelo.nitro.rive.EventPropertiesOutput
@@ -283,15 +284,13 @@ class RiveReactNativeView(context: ThemedReactContext) : FrameLayout(context) {
283284
handleInput(
284285
name = name,
285286
path = path,
286-
type = InputType.BooleanInput,
287-
onSuccess = { _ ->
288-
// Use Rive Android's queue system to actually set the input
287+
type = InputType.Trigger,
288+
onSuccess = {
289289
riveAnimationView?.controller?.fireState(
290290
stateMachineName = activeStateMachineName,
291291
inputName = name,
292292
path = path
293293
)
294-
true
295294
}
296295
)
297296
}
@@ -400,6 +399,7 @@ class RiveReactNativeView(context: ThemedReactContext) : FrameLayout(context) {
400399
private sealed class InputType<T> {
401400
data object Number : InputType<Double>()
402401
data object BooleanInput : InputType<Boolean>()
402+
data object Trigger : InputType<Unit>()
403403
}
404404

405405
/**
@@ -420,6 +420,7 @@ class RiveReactNativeView(context: ThemedReactContext) : FrameLayout(context) {
420420
when (type) {
421421
is InputType.Number -> if (smi !is SMINumber) throw Error("State machine input is not a number")
422422
is InputType.BooleanInput -> if (smi !is SMIBoolean) throw Error("State machine input is not a boolean")
423+
is InputType.Trigger -> if (smi !is SMITrigger) throw Error("State machine input is not a trigger")
423424
}
424425

425426
try {

example/android/.kotlin/sessions/kotlin-compiler-12952147549113407283.salive

Whitespace-only changes.

src/specs/RiveView.nitro.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,52 +72,67 @@ export interface RiveViewMethods extends HybridViewMethods {
7272

7373
/**
7474
* Adds an event listener to the Rive view
75+
* @deprecated Use data binding instead. See https://rive.app/docs/runtimes/data-binding
7576
* @param onEvent - The function to call when an event is triggered
7677
*/
7778
onEventListener(onEvent: (event: UnifiedRiveEvent) => void): void;
78-
/** Removes all event listeners from the Rive view */
79+
/**
80+
* Removes all event listeners from the Rive view
81+
* @deprecated Use data binding instead. See https://rive.app/docs/runtimes/data-binding
82+
*/
7983
removeEventListeners(): void;
8084
/**
8185
* Sets a number state machine input on the Rive view
86+
* @deprecated Use data binding instead. See https://rive.app/docs/runtimes/data-binding
8287
* @param name - The name of the state machine input
8388
* @param value - The value to set the state machine input to
8489
* @param path - The optional path to the state machine input on a nested artboard
8590
*/
8691
setNumberInputValue(name: string, value: number, path?: string): void;
8792
/**
8893
* Gets a number state machine input from the Rive view
94+
* @deprecated Use data binding instead. See https://rive.app/docs/runtimes/data-binding
8995
* @param name - The name of the state machine input
9096
* @param path - The optional path to the state machine input on a nested artboard
9197
* @returns The value of the state machine input
9298
*/
9399
getNumberInputValue(name: string, path?: string): number;
94100
/**
95101
* Sets a boolean state machine input on the Rive view
102+
* @deprecated Use data binding instead. See https://rive.app/docs/runtimes/data-binding
96103
* @param name - The name of the state machine input
97104
* @param value - The value to set the state machine input to
98105
* @param path - The optional path to the state machine input on a nested artboard
99106
*/
100107
setBooleanInputValue(name: string, value: boolean, path?: string): void;
101108
/**
102109
* Gets a boolean state machine input from the Rive view
110+
* @deprecated Use data binding instead. See https://rive.app/docs/runtimes/data-binding
103111
* @param name - The name of the state machine input
104112
* @param path - The optional path to the state machine input on a nested artboard
105113
* @returns The value of the state machine input
106114
*/
107115
getBooleanInputValue(name: string, path?: string): boolean;
108116
/**
109117
* Triggers a trigger state machine input on the Rive view
118+
* @deprecated Use data binding instead. See https://rive.app/docs/runtimes/data-binding
110119
* @param name - The name of the state machine input
111120
* @param path - The optional path to the state machine input on a nested artboard
112121
*/
113122
triggerInput(name: string, path?: string): void;
114123
/**
115124
* Sets the text run value on the Rive view
116-
* @param text - The text to set the text run value to
125+
* @deprecated Use data binding instead. See https://rive.app/docs/runtimes/data-binding
126+
* @param name - The name of the text run
127+
* @param value - The text to set the text run value to
128+
* @param path - The optional path to the text run on a nested artboard
117129
*/
118130
setTextRunValue(name: string, value: string, path?: string): void;
119131
/**
120132
* Gets the text run value from the Rive view
133+
* @deprecated Use data binding instead. See https://rive.app/docs/runtimes/data-binding
134+
* @param name - The name of the text run
135+
* @param path - The optional path to the text run on a nested artboard
121136
* @returns The text run value
122137
*/
123138
getTextRunValue(name: string, path?: string): string;

0 commit comments

Comments
 (0)