Skip to content

Commit

Permalink
sort of got reset in
Browse files Browse the repository at this point in the history
  • Loading branch information
mjtalbot committed May 7, 2021
1 parent bcb7136 commit 3822912
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Example-iOS/Source/UIkit/LoopMode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,13 @@ class LoopModeController: UIViewController {
)

loopModeView.triggeredResetButton = {
loopModeView.riveView.reset()

// TODO: just calling reset on an existing file is really not so hot.
loopModeView.riveView.configure(
withRiveFile: getRiveFile(resourceName: self.loopResourceName),
andAutoPlay: false
)
}
loopModeView.triggeredForwardsButton = {
self.direction = Direction.DirectionForwards
Expand Down
22 changes: 21 additions & 1 deletion Source/Views/RiveView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public class RiveView: UIView {

// Advance the artboard, this will ensure the first
// frame is displayed when the artboard is drawn
artboard.advance(by: 0)
// artboard.advance(by: 0)

// Start the animation loop
if autoPlay {
Expand All @@ -91,6 +91,8 @@ public class RiveView: UIView {
}else {
play()
}
}else {
advance(delta: 0)
}
}

Expand Down Expand Up @@ -125,6 +127,24 @@ public class RiveView: UIView {
displayLink?.isPaused=true
}

func clear() {
playingAnimations.removeAll()
playingStateMachines.removeAll()
animations.removeAll()
stateMachines.removeAll()
stopTimer()
lastTime=0
}

public func reset() {
clear()
stopTimer()
if let riveFile = self.riveFile {
// TODO: this is totally not enough to reset the file. i guess its because the file's artboard is already changed.
configure(withRiveFile: riveFile, andAutoPlay: autoPlay)
}
}


// Animates a frame
@objc func tick() {
Expand Down

0 comments on commit 3822912

Please sign in to comment.