diff --git a/Example-iOS/Source/SwiftUI/Button/RiveButtonBridge.swift b/Example-iOS/Source/SwiftUI/Button/RiveButtonBridge.swift index 2528adb3..3b0c9318 100644 --- a/Example-iOS/Source/SwiftUI/Button/RiveButtonBridge.swift +++ b/Example-iOS/Source/SwiftUI/Button/RiveButtonBridge.swift @@ -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) { - play ? riveView.play() : riveView.pause() + play ? try? riveView.play() : riveView.pause() } - + static func dismantleUIView(_ riveView: RiveView, coordinator: Self.Coordinator) { riveView.stop() } diff --git a/Example-iOS/Source/SwiftUI/Explorer/RiveExplorer.swift b/Example-iOS/Source/SwiftUI/Explorer/RiveExplorer.swift index e4b29a7a..34dec83b 100644 --- a/Example-iOS/Source/SwiftUI/Explorer/RiveExplorer.swift +++ b/Example-iOS/Source/SwiftUI/Explorer/RiveExplorer.swift @@ -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: { diff --git a/Example-iOS/Source/SwiftUI/Explorer/RiveExplorerBridge.swift b/Example-iOS/Source/SwiftUI/Explorer/RiveExplorerBridge.swift index 507979fd..335dfba7 100644 --- a/Example-iOS/Source/SwiftUI/Explorer/RiveExplorerBridge.swift +++ b/Example-iOS/Source/SwiftUI/Explorer/RiveExplorerBridge.swift @@ -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 } @@ -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) { // Set the properties @@ -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 } } @@ -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() } @@ -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) diff --git a/Example-iOS/Source/SwiftUI/ProgressBar/RiveProgressBarBridge.swift b/Example-iOS/Source/SwiftUI/ProgressBar/RiveProgressBarBridge.swift index b2bf1de5..77306aba 100644 --- a/Example-iOS/Source/SwiftUI/ProgressBar/RiveProgressBarBridge.swift +++ b/Example-iOS/Source/SwiftUI/ProgressBar/RiveProgressBarBridge.swift @@ -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) { - 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) } } diff --git a/Example-iOS/Source/SwiftUI/Switch/RiveSwitchBridge.swift b/Example-iOS/Source/SwiftUI/Switch/RiveSwitchBridge.swift index 27a5adc6..b3644e2a 100644 --- a/Example-iOS/Source/SwiftUI/Switch/RiveSwitchBridge.swift +++ b/Example-iOS/Source/SwiftUI/Switch/RiveSwitchBridge.swift @@ -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) { riveView.stop() if switchToOn { - riveView.play(animationName: onAnimation) + try? riveView.play(animationName: onAnimation) } if switchToOff { - riveView.play(animationName: offAnimation) + try? riveView.play(animationName: offAnimation) } } diff --git a/Example-iOS/Source/UIkit/BlendModes.swift b/Example-iOS/Source/UIkit/BlendModes.swift index bc5488ad..c11d1f55 100644 --- a/Example-iOS/Source/UIkit/BlendModes.swift +++ b/Example-iOS/Source/UIkit/BlendModes.swift @@ -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) { diff --git a/Example-iOS/Source/UIkit/Layout.swift b/Example-iOS/Source/UIkit/Layout.swift index 3f0a101b..a152f7dd 100644 --- a/Example-iOS/Source/UIkit/Layout.swift +++ b/Example-iOS/Source/UIkit/Layout.swift @@ -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 diff --git a/Example-iOS/Source/UIkit/LoopMode.swift b/Example-iOS/Source/UIkit/LoopMode.swift index f6953f70..9c88b415 100644 --- a/Example-iOS/Source/UIkit/LoopMode.swift +++ b/Example-iOS/Source/UIkit/LoopMode.swift @@ -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 ) @@ -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) } } diff --git a/Example-iOS/Source/UIkit/MultipleAnimations.swift b/Example-iOS/Source/UIkit/MultipleAnimations.swift index e54284c7..0038997d 100644 --- a/Example-iOS/Source/UIkit/MultipleAnimations.swift +++ b/Example-iOS/Source/UIkit/MultipleAnimations.swift @@ -20,28 +20,27 @@ class MultipleAnimationsController: UIViewController { let loopResourceName = "artboard_animations" - override public func loadView() { + override public func loadView() { super.loadView() guard let multipleAnimationView = view as? MultipleAnimations else { fatalError("Could not find LayoutView") } - - multipleAnimationView.squareGoAround.configure( + try? multipleAnimationView.squareGoAround.configure( getRiveFile(resourceName: loopResourceName), andArtboard: "Square", andAnimation: "goaround" ) - multipleAnimationView.squareRollAround.configure( + try? multipleAnimationView.squareRollAround.configure( getRiveFile(resourceName: loopResourceName), andArtboard: "Square", andAnimation: "rollaround" ) - multipleAnimationView.circle.configure( + try? multipleAnimationView.circle.configure( getRiveFile(resourceName: loopResourceName), andArtboard: "Circle" ) - multipleAnimationView.star?.configure( + try? multipleAnimationView.star?.configure( getRiveFile(resourceName: loopResourceName), andArtboard: "Star" ) diff --git a/Example-iOS/Source/UIkit/SimpleAnimation.swift b/Example-iOS/Source/UIkit/SimpleAnimation.swift index 45d79cc9..3f760a0e 100644 --- a/Example-iOS/Source/UIkit/SimpleAnimation.swift +++ b/Example-iOS/Source/UIkit/SimpleAnimation.swift @@ -9,41 +9,42 @@ import UIKit import RiveRuntime +//class SimpleAnimationViewController: UIViewController { +// let resourceName = "truck_v7" +// +// override public func loadView() { +// super.loadView() +// +// let view = RiveView() +// view.fit = Fit.fitCover +// do{ +// let riveFile = try RiveFile(resource: resourceName) +// try view.configure(riveFile) +// } catch { +// print(error) +// } +// +// self.view = view +// } +// +// override public func viewDidDisappear(_ animated: Bool) { +// super.viewDidDisappear(animated) +// } +//} + + class SimpleAnimationViewController: UIViewController { - let resourceName = "truck_v7" - + let url = "https://cdn.rive.app/animations/truck.riv" + override public func loadView() { super.loadView() - + let view = RiveView() - view.fit = Fit.fitCover - guard let riveFile = RiveFile(resource: resourceName) else { - fatalError("Failed to load RiveFile") + guard let riveFile = RiveFile(httpUrl: url, with: view) else { + fatalError("Unable to load RiveFile") } + try? view.configure(riveFile) - view.configure(riveFile) self.view = view } - - override public func viewDidDisappear(_ animated: Bool) { - super.viewDidDisappear(animated) - } } - -/* -class SimpleAnimationViewController: UIViewController { - let url = "https://cdn.rive.app/animations/truck.riv" - - override public func loadView() { - super.loadView() - - let view = RiveView() - guard let riveFile = RiveFile(httpUrl: url, with: view) else { - fatalError("Unable to load RiveFile") - } - - view.configure(riveFile) - self.view = view - } - } - */ diff --git a/Example-iOS/Source/UIkit/StateMachine.swift b/Example-iOS/Source/UIkit/StateMachine.swift index 4547b1ef..09b7da0c 100644 --- a/Example-iOS/Source/UIkit/StateMachine.swift +++ b/Example-iOS/Source/UIkit/StateMachine.swift @@ -44,33 +44,34 @@ class StateMachineViewController: UIViewController { fatalError("Could not find StateMachineView") } - stateMachineView.riveView.configure( + try? stateMachineView.riveView.configure( getRiveFile(resourceName: resourceName), andStateMachine: "Designer's Test" ) + stateMachineView.beginnerButtonAction = { - stateMachineView.riveView.setNumberState( + try? stateMachineView.riveView.setNumberState( "Designer's Test", inputName: "Level", value: 0.0 ) } stateMachineView.intermediateButtonAction = { - stateMachineView.riveView.setNumberState( + try? stateMachineView.riveView.setNumberState( "Designer's Test", inputName: "Level", value: 1.0 ) } stateMachineView.expertButtonAction = { - stateMachineView.riveView.setNumberState( + try? stateMachineView.riveView.setNumberState( "Designer's Test", inputName: "Level", value: 2.0 ) } stateMachineView.resetButtonAction = { - stateMachineView.riveView.reset() + try? stateMachineView.riveView.reset() } } diff --git a/Example-iOS/Source/UIkit/iosPlayer.swift b/Example-iOS/Source/UIkit/iosPlayer.swift index 23d8ec0c..cf3b6e27 100644 --- a/Example-iOS/Source/UIkit/iosPlayer.swift +++ b/Example-iOS/Source/UIkit/iosPlayer.swift @@ -20,19 +20,19 @@ class FileChoiceDelegate: NSObject, UIPickerViewDataSource, UIPickerViewDelegate var chosen = "skills" weak var viewController:IOSPlayerViewController? //MARK: - Pickerview method - func numberOfComponents(in pickerView: UIPickerView) -> Int { - return 1 - } - func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { - return choices.count - } - func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { - return choices[row] - } - func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { + func numberOfComponents(in pickerView: UIPickerView) -> Int { + return 1 + } + func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { + return choices.count + } + func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { + return choices[row] + } + func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { self.chosen = choices[row] - viewController?.load(name:choices[row]) - } + try? viewController?.load(name:choices[row]) + } } class ArtboardChoicesDelegate: NSObject, UIPickerViewDataSource, UIPickerViewDelegate { @@ -40,19 +40,19 @@ class ArtboardChoicesDelegate: NSObject, UIPickerViewDataSource, UIPickerViewDel var chosen:String? weak var viewController:IOSPlayerViewController? - func numberOfComponents(in pickerView: UIPickerView) -> Int { + func numberOfComponents(in pickerView: UIPickerView) -> Int { return 1 - } - func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { - return choices.count - } - func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { - return choices[row] - } - func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { + } + func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { + return choices.count + } + func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { + return choices[row] + } + func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { self.chosen = choices[row] - viewController?.loadArtboard(name:choices[row]) - } + try? viewController?.loadArtboard(name:choices[row]) + } } class IOSPlayerViewController: UIViewController { @@ -66,22 +66,22 @@ class IOSPlayerViewController: UIViewController { @IBOutlet var FileChoicePicker: UIPickerView! @IBOutlet var ArtboardPicker: UIPickerView! - func load(name:String){ - riveFile = getRiveFile(resourceName: name) - playerView?.riveView.configure( + func load(name:String) throws { + riveFile = try getRiveFile(resourceName: name) + try playerView?.riveView.configure( riveFile! ) artboardChoices.choices = riveFile!.artboardNames() ArtboardPicker.reloadComponent(0) - loadAnimations() + try loadAnimations() } - func loadArtboard(name:String){ - playerView?.riveView.configure( + func loadArtboard(name:String) throws { + try playerView?.riveView.configure( riveFile!, andArtboard: name ) artboardName=name - loadAnimations() + try loadAnimations() } func _clearOld(){ @@ -93,11 +93,11 @@ class IOSPlayerViewController: UIViewController { } } - func _loadAnimations(){ + func _loadAnimations() throws { if #available(iOS 14.0, *) { - let artboard = _getArtbaord() + let artboard = try _getArtbaord() let animationNames = artboard.animationNames() if (animationNames.count > 0){ @@ -119,7 +119,7 @@ class IOSPlayerViewController: UIViewController { type: .system, primaryAction: UIAction(title: ">", handler: { [unowned self] _ in - self.playerView?.riveView?.play(animationName: name) + try? self.playerView?.riveView?.play(animationName: name) })) let pause = UIButton( type: .system, @@ -142,7 +142,7 @@ class IOSPlayerViewController: UIViewController { play.widthAnchor.constraint(equalToConstant: 40).isActive = true pause.widthAnchor.constraint(equalToConstant: 40).isActive = true stop.widthAnchor.constraint(equalToConstant: 40).isActive = true - + let stackView = UIStackView() stackView.translatesAutoresizingMaskIntoConstraints = false @@ -160,19 +160,19 @@ class IOSPlayerViewController: UIViewController { } } - func _getArtbaord()->RiveArtboard{ + func _getArtbaord() throws ->RiveArtboard{ if let name=artboardName{ - return riveFile!.artboard(fromName:name) + return try riveFile!.artboard(fromName:name) } else { - return riveFile!.artboard() + return try riveFile!.artboard() } } - func _loadStateMachines(){ - + func _loadStateMachines() throws { + if #available(iOS 14.0, *) { - let artboard = _getArtbaord() + let artboard = try _getArtbaord() let stateMachineNames = artboard.stateMachineNames() if(stateMachineNames.count > 0){ @@ -183,7 +183,7 @@ class IOSPlayerViewController: UIViewController { PlayerStack.addArrangedSubview(label) } - stateMachineNames.forEach({name in + try stateMachineNames.forEach({name in let label = UILabel() label.text = name @@ -194,7 +194,7 @@ class IOSPlayerViewController: UIViewController { type: .system, primaryAction: UIAction(title: ">", handler: { [unowned self] _ in - self.playerView?.riveView?.play(animationName: name, isStateMachine: true) + try? self.playerView?.riveView?.play(animationName: name, isStateMachine: true) })) let pause = UIButton( type: .system, @@ -217,7 +217,7 @@ class IOSPlayerViewController: UIViewController { play.widthAnchor.constraint(equalToConstant: 40).isActive = true pause.widthAnchor.constraint(equalToConstant: 40).isActive = true stop.widthAnchor.constraint(equalToConstant: 40).isActive = true - + let stackView = UIStackView() stackView.translatesAutoresizingMaskIntoConstraints = false @@ -232,8 +232,8 @@ class IOSPlayerViewController: UIViewController { PlayerStack.addArrangedSubview(stackView) // time to add buttons for all the states :P - let stateMachine = artboard.stateMachine(fromName: name) - stateMachine.inputNames().forEach{inputName in + let stateMachine = try artboard.stateMachine(fromName: name) + try stateMachine.inputNames().forEach{inputName in let label = UILabel() label.text = inputName label.textColor = .black @@ -244,17 +244,17 @@ class IOSPlayerViewController: UIViewController { stackView.alignment = .trailing stackView.addArrangedSubview(label) - let input = stateMachine.input(fromName: inputName) + let input = try stateMachine.input(fromName: inputName) if (input.isBoolean()){ let switchToggle = UISwitch( frame: CGRect(), primaryAction: UIAction( handler: { [unowned self] this in if ((this.sender as! UISwitch).isOn){ - self.playerView?.riveView.setBooleanState(name, inputName: inputName, value: true) + try? self.playerView?.riveView.setBooleanState(name, inputName: inputName, value: true) } else { - self.playerView?.riveView.setBooleanState(name, inputName: inputName, value: false) + try? self.playerView?.riveView.setBooleanState(name, inputName: inputName, value: false) } } ) @@ -266,12 +266,12 @@ class IOSPlayerViewController: UIViewController { type: .system, primaryAction: UIAction(title: "fire", handler: { [unowned self] _ in - self.playerView?.riveView.fireState(name, inputName: inputName) + try? self.playerView?.riveView.fireState(name, inputName: inputName) })) stackView.addArrangedSubview(fireButton) } else if (input.isNumber()){ - + let valueLabel = UILabel() valueLabel.text = NSString(format: "%.2f", (input as! RiveStateMachineNumberInput).value()) as String valueLabel.textColor = .black @@ -284,7 +284,7 @@ class IOSPlayerViewController: UIViewController { let currentFloat = currentValue.floatValue - 1 valueLabel.text = NSString(format: "%.2f", currentFloat) as String - self.playerView?.riveView.setNumberState(name, inputName: inputName, value: currentFloat) + try? self.playerView?.riveView.setNumberState(name, inputName: inputName, value: currentFloat) })) let upButton = UIButton( type: .system, @@ -294,26 +294,23 @@ class IOSPlayerViewController: UIViewController { let currentFloat = currentValue.floatValue + 1 valueLabel.text = NSString(format: "%.2f", currentFloat) as String - self.playerView?.riveView.setNumberState(name, inputName: inputName, value: currentFloat) + try? self.playerView?.riveView.setNumberState(name, inputName: inputName, value: currentFloat) })) stackView.addArrangedSubview(downButton) stackView.addArrangedSubview(valueLabel) stackView.addArrangedSubview(upButton) } - - - - - PlayerStack.addArrangedSubview(stackView) } - }) + PlayerStack.addArrangedSubview(stackView) + } + ) } } - func loadAnimations(){ + func loadAnimations() throws { _clearOld() - _loadStateMachines() - _loadAnimations() + try _loadStateMachines() + try _loadAnimations() PlayerStack.reloadInputViews() } @@ -328,7 +325,7 @@ class IOSPlayerViewController: UIViewController { artboardChoices.viewController = self playerView = view as? IOSPlayerView - load(name:fileChoices.chosen) + try? load(name:fileChoices.chosen) } diff --git a/Example-iOS/Source/lib/utility.swift b/Example-iOS/Source/lib/utility.swift index 489e1c05..4f75384a 100644 --- a/Example-iOS/Source/lib/utility.swift +++ b/Example-iOS/Source/lib/utility.swift @@ -21,10 +21,8 @@ func getBytes(resourceName: String, resourceExt: String=".riv") -> [UInt8] { return [UInt8](data) } -func getRiveFile(resourceName: String, resourceExt: String=".riv") -> RiveFile{ + +func getRiveFile(resourceName: String, resourceExt: String=".riv") throws -> RiveFile{ let byteArray = getBytes(resourceName: resourceName, resourceExt: resourceExt) - guard let riveFile = RiveFile(byteArray: byteArray) else { - fatalError("Failed to import Rive File.") - } - return riveFile + return try RiveFile(byteArray: byteArray) } diff --git a/RiveRuntime.xcodeproj/project.pbxproj b/RiveRuntime.xcodeproj/project.pbxproj index 4b9a8807..3cb24a09 100644 --- a/RiveRuntime.xcodeproj/project.pbxproj +++ b/RiveRuntime.xcodeproj/project.pbxproj @@ -2401,6 +2401,7 @@ C9C73EE624FC478900EF9516 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + BITCODE_GENERATION_MODE = bitcode; BUILD_LIBRARY_FOR_DISTRIBUTION = YES; CLANG_CXX_LANGUAGE_STANDARD = "c++17"; CLANG_ENABLE_MODULES = YES; @@ -2420,6 +2421,7 @@ "@loader_path/Frameworks", ); MARKETING_VERSION = 0.6.5; + OTHER_CFLAGS = "-fembed-bitcode"; PRODUCT_BUNDLE_IDENTIFIER = rive.app.ios.runtime.RiveRuntime; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; @@ -2432,6 +2434,7 @@ C9C73EE724FC478900EF9516 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + BITCODE_GENERATION_MODE = bitcode; BUILD_LIBRARY_FOR_DISTRIBUTION = YES; CLANG_CXX_LANGUAGE_STANDARD = "c++17"; CLANG_ENABLE_MODULES = YES; @@ -2452,6 +2455,10 @@ ); MARKETING_VERSION = 0.6.5; MTL_ENABLE_DEBUG_INFO = NO; + OTHER_CFLAGS = ( + "-DNS_BLOCK_ASSERTIONS=1", + "-fembed-bitcode", + ); PRODUCT_BUNDLE_IDENTIFIER = rive.app.ios.runtime.RiveRuntime; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SKIP_INSTALL = YES; diff --git a/Source/Renderer/RiveFile.mm b/Source/Renderer/RiveFile.mm index b171a0a3..c2faed21 100644 --- a/Source/Renderer/RiveFile.mm +++ b/Source/Renderer/RiveFile.mm @@ -12,7 +12,6 @@ @interface RiveFile () - (rive::BinaryReader) getReader:(UInt8 *)bytes byteLength:(UInt64)length; -- (void) import:(rive::BinaryReader)reader; @end @@ -100,6 +99,7 @@ - (nullable instancetype)initWithHttpUrl:(NSString *)url withDelegate:(id