Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate bitcode flag #89

Merged
merged 3 commits into from
Jul 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions Example-iOS/Source/SwiftUI/Button/RiveButtonBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,30 @@ struct RiveButtonBridge: UIViewRepresentable {

/// Constructs the view
func makeUIView(context: Context) -> RiveView {
let riveView = RiveView(
riveFile: getRiveFile(resourceName: resource),
fit: fit,
alignment: alignment,
artboard: artboard,
animation: animation,
playDelegate: context.coordinator,
pauseDelegate: context.coordinator,
stopDelegate: context.coordinator
)
return riveView

do {
let riveView = try RiveView(
riveFile: getRiveFile(resourceName: resource),
fit: fit,
alignment: alignment,
artboard: artboard,
animation: animation,
playDelegate: context.coordinator,
pauseDelegate: context.coordinator,
stopDelegate: context.coordinator
)
return riveView
}
catch {
print(error)
return RiveView()
}
}

func updateUIView(_ riveView: RiveView, context: UIViewRepresentableContext<RiveButtonBridge>) {
play ? riveView.play() : riveView.pause()
play ? try? riveView.play() : riveView.pause()
}

static func dismantleUIView(_ riveView: RiveView, coordinator: Self.Coordinator) {
riveView.stop()
}
Expand Down
4 changes: 4 additions & 0 deletions Example-iOS/Source/SwiftUI/Explorer/RiveExplorer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ struct RiveExplorer: View {
case .pause, .stop:
Image(systemName: "play.circle")
Text("Play")
@unknown default:
fatalError("Unknown playback value")
}


}
Spacer()
Button(action: dismiss, label: {
Expand Down
75 changes: 40 additions & 35 deletions Example-iOS/Source/SwiftUI/Explorer/RiveExplorerBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ class RiveController: ObservableObject {
alignment: RiveRuntime.Alignment = .alignmentCenter,
autoplay: Bool = false,
playAnimation: String? = nil
) {
) {
self.fit = fit
self.alignment = alignment
self.playback = autoplay ? .play : .stop
self.resource = resource
self.rive = getRiveFile(resourceName: resource)
// TODO: fix this
self.rive = (try? getRiveFile(resourceName: resource))!
self.playAnimation = playAnimation
}

Expand Down Expand Up @@ -81,26 +82,30 @@ struct RiveExplorerBridge: UIViewRepresentable {

/// Constructs the view
func makeUIView(context: Context) -> RiveView {
let riveView = RiveView(
riveFile: controller.rive,
fit: controller.fit,
alignment: controller.alignment,
autoplay: controller.playback == Playback.play,
artboard: controller.activeArtboard,
loopDelegate: context.coordinator,
playDelegate: context.coordinator,
pauseDelegate: context.coordinator,
inputsDelegate: context.coordinator
)

// Update the controller with the correct artboard
if let artboard = riveView.artboard {
controller.artboard = artboard
do {
let riveView = try RiveView(
riveFile: controller.rive,
fit: controller.fit,
alignment: controller.alignment,
autoplay: controller.playback == Playback.play,
artboard: controller.activeArtboard,
loopDelegate: context.coordinator,
playDelegate: context.coordinator,
pauseDelegate: context.coordinator,
inputsDelegate: context.coordinator
)
// Update the controller with the correct artboard
if let artboard = riveView.artboard {
controller.artboard = artboard
}
return riveView
}
catch {
return RiveView()
}

return riveView
}

/// Called when the view model changes
func updateUIView(_ uiView: RiveView, context: UIViewRepresentableContext<RiveExplorerBridge>) {
// Set the properties
Expand All @@ -113,7 +118,7 @@ struct RiveExplorerBridge: UIViewRepresentable {
// Pause all playback
uiView.pause()
// Reconfigure with the new artboard
uiView.configure(controller.rive, andArtboard: artboardName, andAutoPlay: false)
try? uiView.configure(controller.rive, andArtboard: artboardName, andAutoPlay: false)
controller.artboard = uiView.artboard
}
}
Expand All @@ -122,13 +127,13 @@ struct RiveExplorerBridge: UIViewRepresentable {
if let playAnimation = controller.playAnimation {
uiView.pause()
if uiView.animationNames().contains(playAnimation) {
uiView.play(animationName: playAnimation)
try? uiView.play(animationName: playAnimation)
} else if uiView.stateMachineNames().contains(playAnimation) {
uiView.play(animationName: playAnimation, isStateMachine: true)
try? uiView.play(animationName: playAnimation, isStateMachine: true)
}
} else {
if controller.playback == .play {
uiView.play()
try? uiView.play()
} else {
uiView.pause()
}
Expand Down Expand Up @@ -167,23 +172,23 @@ extension RiveExplorerBridge {
self.inputsAction = inputsAction

// This stuff is all experimental and may get removed
// let fitSubscription = controller.$fit.receive(on: RunLoop.main).sink(receiveValue: fitDidChange)
// subscribers.append(fitSubscription)
// let fitSubscription = controller.$fit.receive(on: RunLoop.main).sink(receiveValue: fitDidChange)
// subscribers.append(fitSubscription)
}

// Cancel subscribers when Coordinator is deinitialized
// deinit {
// subscribers.forEach { $0.cancel() }
// }
//
// var fitDidChange: (Fit) -> Void = { fit in
// print("Fit changed to \(fit)")
// }
// deinit {
// subscribers.forEach { $0.cancel() }
// }
//
// var fitDidChange: (Fit) -> Void = { fit in
// print("Fit changed to \(fit)")
// }

func loop(_ animationName: String, type: Int) {
loopAction?(animationName, type)
}

loopAction?(animationName, type)
}
func play(_ animationName: String, isStateMachine: Bool) {
controller.playback = .play
playAction?(animationName)
Expand Down
36 changes: 21 additions & 15 deletions Example-iOS/Source/SwiftUI/ProgressBar/RiveProgressBarBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,33 @@ struct RiveProgressBarBridge: UIViewRepresentable {

/// Constructs the view
func makeUIView(context: Context) -> RiveView {
let riveView = RiveView(
riveFile: getRiveFile(resourceName: resource),
fit: fit,
alignment: alignment,
autoplay: true,
stateMachine: stateMachine
)
do {
let riveView = try RiveView(
riveFile: getRiveFile(resourceName: resource),
fit: fit,
alignment: alignment,
autoplay: true,
stateMachine: stateMachine
)
// Always keep the 100 set; just how this state machine works
try? riveView.setBooleanState(stateMachine, inputName: input100Name, value: true)
return riveView
}
catch{
print(error)
return RiveView()
}

// Always keep the 100 set; just how this state machine works
riveView.setBooleanState(stateMachine, inputName: input100Name, value: true)
return riveView
}

static func dismantleUIView(_ riveView: RiveView, coordinator: Self.Coordinator) {
riveView.stop()
}

func updateUIView(_ riveView: RiveView, context: UIViewRepresentableContext<RiveProgressBarBridge>) {
riveView.setBooleanState(stateMachine, inputName: input75Name, value: health < 100)
riveView.setBooleanState(stateMachine, inputName: input50Name, value: health <= 66)
riveView.setBooleanState(stateMachine, inputName: input25Name, value: health <= 33)
riveView.setBooleanState(stateMachine, inputName: input0Name, value: health <= 0)
try? riveView.setBooleanState(stateMachine, inputName: input75Name, value: health < 100)
try? riveView.setBooleanState(stateMachine, inputName: input50Name, value: health <= 66)
try? riveView.setBooleanState(stateMachine, inputName: input25Name, value: health <= 33)
try? riveView.setBooleanState(stateMachine, inputName: input0Name, value: health <= 0)
}
}
26 changes: 15 additions & 11 deletions Example-iOS/Source/SwiftUI/Switch/RiveSwitchBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,27 @@ struct RiveSwitchBridge: UIViewRepresentable {

/// Constructs the view
func makeUIView(context: Context) -> RiveView {
let riveView = RiveView(
riveFile: getRiveFile(resourceName: resource),
fit: fit,
alignment: alignment,
artboard: artboard,
animation: startAnimation
)
return riveView
do {
let riveView = try RiveView(
riveFile: getRiveFile(resourceName: resource),
fit: fit,
alignment: alignment,
artboard: artboard,
animation: startAnimation
)
return riveView
} catch {
return RiveView()
}
}

func updateUIView(_ riveView: RiveView, context: UIViewRepresentableContext<RiveSwitchBridge>) {
riveView.stop()
if switchToOn {
riveView.play(animationName: onAnimation)
try? riveView.play(animationName: onAnimation)
}
if switchToOff {
riveView.play(animationName: offAnimation)
try? riveView.play(animationName: offAnimation)
}
}

Expand Down
10 changes: 5 additions & 5 deletions Example-iOS/Source/UIkit/BlendModes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ class BlendModeViewController: UIViewController {

let view = RiveView()
view.fit = Fit.fitContain
guard let riveFile = RiveFile(resource: resourceName) else {
fatalError("Failed to load RiveFile")

guard let riveFile = try? RiveFile(resource: resourceName) else {
fatalError("Failed to import Rive file.")
}

view.configure(riveFile)
// self.view.addSubview(view)
try? view.configure(riveFile)
self.view = view

}

override public func viewDidDisappear(_ animated: Bool) {
Expand Down
2 changes: 1 addition & 1 deletion Example-iOS/Source/UIkit/Layout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class LayoutViewController: UIViewController {
fatalError("Could not find LayoutView")
}

layoutView.riveView.configure(getRiveFile(resourceName: resourceName))
try? layoutView.riveView.configure(getRiveFile(resourceName: resourceName))

func setFit(name:String) {
var fit: Fit = .fitContain
Expand Down
31 changes: 15 additions & 16 deletions Example-iOS/Source/UIkit/LoopMode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,16 @@ class LoopModeController: UIViewController {
guard let loopModeView = view as? LoopMode else {
fatalError("Could not find LayoutView")
}

loopModeView.riveView.configure(
try? loopModeView.riveView.configure(
getRiveFile(resourceName: loopResourceName),
andAutoPlay: false
)

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

// TODO: just calling reset on an existing file is really not so hot.
loopModeView.riveView.configure(
try? loopModeView.riveView.configure(
getRiveFile(resourceName: self.loopResourceName),
andAutoPlay: false
)
Expand All @@ -123,42 +122,42 @@ class LoopModeController: UIViewController {
}

loopModeView.triggeredRotatePlayButton = {
loopModeView.riveView.play(animationName:"oneshot", direction: self.direction)
try? loopModeView.riveView.play(animationName:"oneshot", direction: self.direction)
}
loopModeView.triggeredRotateOneShotButton = {
loopModeView.riveView.play(animationName:"oneshot", loop: Loop.loopOneShot, direction: self.direction)
try? loopModeView.riveView.play(animationName:"oneshot", loop: Loop.loopOneShot, direction: self.direction)
}
loopModeView.triggeredRotateLoopButton = {
loopModeView.riveView.play(animationName:"oneshot", loop: Loop.loopLoop, direction: self.direction)
try? loopModeView.riveView.play(animationName:"oneshot", loop: Loop.loopLoop, direction: self.direction)
}
loopModeView.triggeredRotatePingPongButton = {
loopModeView.riveView.play(animationName:"oneshot", loop: Loop.loopPingPong, direction: self.direction)
try? loopModeView.riveView.play(animationName:"oneshot", loop: Loop.loopPingPong, direction: self.direction)
}

loopModeView.triggeredLoopDownPlayButton = {
loopModeView.riveView.play(animationName:"loop", direction: self.direction)
try? loopModeView.riveView.play(animationName:"loop", direction: self.direction)
}
loopModeView.triggeredLoopDownOneShotButton = {
loopModeView.riveView.play(animationName:"loop", loop: Loop.loopOneShot, direction: self.direction)
try? loopModeView.riveView.play(animationName:"loop", loop: Loop.loopOneShot, direction: self.direction)
}
loopModeView.triggeredLoopDownLoopButton = {
loopModeView.riveView.play(animationName:"loop", loop: Loop.loopLoop, direction: self.direction)
try? loopModeView.riveView.play(animationName:"loop", loop: Loop.loopLoop, direction: self.direction)
}
loopModeView.triggeredLoopDownPingPongButton = {
loopModeView.riveView.play(animationName:"loop", loop: Loop.loopPingPong, direction: self.direction)
try? loopModeView.riveView.play(animationName:"loop", loop: Loop.loopPingPong, direction: self.direction)
}

loopModeView.triggeredLtrPlayButton = {
loopModeView.riveView.play(animationName:"pingpong", direction: self.direction)
try? loopModeView.riveView.play(animationName:"pingpong", direction: self.direction)
}
loopModeView.triggeredLtrLoopButton = {
loopModeView.riveView.play(animationName:"pingpong", loop: Loop.loopLoop, direction: self.direction)
try? loopModeView.riveView.play(animationName:"pingpong", loop: Loop.loopLoop, direction: self.direction)
}
loopModeView.triggeredLtrOneShotButton = {
loopModeView.riveView.play(animationName:"pingpong", loop: Loop.loopOneShot, direction: self.direction)
try? loopModeView.riveView.play(animationName:"pingpong", loop: Loop.loopOneShot, direction: self.direction)
}
loopModeView.triggeredLtrPingPongButton = {
loopModeView.riveView.play(animationName:"pingpong", loop: Loop.loopPingPong, direction: self.direction)
try? loopModeView.riveView.play(animationName:"pingpong", loop: Loop.loopPingPong, direction: self.direction)
}
}

Expand Down
Loading