-
Notifications
You must be signed in to change notification settings - Fork 57
/
SwiftLayout.swift
67 lines (60 loc) · 2.02 KB
/
SwiftLayout.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//
// Layout.swift
// RiveExample
//
// Created by Maxwell Talbot on 01/03/2022.
// Copyright © 2022 Rive. All rights reserved.
//
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.view()
.onChange(of: fit) { value in
riveViewModel.fit = value
}
.onChange(of: alignment) { value in
riveViewModel.alignment = value
}
}
HStack {
Text("Fit")
}
HStack {
Button("Fill", action: {fit = .fill})
Button("Contain", action: {fit = .contain})
Button("Cover", action: {fit = .cover})
}
HStack {
Button("Fit Width", action: {fit = .fitWidth})
Button("Fit Height", action: {fit = .fitHeight})
Button("Scale Down", action: {fit = .scaleDown})
}
HStack {
Button("None", action: {fit = .noFit})
}
HStack {
Text("Alignment")
}
HStack {
Button("Top Left", action: {alignment = .topLeft})
Button("Top Center", action: {alignment = .topCenter})
Button("Top Right", action: {alignment = .topRight})
}
HStack {
Button("Center Left", action: {alignment = .centerLeft})
Button("Center", action: {alignment = .center})
Button("Center Right", action: {alignment = .centerRight})
}
HStack {
Button("Bottom Left", action: {alignment = .bottomLeft})
Button("Bottom Center", action: {alignment = .bottomCenter})
Button("Bottom Right", action: {alignment = .bottomRight})
}
}
}