Skip to content

Commit

Permalink
Fix the SwiftUI component examples
Browse files Browse the repository at this point in the history
  • Loading branch information
zplata committed Mar 15, 2022
1 parent 57d9464 commit bd9eb6f
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 62 deletions.
4 changes: 4 additions & 0 deletions Example-iOS/RiveExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
C9E0409F264DF1A3009ABC7C /* RiveSwitch.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9E0409E264DF1A3009ABC7C /* RiveSwitch.swift */; };
C9E040A7264DF95C009ABC7C /* RiveSwitchBridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9E040A6264DF95C009ABC7C /* RiveSwitchBridge.swift */; };
C9E040A9264DFCFD009ABC7C /* switch.riv in Resources */ = {isa = PBXBuildFile; fileRef = C9E040A8264DFCFD009ABC7C /* switch.riv */; };
E5CD7D6827DBF4D500BFE5E2 /* energy_bar_example.riv in Resources */ = {isa = PBXBuildFile; fileRef = E5CD7D6527DBF4D500BFE5E2 /* energy_bar_example.riv */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -156,6 +157,7 @@
C9E0409E264DF1A3009ABC7C /* RiveSwitch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RiveSwitch.swift; sourceTree = "<group>"; };
C9E040A6264DF95C009ABC7C /* RiveSwitchBridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RiveSwitchBridge.swift; sourceTree = "<group>"; };
C9E040A8264DFCFD009ABC7C /* switch.riv */ = {isa = PBXFileReference; lastKnownFileType = file; path = switch.riv; sourceTree = "<group>"; };
E5CD7D6527DBF4D500BFE5E2 /* energy_bar_example.riv */ = {isa = PBXFileReference; lastKnownFileType = file; name = energy_bar_example.riv; path = ../../../../../Downloads/energy_bar_example.riv; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -211,6 +213,7 @@
042C88CF2644447500E7DBB2 /* basketball.riv */,
048002882729AA4400F7132B /* clean_icon_set.riv */,
042C88D92644447500E7DBB2 /* clipping.riv */,
E5CD7D6527DBF4D500BFE5E2 /* energy_bar_example.riv */,
042C88D32644447500E7DBB2 /* explorer.riv */,
042C88D02644447500E7DBB2 /* f22.riv */,
042C88D12644447500E7DBB2 /* flux_capacitor.riv */,
Expand Down Expand Up @@ -451,6 +454,7 @@
0450446126B3F71E007B25CA /* constrained.riv in Resources */,
C9D3DE68264F49F4001BA265 /* life_bar.riv in Resources */,
042C88DB2644447500E7DBB2 /* wacky.riv in Resources */,
E5CD7D6827DBF4D500BFE5E2 /* energy_bar_example.riv in Resources */,
042C88EB2644447500E7DBB2 /* clipping.riv in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1310"
LastUpgradeVersion = "1320"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion Example-iOS/Source/SwiftUI/Button/RiveButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct RiveButton: View {
.clipShape(RoundedRectangle(cornerRadius: 25, style: .continuous))
.onTapGesture {
controller.stop()
try? controller.play()
try? controller.play("Pull")

action?()
}
Expand Down
23 changes: 4 additions & 19 deletions Example-iOS/Source/SwiftUI/ProgressBar/RiveProgressBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,14 @@
import SwiftUI
import RiveRuntime

//struct RiveProgressBar: View {
//
// let resource: String
//
// @Binding var health: Double
//
// var body: some View {
// VStack {
// RiveProgressBarBridge(health: $health)
// .frame(width: 300, height: 75)
// }
// }
//}
struct RiveProgressBar: View {

var resource: String = "life_bar"
var controller: RiveController;

@Binding var health: Double
let resource: String
var controller: RiveController

var body: some View {
VStack {
RiveViewSwift(resource: resource, autoplay: true, stateMachine: "Life Machine", controller: controller)
RiveViewSwift(resource: resource, fit: Binding.constant(.fitCover), autoplay: true, stateMachine: "State Machine ", controller: controller)
.frame(width: 300, height: 75)
}
}
Expand All @@ -40,6 +25,6 @@ struct RiveProgressBar: View {

struct RiveProgressBar_Previews: PreviewProvider {
static var previews: some View {
RiveProgressBar(resource: "life_bar", controller: RiveController(), health: Binding.constant(50.0))
RiveProgressBar(resource: "energy_bar_example", controller: RiveController())
}
}
15 changes: 3 additions & 12 deletions Example-iOS/Source/SwiftUI/RiveComponents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct RiveComponents: View {
@State var play: Bool = false

/// Tracks the health value coming from the slide for the progress bar
@State var health: Double = 100
@State var health: Double = 0

@State var sliderController: RiveController = RiveController()

Expand All @@ -38,22 +38,13 @@ struct RiveComponents: View {
}
VStack {
Text("RiveProgressBar:")
RiveProgressBar(resource: "life_bar", controller: sliderController, health: $health)
RiveProgressBar(resource: "energy_bar_example", controller: sliderController)
}
// Slider(
// value: $health,
// in: 0...100
// )
Slider(value: Binding(get: {
self.health
}, set: { (newVal) in
self.health = newVal
print(newVal)
try? self.sliderController.setBooleanState("Life Machine", inputName: "100", value: true)
try? self.sliderController.setBooleanState("Life Machine", inputName: "75", value: newVal < 100)
try? self.sliderController.setBooleanState("Life Machine", inputName: "50", value: newVal <= 66)
try? self.sliderController.setBooleanState("Life Machine", inputName: "25", value: newVal <= 33)
try? self.sliderController.setBooleanState("Life Machine", inputName: "0", value: newVal <= 0)
try? self.sliderController.setNumberState("State Machine ", inputName: "Energy", value: Float(newVal))
}), in: 0...100)
.padding()
}
Expand Down
31 changes: 2 additions & 29 deletions Example-iOS/Source/SwiftUI/Switch/RiveSwitch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,40 +26,13 @@ struct RiveSwitch: View {
.frame(width: 100, height: 50)
.onTapGesture {
on = !on
try? controller.play(onAnimation)
self.controller.stop()
try? self.controller.play(on ? onAnimation : offAnimation)
action?(on)
}
}
}

//struct RiveSwitch: View {
// @State var switchToOn: Bool = false
// @State var switchToOff: Bool = false
// @State var on: Bool = false
//
// let resource: String
// var onAnimation: String = "On"
// var offAnimation: String = "Off"
// var startAnimation: String = "StartOff"
// var action: ((Bool) -> Void)? = nil
//
// var body: some View {
// RiveSwitchBridge(resource: resource, fit: .fitCover, switchToOn: $switchToOn, switchToOff: $switchToOff)
// .frame(width: 100, height: 50)
// .onTapGesture {
// switchToOn = false
// switchToOff = false
// if on {
// switchToOff = true
// } else {
// switchToOn = true
// }
// on = !on
// action?(on)
// }
// }
//}

struct RiveSwitch_Previews: PreviewProvider {
static var previews: some View {
RiveSwitch(resource: "switch")
Expand Down

0 comments on commit bd9eb6f

Please sign in to comment.