Skip to content

Commit

Permalink
Added documentation to RiveViewModel. Hid fpsCounter in RiveView.
Browse files Browse the repository at this point in the history
  • Loading branch information
duncandoit committed May 19, 2022
1 parent e5f1b24 commit 1057c74
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
7 changes: 2 additions & 5 deletions Source/Components/RiveView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ open class RiveView: RiveRendererView {
advance(delta: 0)
}

showFPS = true
showFPS = false
}

// MARK: - Controls
Expand Down Expand Up @@ -172,10 +172,7 @@ open class RiveView: RiveRendererView {
if let stateMachine = riveModel.stateMachine {
isPlaying = stateMachine.advance(by: delta) && wasPlaying

for stateChange in stateMachine.stateChanges() {
stateMachineDelegate?.stateMachine?(stateMachine, didChangeState: stateChange)
}
// stateMachine.stateChanges().forEach { stateMachineDelegate?.stateMachine?(stateMachine, didChangeState: $0) }
stateMachine.stateChanges().forEach { stateMachineDelegate?.stateMachine?(stateMachine, didChangeState: $0) }
}
else if let animation = riveModel.animation {
isPlaying = animation.advance(by: delta) && wasPlaying
Expand Down
27 changes: 27 additions & 0 deletions Source/Components/RiveViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,33 @@
import SwiftUI
import Combine

/// An object used for controlling a RiveView. For most common Rive files you should only need to interact with a `RiveViewModel` object.
///
/// - Usage:
/// - You should initialize with either an Animation name or a StateMachine name, but not both. Only one will be used and if both are given the StateMachine will be used.
/// - Default StateMachine or Animation from the file can be used by leaving their parameters nil
/// - Examples:
///
/// ```
/// // SwiftUI Example
/// struct Animation: View {
/// var body: some View {
/// RiveViewModel(fileName: "cool_rive_file").view()
/// }
/// }
/// ```
///
/// ```
/// // UIKit Example
/// class AnimationViewController: UIViewController {
/// @IBOutlet weak var riveView: RiveView!
/// var viewModel = RiveViewModel(fileName: "cool_rive_file")
///
/// override func viewDidLoad() {
/// viewModel.setView(riveView)
/// }
/// }
/// ```
open class RiveViewModel: NSObject, ObservableObject, RiveFileDelegate, RiveStateMachineDelegate, RivePlayerDelegate {
open private(set) var riveView: RiveView?
private var defaultModel: RiveModelBuffer!
Expand Down
2 changes: 1 addition & 1 deletion Tests/RiveDelegatesTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class DelegatesTest: XCTestCase {
let delegate = DrDelegate()
let file = try RiveFile(testfileName: "multiple_animations")
let model = RiveModel(riveFile: file)
let viewModel = RiveViewModel(model, autoPlay: false)
let viewModel = RiveViewModel(model, autoPlay: false, animationName: "one")
let view = viewModel.createRiveView()

view.playerDelegate = delegate
Expand Down

0 comments on commit 1057c74

Please sign in to comment.