mirror of
https://github.com/rive-app/rive-ios.git
synced 2026-01-18 17:11:28 +01:00
Gave RiveViewModel specialized inits so that users are presented without only an animation or a state machine param
This commit is contained in:
committed by
Zachary Duncan
parent
a4387fc273
commit
79f31196f3
@@ -18,10 +18,10 @@ class MultipleAnimationsController: UIViewController {
|
||||
@IBOutlet weak var rviewStar: RiveView!
|
||||
|
||||
var rSquareGoAround = RiveViewModel(
|
||||
fileName: "artboard_animations", artboardName: "Square", animationName: "goaround"
|
||||
fileName: "artboard_animations", animationName: "goaround", artboardName: "Square"
|
||||
)
|
||||
var rSquareRollAround = RiveViewModel(
|
||||
fileName: "artboard_animations", artboardName: "Square", animationName: "rollaround"
|
||||
fileName: "artboard_animations", animationName: "rollaround", artboardName: "Square"
|
||||
)
|
||||
var rCircle = RiveViewModel(
|
||||
fileName: "artboard_animations", artboardName: "Circle"
|
||||
|
||||
@@ -19,11 +19,11 @@ struct SwiftMultipleAnimations: DismissableView {
|
||||
ScrollView{
|
||||
VStack {
|
||||
Text("Square - go around")
|
||||
RiveViewModel(model(), artboardName: "Square", animationName: "goaround").view()
|
||||
RiveViewModel(model(), animationName: "goaround", artboardName: "Square").view()
|
||||
.aspectRatio(1, contentMode: .fit)
|
||||
|
||||
Text("Square - roll around")
|
||||
RiveViewModel(model(), artboardName: "Square", animationName: "rollaround").view()
|
||||
RiveViewModel(model(), animationName: "rollaround", artboardName: "Square").view()
|
||||
.aspectRatio(1, contentMode: .fit)
|
||||
|
||||
Text("Circle")
|
||||
|
||||
@@ -17,7 +17,7 @@ struct SwiftTestParityAnimSM: DismissableView {
|
||||
SwiftVMPlayer(
|
||||
viewModels:
|
||||
RiveViewModel(fileName: "teststatemachine", stateMachineName: "State Machine 1", autoPlay: false),
|
||||
RiveViewModel(fileName: "testanimation", autoPlay: false, animationName: "Move")
|
||||
RiveViewModel(fileName: "testanimation", animationName: "Move", autoPlay: false)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class RiveSwitch: RiveViewModel {
|
||||
}
|
||||
|
||||
init() {
|
||||
super.init(fileName: "switch", fit: .fitCover, animationName: startAnimation)
|
||||
super.init(fileName: "switch", animationName: startAnimation, fit: .fitCover)
|
||||
}
|
||||
|
||||
func view(_ action: ((Bool) -> Void)? = nil) -> some View {
|
||||
|
||||
@@ -44,59 +44,98 @@ open class RiveViewModel: NSObject, ObservableObject, RiveFileDelegate, RiveStat
|
||||
|
||||
public init(
|
||||
_ model: RiveModel,
|
||||
stateMachineName: String? = nil,
|
||||
stateMachineName: String?,
|
||||
fit: RiveRuntime.Fit = .fitContain,
|
||||
alignment: RiveRuntime.Alignment = .alignmentCenter,
|
||||
autoPlay: Bool = true,
|
||||
artboardName: String? = nil,
|
||||
animationName: String? = nil
|
||||
artboardName: String? = nil
|
||||
) {
|
||||
self.riveModel = model
|
||||
self.fit = fit
|
||||
self.alignment = alignment
|
||||
self.autoPlay = autoPlay
|
||||
|
||||
super.init()
|
||||
|
||||
sharedInit(artboardName: artboardName, stateMachineName: stateMachineName, animationName: animationName)
|
||||
riveModel = model
|
||||
sharedInit(artboardName: artboardName, stateMachineName: stateMachineName, animationName: nil)
|
||||
}
|
||||
|
||||
public init(
|
||||
_ model: RiveModel,
|
||||
animationName: String? = nil,
|
||||
fit: RiveRuntime.Fit = .fitContain,
|
||||
alignment: RiveRuntime.Alignment = .alignmentCenter,
|
||||
autoPlay: Bool = true,
|
||||
artboardName: String? = nil
|
||||
) {
|
||||
self.fit = fit
|
||||
self.alignment = alignment
|
||||
self.autoPlay = autoPlay
|
||||
super.init()
|
||||
riveModel = model
|
||||
sharedInit(artboardName: artboardName, stateMachineName: nil, animationName: animationName)
|
||||
}
|
||||
|
||||
public init(
|
||||
fileName: String,
|
||||
stateMachineName: String? = nil,
|
||||
stateMachineName: String?,
|
||||
fit: RiveRuntime.Fit = .fitContain,
|
||||
alignment: RiveRuntime.Alignment = .alignmentCenter,
|
||||
autoPlay: Bool = true,
|
||||
artboardName: String? = nil,
|
||||
animationName: String? = nil
|
||||
artboardName: String? = nil
|
||||
) {
|
||||
riveModel = try! RiveModel(fileName: fileName)
|
||||
self.fit = fit
|
||||
self.alignment = alignment
|
||||
self.autoPlay = autoPlay
|
||||
|
||||
super.init()
|
||||
|
||||
sharedInit(artboardName: artboardName, stateMachineName: stateMachineName, animationName: animationName)
|
||||
riveModel = try! RiveModel(fileName: fileName)
|
||||
sharedInit(artboardName: artboardName, stateMachineName: stateMachineName, animationName: nil)
|
||||
}
|
||||
|
||||
public init(
|
||||
fileName: String,
|
||||
animationName: String? = nil,
|
||||
fit: RiveRuntime.Fit = .fitContain,
|
||||
alignment: RiveRuntime.Alignment = .alignmentCenter,
|
||||
autoPlay: Bool = true,
|
||||
artboardName: String? = nil
|
||||
) {
|
||||
self.fit = fit
|
||||
self.alignment = alignment
|
||||
self.autoPlay = autoPlay
|
||||
super.init()
|
||||
riveModel = try! RiveModel(fileName: fileName)
|
||||
sharedInit(artboardName: artboardName, stateMachineName: nil, animationName: animationName)
|
||||
}
|
||||
|
||||
public init(
|
||||
webURL: String,
|
||||
stateMachineName: String? = nil,
|
||||
stateMachineName: String?,
|
||||
fit: RiveRuntime.Fit = .fitContain,
|
||||
alignment: RiveRuntime.Alignment = .alignmentCenter,
|
||||
autoPlay: Bool = true,
|
||||
artboardName: String? = nil,
|
||||
animationName: String? = nil
|
||||
artboardName: String? = nil
|
||||
) {
|
||||
self.fit = fit
|
||||
self.alignment = alignment
|
||||
self.autoPlay = autoPlay
|
||||
|
||||
super.init()
|
||||
|
||||
riveModel = RiveModel(webURL: webURL, delegate: self)
|
||||
defaultModel = RiveModelBuffer(artboardName: artboardName, stateMachineName: stateMachineName, animationName: animationName)
|
||||
defaultModel = RiveModelBuffer(artboardName: artboardName, stateMachineName: stateMachineName, animationName: nil)
|
||||
}
|
||||
|
||||
public init(
|
||||
webURL: String,
|
||||
animationName: String? = nil,
|
||||
fit: RiveRuntime.Fit = .fitContain,
|
||||
alignment: RiveRuntime.Alignment = .alignmentCenter,
|
||||
autoPlay: Bool = true,
|
||||
artboardName: String? = nil
|
||||
) {
|
||||
self.fit = fit
|
||||
self.alignment = alignment
|
||||
self.autoPlay = autoPlay
|
||||
super.init()
|
||||
riveModel = RiveModel(webURL: webURL, delegate: self)
|
||||
defaultModel = RiveModelBuffer(artboardName: artboardName, stateMachineName: nil, animationName: animationName)
|
||||
}
|
||||
|
||||
private func sharedInit(artboardName: String?, stateMachineName: String?, animationName: String?) {
|
||||
|
||||
@@ -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, animationName: "one")
|
||||
let viewModel = RiveViewModel(model, animationName: "one", autoPlay: false)
|
||||
let view = viewModel.createRiveView()
|
||||
|
||||
view.playerDelegate = delegate
|
||||
|
||||
Reference in New Issue
Block a user