rive-app / rive-react-native

MIT License
528 stars 36 forks source link

Cannot change state with trigger #117

Open wibimaster opened 3 years ago

wibimaster commented 3 years ago

Description

I'm trying to update the animation state with a trigger. But when I call the "fireState" method, the only trace I got on onStateChanged is mood_state, AnyState or mood_state, ExitState.

Provide a Repro

const riveRef = React.useRef(null);
// [...]
<Rive
  ref={riveRef}
  resourceName={'moods'}
  alignment={Alignment.Center}
  fit={Fit.FitWidth}
  stateMachineName={'mood_state'}
  autoplay={true}
  onStateChanged={(smn, sn) => {
    console.log('State changed', smn, sn);
  }}
  />
<Button
  title={'Trigger happy'}
  onPress={() => {
    riveRef.current?.fireState('mood_state', 'trigger_happy');
  }}
/>
<Button
  title={'Trigger content'}
  onPress={() => {
  riveRef.current?.fireState('mood_state', 'trigger_content');
  }}
/>

Source .riv/.rev file

moods.riv - v7 moods.rev Permanent link : moods.zip

Expected behavior

Trigger fire should update the animation with the good state

Screenshots

N.A.

Device & Versions (please complete the following information)

Additional context

N.A.

wibimaster commented 3 years ago

I'm able to have the desired effect by adding a number input on the blend state ; For mixing 2 animation : image And on the React side :

<Button
  title={'Trigger happy'}
  onPress={() => {
    riveRef.current?.setInputState('mood_state', 'mix', 5);
    riveRef.current?.fireState('mood_state', 'trigger_happy');
  }}
/>

Should it be the same as no input value, and 0 for each animation to mix ?

Is it an Android Rive package bug ?

Thanks !