-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes crashes with unknown layer states, adds SwiftUI state machine e…
…xample, tidies up file layout for SwiftUI
- Loading branch information
1 parent
640ce4e
commit b2e6939
Showing
20 changed files
with
203 additions
and
54 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
Example-iOS/Source/SwiftUI/ProgressBar/RiveProgressBar.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// RiveProgressBar.swift | ||
// RiveExample | ||
// | ||
// Created by Matt Sullivan on 5/14/21. | ||
// Copyright © 2021 Rive. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
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_Previews: PreviewProvider { | ||
static var previews: some View { | ||
|
||
|
||
RiveProgressBar(resource: "liquid", health: Binding.constant(50.0)) | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
Example-iOS/Source/SwiftUI/ProgressBar/RiveProgressBarBridge.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import SwiftUI | ||
import RiveRuntime | ||
|
||
struct RiveProgressBarBridge: UIViewRepresentable { | ||
let resource: String = "life_bar" | ||
var fit: Fit = .fitFill | ||
var alignment: RiveRuntime.Alignment = .alignmentCenter | ||
var stateMachine: String = "Life Machine" | ||
|
||
@Binding var health: Double | ||
|
||
/// The inputs | ||
private let input100Name = "100" | ||
private let input75Name = "75" | ||
private let input50Name = "50" | ||
private let input25Name = "25" | ||
private let input0Name = "0" | ||
|
||
/// Constructs the view | ||
func makeUIView(context: Context) -> RiveView { | ||
let riveView = RiveView( | ||
riveFile: getRiveFile(resourceName: resource), | ||
fit: fit, | ||
alignment: alignment, | ||
autoplay: true, | ||
stateMachine: stateMachine | ||
) | ||
|
||
// Always keep the 100 set; just how this state machine works | ||
riveView.setBooleanState(stateMachine, inputName: input100Name, value: true) | ||
|
||
return riveView | ||
} | ||
|
||
|
||
|
||
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
Oops, something went wrong.