Skip to content

Commit 98dfda8

Browse files
HayesGordonzplata
authored andcommitted
fix: missing isStateMachine argument for Android
1 parent f3f9136 commit 98dfda8

File tree

7 files changed

+16
-13
lines changed

7 files changed

+16
-13
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,14 @@ class RiveReactNativeView(private val context: ThemedReactContext) : FrameLayout
166166
reactContext.getJSModule(RCTEventEmitter::class.java).receiveEvent(id, Events.STATE_CHANGED.toString(), data)
167167
}
168168

169-
fun play(animationName: String, rnLoopMode: RNLoopMode, rnDirection: RNDirection) {
169+
fun play(animationName: String, rnLoopMode: RNLoopMode, rnDirection: RNDirection, isStateMachine: Boolean) {
170170
val loop = RNLoopMode.mapToRiveLoop(rnLoopMode)
171171
val direction = RNDirection.mapToRiveDirection(rnDirection)
172172
if (animationName.isEmpty()) {
173-
riveAnimationView.play(loop, direction)
173+
riveAnimationView.play(loop, direction) // intentionally we skipped areStateMachines argument to keep same behaviour as it is in the native sdk
174174
} else {
175175
try {
176-
riveAnimationView.play(animationName, loop, direction)
176+
riveAnimationView.play(animationName, loop, direction, isStateMachine)
177177
} catch (ex: RiveException) {
178178
handleRiveException(ex)
179179
}

android/src/main/java/com/rivereactnative/RiveReactNativeViewManager.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ class RiveReactNativeViewManager : SimpleViewManager<RiveReactNativeView>() {
2727
val animationName = it.getString(0)!!
2828
val loopMode = it.getString(1)!!
2929
val direction = it.getString(2)!!
30+
val isStateMachine = it.getBoolean(3)
3031
view.run {
3132
val rnLoopMode = RNLoopMode.mapToRNLoopMode(loopMode)
3233
val rnDirection = RNDirection.mapToRNDirection(direction)
33-
play(animationName, rnLoopMode, rnDirection)
34+
play(animationName, rnLoopMode, rnDirection, isStateMachine)
3435
}
3536
}
3637

ios/RiveReactNativeView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,10 @@ class RiveReactNativeView: UIView, RivePlayerDelegate, RiveStateMachineDelegate
187187

188188
// MARK: - Playback Controls
189189

190-
func play(animationName: String? = nil, rnLoopMode: RNLoopMode, rnDirection: RNDirection) {
190+
func play(animationName: String? = nil, rnLoopMode: RNLoopMode, rnDirection: RNDirection, isStateMachine: Bool) {
191191
let loop = RNLoopMode.mapToRiveLoop(rnLoopMode: rnLoopMode)
192192
let direction = RNDirection.mapToRiveDirection(rnDirection: rnDirection)
193-
if (animationName ?? "").isEmpty {
193+
if (animationName ?? "").isEmpty || isStateMachine {
194194
viewModel.play(loop: loop, direction: direction)
195195
} else {
196196
viewModel.play(animationName: animationName, loop: loop, direction: direction)

ios/RiveReactNativeViewManager.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ @interface RCT_EXTERN_MODULE(RiveReactNativeViewManager, RCTViewManager)
1919
RCT_EXPORT_VIEW_PROPERTY(onStateChanged, RCTDirectEventBlock)
2020
RCT_EXPORT_VIEW_PROPERTY(onError, RCTDirectEventBlock)
2121

22-
RCT_EXTERN_METHOD(play:(nonnull NSNumber *)node animationName:(nonnull NSString)animationName loop:(NSString)loopMode direction:(NSString)direction)
22+
RCT_EXTERN_METHOD(play:(nonnull NSNumber *)node animationName:(nonnull NSString)animationName loop:(NSString)loopMode direction:(NSString)direction isStateMachine:(BOOL)isStateMachine)
2323
RCT_EXTERN_METHOD(pause:(nonnull NSNumber *)node)
2424
RCT_EXTERN_METHOD(stop:(nonnull NSNumber *)node)
2525
RCT_EXTERN_METHOD(reset:(nonnull NSNumber *)node)

ios/RiveReactNativeViewManager.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ class RiveReactNativeViewManager: RCTViewManager {
88
return RiveReactNativeView()
99
}
1010

11-
@objc func play(_ node: NSNumber, animationName: String, loop: String, direction: String) {
11+
@objc func play(_ node: NSNumber, animationName: String, loop: String, direction: String, isStateMachine: Bool) {
1212
DispatchQueue.main.async {
1313
let component = self.bridge.uiManager.view(forReactTag: node) as! RiveReactNativeView
14-
component.play(animationName: animationName, rnLoopMode: RNLoopMode.mapToRNLoopMode(value: loop), rnDirection: RNDirection.mapToRNDirection(value: direction))
14+
component.play(animationName: animationName, rnLoopMode: RNLoopMode.mapToRNLoopMode(value: loop), rnDirection: RNDirection.mapToRNDirection(value: direction), isStateMachine: isStateMachine);
1515

1616
}
1717
}

src/Rive.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,15 @@ const RiveContainer = React.forwardRef<RiveRef, Props>(
204204
const play = useCallback<RiveRef[ViewManagerMethod.play]>(
205205
(
206206
// eslint-disable-next-line no-shadow
207-
animationName = '', // TODO change
207+
animationName = '',
208208
loop = LoopMode.Auto,
209-
direction = Direction.Auto
209+
direction = Direction.Auto,
210+
isStateMachine = false
210211
) => {
211212
UIManager.dispatchViewManagerCommand(
212213
findNodeHandle(riveRef.current),
213214
ViewManagerMethod.play,
214-
[animationName, loop, direction]
215+
[animationName, loop, direction, isStateMachine]
215216
);
216217
},
217218
[]

src/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ export type RiveRef = {
88
play: (
99
animationName?: string,
1010
loop?: LoopMode,
11-
direction?: Direction
11+
direction?: Direction,
12+
isStateMachine?: boolean
1213
) => void;
1314
pause: () => void;
1415
stop: () => void;

0 commit comments

Comments
 (0)