Skip to content

Commit

Permalink
Force advancing on iOS if advancing by 0
Browse files Browse the repository at this point in the history
Similar to Android: https://github.com/rive-app/rive/pull/8725

With changes from Option C, the C++ runtime will report that an animation should not continue if advancing by 0. This causes the iOS advance logic to break, and if stopping / pausing and then playing, the advance by 0 will continually return false, not allowing an animation to play again.

Diffs=
d527114521 Force advancing on iOS if advancing by 0 (#8766)

Co-authored-by: David Skuza <[email protected]>
  • Loading branch information
dskuza and dskuza committed Dec 19, 2024
1 parent a71159d commit 1b5de5f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14dcaa0cdedd07c92b77bc013567251ffc29b2c6
d5271145212650f72b01b239afb4f5607ee1a9b6
12 changes: 8 additions & 4 deletions Source/RiveView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -355,15 +355,19 @@ open class RiveView: RiveRendererView {
RiveLogger.log(view: self, event: .eventReceived(event.name()))
stateMachineDelegate?.onRiveEventReceived?(onRiveEvent: event)
}
}
isPlaying = stateMachine.advance(by: delta) && wasPlaying

}
var shouldAdvance = stateMachine.advance(by: delta)
if delta == 0 {
shouldAdvance = true
}
isPlaying = shouldAdvance && wasPlaying

if let delegate = stateMachineDelegate {
stateMachine.stateChanges().forEach { delegate.stateMachine?(stateMachine, didChangeState: $0) }
}
} else if let animation = riveModel?.animation {
isPlaying = animation.advance(by: delta) && wasPlaying

if isPlaying {
if animation.didLoop() {
playerDelegate?.player(loopedWithModel: riveModel, type: Int(animation.loop()))
Expand Down
2 changes: 1 addition & 1 deletion Tests/RiveDelegatesTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ class DelegatesTest: XCTestCase {
XCTAssertEqual(delegate.stateMachineStates[1], "ExitState")

// takes an extra advance to trigger
view.advance(delta:0)
view.advance(delta:0.1)
XCTAssertEqual(delegate.stateMachinePauses.count, 1)
}

Expand Down

0 comments on commit 1b5de5f

Please sign in to comment.