diff --git a/.rive_head b/.rive_head index 8b6016b7..0b213a5e 100644 --- a/.rive_head +++ b/.rive_head @@ -1 +1 @@ -bd71143bc0964a789174f30f01d14fa551e33bb9 +fbb092d8c71e2854102a30cdec6e0a57ad10a3ba diff --git a/.rive_renderer b/.rive_renderer index 12eef9ff..7c166b57 100644 --- a/.rive_renderer +++ b/.rive_renderer @@ -1 +1 @@ -7e2d06a1e206eac1c65dcc88e153e6fe1e8067c9 +9859a2759e36e12f10e95324c11602ef5e7fa6a7 diff --git a/Example-iOS/Assets/switch.riv b/Example-iOS/Assets/switch.riv deleted file mode 100644 index a419b6c9..00000000 Binary files a/Example-iOS/Assets/switch.riv and /dev/null differ diff --git a/Example-iOS/RiveExample.xcodeproj/project.pbxproj b/Example-iOS/RiveExample.xcodeproj/project.pbxproj index c3e60083..825c871c 100644 --- a/Example-iOS/RiveExample.xcodeproj/project.pbxproj +++ b/Example-iOS/RiveExample.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 54; + objectVersion = 52; objects = { /* Begin PBXBuildFile section */ @@ -94,7 +94,6 @@ 04E51C662A151C230075E473 /* pull.riv in Resources */ = {isa = PBXBuildFile; fileRef = 042C88CA2644447400E7DBB2 /* pull.riv */; }; 04E51C672A151C230075E473 /* rope.riv in Resources */ = {isa = PBXBuildFile; fileRef = 042C88CC2644447400E7DBB2 /* rope.riv */; }; 04E51C682A151C230075E473 /* skills.riv in Resources */ = {isa = PBXBuildFile; fileRef = 042C88D82644447500E7DBB2 /* skills.riv */; }; - 04E51C692A151C230075E473 /* switch.riv in Resources */ = {isa = PBXBuildFile; fileRef = C9E040A8264DFCFD009ABC7C /* switch.riv */; }; 04E51C6A2A151C230075E473 /* trailblaze.riv in Resources */ = {isa = PBXBuildFile; fileRef = 042C88D52644447500E7DBB2 /* trailblaze.riv */; }; 04E51C6B2A151C230075E473 /* ui_swipe_left_to_delete.riv in Resources */ = {isa = PBXBuildFile; fileRef = 042C88CB2644447400E7DBB2 /* ui_swipe_left_to_delete.riv */; }; 04E51C6C2A151C230075E473 /* vader.riv in Resources */ = {isa = PBXBuildFile; fileRef = 042C88DA2644447500E7DBB2 /* vader.riv */; }; @@ -108,7 +107,6 @@ 83C89ACF2988709400044C17 /* marty.riv in Resources */ = {isa = PBXBuildFile; fileRef = 83C89ACE2988709400044C17 /* marty.riv */; }; 83C89AD1298870A700044C17 /* paper.riv in Resources */ = {isa = PBXBuildFile; fileRef = 83C89AD0298870A700044C17 /* paper.riv */; }; 83DE4CB52AB397A800B88B72 /* Bear.riv in Resources */ = {isa = PBXBuildFile; fileRef = 83DE4CB42AB3974300B88B72 /* Bear.riv */; }; - C324DB5628071EB80060589F /* RiveSwitch.swift in Sources */ = {isa = PBXBuildFile; fileRef = C324DB5528071EB80060589F /* RiveSwitch.swift */; }; C324DB5B2807216B0060589F /* RiveSlider.swift in Sources */ = {isa = PBXBuildFile; fileRef = C324DB5A2807216B0060589F /* RiveSlider.swift */; }; C324DB5D280728690060589F /* RiveButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = C324DB5C280728690060589F /* RiveButton.swift */; }; C324DB5F280740FB0060589F /* rbutton.riv in Resources */ = {isa = PBXBuildFile; fileRef = C324DB5E280740FB0060589F /* rbutton.riv */; }; @@ -117,7 +115,6 @@ C3745FCE282AE2320087F4AF /* hero_editor.riv in Resources */ = {isa = PBXBuildFile; fileRef = C3745FCB282AE2320087F4AF /* hero_editor.riv */; }; C3C074AB283FC75900E8EB33 /* testanimation.riv in Resources */ = {isa = PBXBuildFile; fileRef = C3C074A7283FC75800E8EB33 /* testanimation.riv */; }; C3C074AC283FC75900E8EB33 /* teststatemachine.riv in Resources */ = {isa = PBXBuildFile; fileRef = C3C074AA283FC75900E8EB33 /* teststatemachine.riv */; }; - C3C074EE28414F4600E8EB33 /* SwiftTestParityAnimSM.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C074ED28414F4600E8EB33 /* SwiftTestParityAnimSM.swift */; }; C3C074F2284161E400E8EB33 /* halloween.riv in Resources */ = {isa = PBXBuildFile; fileRef = C3C074F1284161E400E8EB33 /* halloween.riv */; }; C3D187F3280751A8008B739A /* RiveProgressBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3D187F2280751A8008B739A /* RiveProgressBar.swift */; }; C3D187F728075B6C008B739A /* riveslider.riv in Resources */ = {isa = PBXBuildFile; fileRef = C3D187F628075B6C008B739A /* riveslider.riv */; }; @@ -140,7 +137,6 @@ C9CE8266263B90E000F98DDB /* juice_v7.riv in Resources */ = {isa = PBXBuildFile; fileRef = C9CE8265263B90E000F98DDB /* juice_v7.riv */; }; C9D3DE5B264F3B51001BA265 /* liquid.riv in Resources */ = {isa = PBXBuildFile; fileRef = C9D3DE5A264F3B51001BA265 /* liquid.riv */; }; C9D3DE68264F49F4001BA265 /* life_bar.riv in Resources */ = {isa = PBXBuildFile; fileRef = C9D3DE67264F49F4001BA265 /* life_bar.riv */; }; - C9E040A9264DFCFD009ABC7C /* switch.riv in Resources */ = {isa = PBXBuildFile; fileRef = C9E040A8264DFCFD009ABC7C /* switch.riv */; }; E57798A02A72C77900FF25C3 /* testtext.riv in Resources */ = {isa = PBXBuildFile; fileRef = E577989D2A72C77900FF25C3 /* testtext.riv */; }; E57798A92A730A9B00FF25C3 /* SwiftTestText.swift in Sources */ = {isa = PBXBuildFile; fileRef = E57798A82A730A9B00FF25C3 /* SwiftTestText.swift */; }; E57798AC2A731C5800FF25C3 /* testtext.riv in Resources */ = {isa = PBXBuildFile; fileRef = E577989D2A72C77900FF25C3 /* testtext.riv */; }; @@ -259,7 +255,6 @@ 83C89ACE2988709400044C17 /* marty.riv */ = {isa = PBXFileReference; lastKnownFileType = file; path = marty.riv; sourceTree = ""; }; 83C89AD0298870A700044C17 /* paper.riv */ = {isa = PBXFileReference; lastKnownFileType = file; path = paper.riv; sourceTree = ""; }; 83DE4CB42AB3974300B88B72 /* Bear.riv */ = {isa = PBXFileReference; lastKnownFileType = file; path = Bear.riv; sourceTree = ""; }; - C324DB5528071EB80060589F /* RiveSwitch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RiveSwitch.swift; sourceTree = ""; }; C324DB5A2807216B0060589F /* RiveSlider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RiveSlider.swift; sourceTree = ""; }; C324DB5C280728690060589F /* RiveButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RiveButton.swift; sourceTree = ""; }; C324DB5E280740FB0060589F /* rbutton.riv */ = {isa = PBXFileReference; lastKnownFileType = file; path = rbutton.riv; sourceTree = ""; }; @@ -268,7 +263,6 @@ C3745FCB282AE2320087F4AF /* hero_editor.riv */ = {isa = PBXFileReference; lastKnownFileType = file; path = hero_editor.riv; sourceTree = ""; }; C3C074A7283FC75800E8EB33 /* testanimation.riv */ = {isa = PBXFileReference; lastKnownFileType = file; path = testanimation.riv; sourceTree = ""; }; C3C074AA283FC75900E8EB33 /* teststatemachine.riv */ = {isa = PBXFileReference; lastKnownFileType = file; path = teststatemachine.riv; sourceTree = ""; }; - C3C074ED28414F4600E8EB33 /* SwiftTestParityAnimSM.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftTestParityAnimSM.swift; sourceTree = ""; }; C3C074F1284161E400E8EB33 /* halloween.riv */ = {isa = PBXFileReference; lastKnownFileType = file; path = halloween.riv; sourceTree = ""; }; C3D187F2280751A8008B739A /* RiveProgressBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RiveProgressBar.swift; sourceTree = ""; }; C3D187F628075B6C008B739A /* riveslider.riv */ = {isa = PBXFileReference; lastKnownFileType = file; path = riveslider.riv; sourceTree = ""; }; @@ -293,7 +287,6 @@ C9CE8265263B90E000F98DDB /* juice_v7.riv */ = {isa = PBXFileReference; lastKnownFileType = file; path = juice_v7.riv; sourceTree = ""; }; C9D3DE5A264F3B51001BA265 /* liquid.riv */ = {isa = PBXFileReference; lastKnownFileType = file; path = liquid.riv; sourceTree = ""; }; C9D3DE67264F49F4001BA265 /* life_bar.riv */ = {isa = PBXFileReference; lastKnownFileType = file; path = life_bar.riv; sourceTree = ""; }; - C9E040A8264DFCFD009ABC7C /* switch.riv */ = {isa = PBXFileReference; lastKnownFileType = file; path = switch.riv; sourceTree = ""; }; E577989D2A72C77900FF25C3 /* testtext.riv */ = {isa = PBXFileReference; lastKnownFileType = file; path = testtext.riv; sourceTree = ""; }; E57798A82A730A9B00FF25C3 /* SwiftTestText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftTestText.swift; sourceTree = ""; }; E57798AD2A73264100FF25C3 /* text_test_2.riv */ = {isa = PBXFileReference; lastKnownFileType = file; path = text_test_2.riv; sourceTree = ""; }; @@ -395,7 +388,6 @@ isa = PBXGroup; children = ( C324DB5C280728690060589F /* RiveButton.swift */, - C324DB5528071EB80060589F /* RiveSwitch.swift */, C324DB5A2807216B0060589F /* RiveSlider.swift */, C3D187F2280751A8008B739A /* RiveProgressBar.swift */, C3ECAC2E281840A300A81123 /* ClockViewModel.swift */, @@ -452,7 +444,6 @@ 042C88CA2644447400E7DBB2 /* pull.riv */, 042C88CC2644447400E7DBB2 /* rope.riv */, 042C88D82644447500E7DBB2 /* skills.riv */, - C9E040A8264DFCFD009ABC7C /* switch.riv */, 042C88D52644447500E7DBB2 /* trailblaze.riv */, 042C88CB2644447400E7DBB2 /* ui_swipe_left_to_delete.riv */, 042C88DA2644447500E7DBB2 /* vader.riv */, @@ -476,7 +467,6 @@ E5CD7D7027DC331900BFE5E2 /* SwiftMeshAnimation.swift */, C3ECAC262817BE4600A81123 /* SwiftTouchEvents.swift */, C3E2B58B2833ECFE00A8651B /* SwiftCannonGame.swift */, - C3C074ED28414F4600E8EB33 /* SwiftTestParityAnimSM.swift */, E57798A82A730A9B00FF25C3 /* SwiftTestText.swift */, E5964AAA2A9CD49200140479 /* SwiftEvents.swift */, 041265212B0BC5A5009400EC /* SwiftSimpleAssets.swift */, @@ -686,7 +676,6 @@ E57798AF2A73264100FF25C3 /* text_test_2.riv in Resources */, 04E51C672A151C230075E473 /* rope.riv in Resources */, 04E51C682A151C230075E473 /* skills.riv in Resources */, - 04E51C692A151C230075E473 /* switch.riv in Resources */, 04E51C6A2A151C230075E473 /* trailblaze.riv in Resources */, 0453FCB52B012D17001185C8 /* picture-47982.jpeg in Resources */, 04E51C6B2A151C230075E473 /* ui_swipe_left_to_delete.riv in Resources */, @@ -725,7 +714,6 @@ 042C88E92644447500E7DBB2 /* off_road_car_blog.riv in Resources */, 042C88832643D6B900E7DBB2 /* Main.storyboard in Resources */, 042C88EA2644447500E7DBB2 /* skills.riv in Resources */, - C9E040A9264DFCFD009ABC7C /* switch.riv in Resources */, 042C88E62644447500E7DBB2 /* artboard_animations.riv in Resources */, 042C88E72644447500E7DBB2 /* trailblaze.riv in Resources */, C3D187F728075B6C008B739A /* riveslider.riv in Resources */, @@ -797,11 +785,9 @@ 042C88902644250D00E7DBB2 /* MultipleAnimations.swift in Sources */, C3468E6227FDCBC6008652FD /* SimpleSlider.swift in Sources */, 041265222B0BC5A5009400EC /* SwiftSimpleAssets.swift in Sources */, - C3C074EE28414F4600E8EB33 /* SwiftTestParityAnimSM.swift in Sources */, 83C89ACB29886ECB00044C17 /* StressTest.swift in Sources */, E5E87A012AE5A83800E7295F /* SwiftVariableFPS.swift in Sources */, C3357CA1280F42EC00F03B6F /* ExamplesMaster.swift in Sources */, - C324DB5628071EB80060589F /* RiveSwitch.swift in Sources */, C3ECAC272817BE4600A81123 /* SwiftTouchEvents.swift in Sources */, C3ECAC2F281840A300A81123 /* ClockViewModel.swift in Sources */, 04026DC827CE3EE6002B3DBF /* SwiftLayout.swift in Sources */, diff --git a/Example-iOS/Source/Examples/Storyboard/CachedAssets.swift b/Example-iOS/Source/Examples/Storyboard/CachedAssets.swift index 6654b71a..93240a7b 100644 --- a/Example-iOS/Source/Examples/Storyboard/CachedAssets.swift +++ b/Example-iOS/Source/Examples/Storyboard/CachedAssets.swift @@ -26,7 +26,6 @@ class AssetLoader{ var cachedImage: RiveImageAsset?; var factory: RiveFactory?; - // pretty naive way to clean up any outstanding requests. var tasks: [URLSessionDataTask] = []; func fillFontCache(){ @@ -193,7 +192,6 @@ class AssetLoader{ class OutOfBandAssetsController: UIViewController, UIGestureRecognizerDelegate { - // TODO: talk to people to see if we can make this nice... var loader: AssetLoader = AssetLoader(); var viewModel: RiveViewModel?; diff --git a/Example-iOS/Source/Examples/Storyboard/SimpleOutOfBand.swift b/Example-iOS/Source/Examples/Storyboard/SimpleOutOfBand.swift index 97e23396..77758af5 100644 --- a/Example-iOS/Source/Examples/Storyboard/SimpleOutOfBand.swift +++ b/Example-iOS/Source/Examples/Storyboard/SimpleOutOfBand.swift @@ -32,12 +32,9 @@ func loadAndSetRenderFont(named resourceName: String, asset: RiveFontAsset, fact } class SimpleOutOfBandController: UIViewController, UIGestureRecognizerDelegate { - // TODO: talk to people to see if we can make this nice... var loader: AssetLoader = AssetLoader(); var viewModel: RiveViewModel?; - - required init?(coder: NSCoder) { self.viewModel = RiveViewModel(fileName: "simple_assets", loadCdn: false, customLoader: { (asset: RiveFileAsset, data: Data, factory: RiveFactory) -> Bool in diff --git a/Example-iOS/Source/Examples/SwiftUI/SwiftCannonGame.swift b/Example-iOS/Source/Examples/SwiftUI/SwiftCannonGame.swift index 7a3539ee..cce3ae8f 100644 --- a/Example-iOS/Source/Examples/SwiftUI/SwiftCannonGame.swift +++ b/Example-iOS/Source/Examples/SwiftUI/SwiftCannonGame.swift @@ -12,12 +12,13 @@ import RiveRuntime struct SwiftCannonGame: DismissableView { var dismiss: () -> Void = {} + // MARK: RiveViewModel + // This view model controls a file configured with: + // - StateMachine + // - Listeners + @StateObject private var riveViewModel = RiveViewModel(fileName: "bullet_man_game") + var body: some View { - // MARK: RiveViewModel - // This view model controls a file configured with: - // - StateMachine - // - Listeners - - RiveViewModel(fileName: "bullet_man_game").view() + riveViewModel.view() } } diff --git a/Example-iOS/Source/Examples/SwiftUI/SwiftLayout.swift b/Example-iOS/Source/Examples/SwiftUI/SwiftLayout.swift index 8e7e9643..e32193cd 100644 --- a/Example-iOS/Source/Examples/SwiftUI/SwiftLayout.swift +++ b/Example-iOS/Source/Examples/SwiftUI/SwiftLayout.swift @@ -9,15 +9,24 @@ import SwiftUI import RiveRuntime + + struct SwiftLayout: DismissableView { var dismiss: () -> Void = {} @State private var fit: RiveFit = .contain @State private var alignment: RiveAlignment = .center + @StateObject private var riveViewModel = RiveViewModel(fileName: "truck_v7", fit: .contain, alignment: .center) var body: some View { VStack { - RiveViewModel(fileName: "truck_v7", fit: fit, alignment: alignment).view() + riveViewModel.view() + .onChange(of: fit) { value in + riveViewModel.fit = value + } + .onChange(of: alignment) { value in + riveViewModel.alignment = value + } } HStack { Text("Fit") diff --git a/Example-iOS/Source/Examples/SwiftUI/SwiftMeshAnimation.swift b/Example-iOS/Source/Examples/SwiftUI/SwiftMeshAnimation.swift index 0de4f987..7fe6f673 100644 --- a/Example-iOS/Source/Examples/SwiftUI/SwiftMeshAnimation.swift +++ b/Example-iOS/Source/Examples/SwiftUI/SwiftMeshAnimation.swift @@ -14,13 +14,10 @@ struct SwiftMeshAnimation: DismissableView { // MARK: RiveViewModel // This view model specifies the exact StateMachine that it wants from the file - - // TODO: - // Review viewmodel set-up here to avoid recreation & also loading files on launch. @State var isTapped: Bool = false + @StateObject private var tapePlayer = RiveViewModel(fileName: "prop_example", stateMachineName: "State Machine 1") var body: some View { - let tapePlayer = RiveViewModel(fileName: "prop_example", stateMachineName: "State Machine 1") tapePlayer.view() .aspectRatio(1, contentMode: .fit) .onTapGesture { diff --git a/Example-iOS/Source/Examples/SwiftUI/SwiftMultipleAnimations.swift b/Example-iOS/Source/Examples/SwiftUI/SwiftMultipleAnimations.swift index 503b6f54..7e7b0c86 100644 --- a/Example-iOS/Source/Examples/SwiftUI/SwiftMultipleAnimations.swift +++ b/Example-iOS/Source/Examples/SwiftUI/SwiftMultipleAnimations.swift @@ -13,9 +13,9 @@ import RiveRuntime /// different animations within those artboards struct SwiftMultipleAnimations: DismissableView { var dismiss: () -> Void = {} + let file = try! RiveFile(name: "artboard_animations") var body: some View { - let file = try! RiveFile(name: "artboard_animations") ScrollView{ VStack { Text("Square - go around") diff --git a/Example-iOS/Source/Examples/SwiftUI/SwiftSimpleAnimation.swift b/Example-iOS/Source/Examples/SwiftUI/SwiftSimpleAnimation.swift index 15dc8564..c115e720 100644 --- a/Example-iOS/Source/Examples/SwiftUI/SwiftSimpleAnimation.swift +++ b/Example-iOS/Source/Examples/SwiftUI/SwiftSimpleAnimation.swift @@ -13,11 +13,12 @@ import RiveRuntime struct SwiftSimpleAnimation: DismissableView { var dismiss: () -> Void = {} + @StateObject private var riveViewModel = RiveViewModel(fileName: "halloween", autoPlay: false) var body: some View { SwiftVMPlayer( viewModels: - RiveViewModel(fileName: "halloween", autoPlay: false) + riveViewModel ) } } diff --git a/Example-iOS/Source/Examples/SwiftUI/SwiftSimpleAssets.swift b/Example-iOS/Source/Examples/SwiftUI/SwiftSimpleAssets.swift index ce9c7f90..d424a162 100644 --- a/Example-iOS/Source/Examples/SwiftUI/SwiftSimpleAssets.swift +++ b/Example-iOS/Source/Examples/SwiftUI/SwiftSimpleAssets.swift @@ -11,38 +11,38 @@ import RiveRuntime struct SwiftSimpleAssets: DismissableView { var dismiss: () -> Void = {} - - var body: some View { - RiveViewModel(fileName: "simple_assets", autoPlay: false, loadCdn: false, customLoader: { (asset: RiveFileAsset, data: Data, factory: RiveFactory) -> Bool in + @StateObject private var riveViewModel = RiveViewModel(fileName: "simple_assets", autoPlay: false, loadCdn: false, customLoader: { (asset: RiveFileAsset, data: Data, factory: RiveFactory) -> Bool in + + if (asset is RiveImageAsset){ - // TODO: this looks kinda compolex, can this be simpler? - if (asset is RiveImageAsset){ - - guard let url = (.main as Bundle).url(forResource: "picture-47982", withExtension: "jpeg") else { - fatalError("Failed to locate 'picture-47982' in bundle.") - } - guard let data = try? Data(contentsOf: url) else { - fatalError("Failed to load \(url) from bundle.") - } - (asset as! RiveImageAsset).renderImage( - factory.decodeImage(data) - ) - return true; - }else if (asset is RiveFontAsset) { - guard let url = (.main as Bundle).url(forResource: "Inter-45562", withExtension: "ttf") else { - fatalError("Failed to locate 'Inter-45562' in bundle.") - } - guard let data = try? Data(contentsOf: url) else { - fatalError("Failed to load \(url) from bundle.") - } - - (asset as! RiveFontAsset).font( - factory.decodeFont(data) - ) - return true; + guard let url = (.main as Bundle).url(forResource: "picture-47982", withExtension: "jpeg") else { + fatalError("Failed to locate 'picture-47982' in bundle.") + } + guard let data = try? Data(contentsOf: url) else { + fatalError("Failed to load \(url) from bundle.") + } + (asset as! RiveImageAsset).renderImage( + factory.decodeImage(data) + ) + return true; + }else if (asset is RiveFontAsset) { + guard let url = (.main as Bundle).url(forResource: "Inter-45562", withExtension: "ttf") else { + fatalError("Failed to locate 'Inter-45562' in bundle.") + } + guard let data = try? Data(contentsOf: url) else { + fatalError("Failed to load \(url) from bundle.") } - return false; - }).view() + (asset as! RiveFontAsset).font( + factory.decodeFont(data) + ) + return true; + } + + return false; + }); + + var body: some View { + riveViewModel.view() } } diff --git a/Example-iOS/Source/Examples/SwiftUI/SwiftStateMachine.swift b/Example-iOS/Source/Examples/SwiftUI/SwiftStateMachine.swift index 84c2bc79..9573bba5 100644 --- a/Example-iOS/Source/Examples/SwiftUI/SwiftStateMachine.swift +++ b/Example-iOS/Source/Examples/SwiftUI/SwiftStateMachine.swift @@ -14,8 +14,9 @@ struct SwiftStateMachine: DismissableView { // MARK: RiveViewModel // This view model specifies the exact StateMachine that it wants from the file + @StateObject private var stateChanger = RiveViewModel(fileName: "skills", stateMachineName: "Designer's Test") + var body: some View { - let stateChanger = RiveViewModel(fileName: "skills", stateMachineName: "Designer's Test") ScrollView{ VStack { stateChanger.view() diff --git a/Example-iOS/Source/Examples/SwiftUI/SwiftTestParityAnimSM.swift b/Example-iOS/Source/Examples/SwiftUI/SwiftTestParityAnimSM.swift deleted file mode 100644 index 7e970a38..00000000 --- a/Example-iOS/Source/Examples/SwiftUI/SwiftTestParityAnimSM.swift +++ /dev/null @@ -1,23 +0,0 @@ -// -// SwiftTestParityAnimSM.swift -// RiveExample -// -// Created by Zachary Duncan on 5/27/22. -// Copyright © 2022 Rive. All rights reserved. -// - -import SwiftUI -import RiveRuntime - -/// Test to check the difference in behavior between an Animation and an almost idential StateMachine -struct SwiftTestParityAnimSM: DismissableView { - var dismiss: () -> Void = {} - - var body: some View { - SwiftVMPlayer( - viewModels: - RiveViewModel(fileName: "teststatemachine", stateMachineName: "State Machine 1", autoPlay: false), - RiveViewModel(fileName: "testanimation", animationName: "Move", autoPlay: false) - ) - } -} diff --git a/Example-iOS/Source/Examples/SwiftUI/SwiftTestText.swift b/Example-iOS/Source/Examples/SwiftUI/SwiftTestText.swift index 52459778..10f17cb1 100644 --- a/Example-iOS/Source/Examples/SwiftUI/SwiftTestText.swift +++ b/Example-iOS/Source/Examples/SwiftUI/SwiftTestText.swift @@ -13,7 +13,7 @@ struct TextInputView: DismissableView { var dismiss: () -> Void = {} @State private var userInput: String = "" - @State private var rvm = RiveViewModel(fileName: "text_test_2") + @StateObject private var rvm = RiveViewModel(fileName: "text_test_2") var body: some View { VStack(spacing: 20) { diff --git a/Example-iOS/Source/Examples/SwiftUI/SwiftTouchEvents.swift b/Example-iOS/Source/Examples/SwiftUI/SwiftTouchEvents.swift index e10a2058..431682ec 100644 --- a/Example-iOS/Source/Examples/SwiftUI/SwiftTouchEvents.swift +++ b/Example-iOS/Source/Examples/SwiftUI/SwiftTouchEvents.swift @@ -17,19 +17,15 @@ struct SwiftTouchEvents: DismissableView { // - State Machine // - Listeners - // TODO: - // Review viewmodel set-up here to avoid recreation & also loading files on launch. + @StateObject private var clock = ClockViewModel() + @StateObject private var jelly = RiveViewModel(fileName: "hero_editor") + @StateObject private var playButton = RiveViewModel(fileName: "play_button_event_example") + @StateObject private var lighthouse = RiveViewModel(fileName: "switch_event_example") + @StateObject private var eightball = RiveViewModel(fileName: "magic_8-ball_v2") + @StateObject private var bearGuy = RiveViewModel(fileName: "leg_day_events_example") + @StateObject private var toggle = RiveViewModel(fileName: "light_switch") - var body: some View { - - let clock = ClockViewModel() - let jelly = RiveViewModel(fileName: "hero_editor") - let playButton = RiveViewModel(fileName: "play_button_event_example") - let lighthouse = RiveViewModel(fileName: "switch_event_example") - let eightball = RiveViewModel(fileName: "magic_8-ball_v2") - let bearGuy = RiveViewModel(fileName: "leg_day_events_example") - let toggle = RiveViewModel(fileName: "light_switch") - + var body: some View { ScrollView { VStack { jelly.view() diff --git a/Example-iOS/Source/Examples/SwiftUI/SwiftVariableFPS.swift b/Example-iOS/Source/Examples/SwiftUI/SwiftVariableFPS.swift index 17ff699c..45f35568 100644 --- a/Example-iOS/Source/Examples/SwiftUI/SwiftVariableFPS.swift +++ b/Example-iOS/Source/Examples/SwiftUI/SwiftVariableFPS.swift @@ -12,7 +12,7 @@ import RiveRuntime struct SwiftVariableFPS: DismissableView { var dismiss: () -> Void = {} - private var stateChanger = RiveViewModel(fileName: "skills", stateMachineName: "Designer's Test") + @StateObject private var stateChanger = RiveViewModel(fileName: "skills", stateMachineName: "Designer's Test") var body: some View { ScrollView{ diff --git a/Example-iOS/Source/Examples/SwiftUI/SwiftWidgets.swift b/Example-iOS/Source/Examples/SwiftUI/SwiftWidgets.swift index 3c919790..4d2ac106 100644 --- a/Example-iOS/Source/Examples/SwiftUI/SwiftWidgets.swift +++ b/Example-iOS/Source/Examples/SwiftUI/SwiftWidgets.swift @@ -18,13 +18,11 @@ struct SwiftWidgets: DismissableView { /// Tracks the health value coming from the slide for the progress bar @State var health: Double = 0 + @StateObject private var rslider = RiveSlider() + @StateObject private var rprogress = RiveProgressBar(); + @StateObject private var rbutton = RiveButton(); var body: some View { - - let rslider = RiveSlider() - let rprogress = RiveProgressBar() - let rswitch = RiveSwitch() - ZStack { Color.gray .ignoresSafeArea() @@ -33,20 +31,12 @@ struct SwiftWidgets: DismissableView { VStack { HStack { Text("RiveButton:") - RiveButton().view { + rbutton.view { print("Button tapped") } } Spacer().padding() - HStack { - Text("RSwitch:") - rswitch.view { on in - print("The switch is " + (on ? "on" : "off")) - } - } - Spacer().padding() - VStack { Text("RiveProgressBar:") rprogress.view() diff --git a/Example-iOS/Source/Examples/ViewModel/RiveSwitch.swift b/Example-iOS/Source/Examples/ViewModel/RiveSwitch.swift deleted file mode 100644 index 6634896d..00000000 --- a/Example-iOS/Source/Examples/ViewModel/RiveSwitch.swift +++ /dev/null @@ -1,38 +0,0 @@ -// -// RiveSwitch.swift -// RiveExample -// -// Created by Zachary Duncan on 4/13/22. -// Copyright © 2022 Rive. All rights reserved. -// - -import SwiftUI -import RiveRuntime - -class RiveSwitch: RiveViewModel { - private let onAnimation: String = "On" - private let offAnimation: String = "Off" - private let startAnimation: String = "StartOff" - - var action: ((Bool) -> Void)? = nil - var isOn = false { - didSet { - stop() - play(animationName: isOn ? onAnimation : offAnimation) - action?(isOn) - } - } - - init() { - super.init(fileName: "switch", animationName: startAnimation, fit: .cover) - } - - func view(_ action: ((Bool) -> Void)? = nil) -> some View { - self.action = action - return super.view().frame(width: 100, height: 50, alignment: .center) - } - - func touchEnded(onArtboard artboard: RiveArtboard?, atLocation location: CGPoint) { - isOn.toggle() - } -} diff --git a/Example-iOS/Source/ExamplesMaster.swift b/Example-iOS/Source/ExamplesMaster.swift index ea48b560..65c1d71e 100644 --- a/Example-iOS/Source/ExamplesMaster.swift +++ b/Example-iOS/Source/ExamplesMaster.swift @@ -30,7 +30,6 @@ class ExamplesMasterTableViewController: UITableViewController { // MARK: SwiftUI View Examples /// Made from custom `Views` private lazy var swiftViews: [(String, AnyView)] = [ - //("Test Anim/SM Parity", typeErased(dismissableView: SwiftTestParityAnimSM())), ("Touch Events!", typeErased(dismissableView: SwiftTouchEvents())), ("Widget Collection", typeErased(dismissableView: SwiftWidgets())), ("Animation Player", typeErased(dismissableView: SwiftSimpleAnimation())),