-
Notifications
You must be signed in to change notification settings - Fork 118
/
Copy pathHero.swift
68 lines (56 loc) · 1.57 KB
/
Hero.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
67
68
//
// Hero.swift
// Popovers
//
// Created by A. Zheng (github.com/aheze) on 7/17/22.
// Copyright © 2022 A. Zheng. All rights reserved.
//
import SwiftUI
#if os(iOS)
// MARK: Work in progress, not usable yet
public extension Templates {
class Hero: ObservableObject {
public enum Selection {
case a
case b
}
@Published public var selection: Selection?
public init() {}
public func transitionForwards() {
guard selection == nil else { return }
selection = .a
DispatchQueue.main.asyncAfter(deadline: .now() + 0.09) {
withAnimation {
self.selection = .b
}
}
DispatchQueue.main.asyncAfter(deadline: .now() + 0.7) {
self.selection = nil
}
}
public func moveForwards() {
guard selection == nil else { return }
selection = .a
DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {
withAnimation {
self.selection = .b
}
}
}
public func moveBackwards() {
guard selection == .b else { return }
selection = .a
DispatchQueue.main.asyncAfter(deadline: .now() + 0.7) {
self.selection = nil
}
}
public func toggleMove() {
if selection == .none {
moveForwards()
} else {
moveBackwards()
}
}
}
}
#endif