-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuantumGraphView.swift
96 lines (86 loc) · 4.09 KB
/
QuantumGraphView.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import SwiftUI
// 'quantum_computer' vector image modified from https://publicdomainvectors.org/en/free-clipart/Image-of-scheme-of-an-atom-in-black-and-white/35163.html by 'OpenClipart' licensed under a public domain license
struct QuantumGraphView: View {
@ObservedObject var viewModel: QuantumViewModel
@Binding var publicKeyColor: Color
@Binding var secretKeyColor: Color
@State private var publicKeyShake = 0
@State private var quantumPulseStart = false
var body: some View {
GeometryReader { geo in
VStack {
Spacer()
// Public Key from prev
if #available(iOS 16.0, *) {
Style.boxify(Text("Your public key"), color: publicKeyColor)
.frame(maxWidth: geo.size.width*0.5)
.shake(with: publicKeyShake)
.onReceive(viewModel.$publicKeyDraggable) { bool in
if bool {
withAnimation(.shakeSpring()) {
publicKeyShake = 3
}
}
}
.onDrag {
quantumPulseStart = true
return NSItemProvider(object: "key" as NSItemProviderWriting)
}
.disabled(viewModel.publicKeyDraggable == false)
} else {
Style.boxify(Text("Your public key"), color: publicKeyColor)
.frame(maxWidth: geo.size.width*0.5)
}
Image("arrow_down")
.resizable()
.frame(width: 18, height: 18)
.invertOnDarkTheme()
.transition(.enterFromBottom)
// Quantum Computer with Shor's Algorithm
if #available(iOS 16.0, *) {
Image("quantum_computer")
.scaleEffect(quantumPulseStart ? 1.05 : 1)
.animation(quantumPulseStart ? .easeInOut.repeatForever(autoreverses: true) : .default, value: quantumPulseStart)
.dropDestination(for: String.self) { _, _ in
quantumPulseStart = false
viewModel.publicKeyDraggable = false
viewModel.pageTwo = false
viewModel.pageThree = true
return true
}
}
Text("Quantum computer running Shor's Algorithm")
if viewModel.pageThree {
// Unmixed colors
HStack {
// your secret
VStack {
Image("arrow_left")
.resizable()
.frame(width: 18, height: 18)
.invertOnDarkTheme()
.transition(.enterFromBottom)
Style.boxify(Text("User Secret"), color: secretKeyColor)
.frame(maxWidth: geo.size.width*0.5)
}
Spacer().frame(maxWidth: 25)
// base color
VStack {
Image("arrow_right")
.resizable()
.frame(width: 18, height: 18)
.invertOnDarkTheme()
.transition(.enterFromBottom)
Style.boxify(Text("Base Color"), color: .red)
.frame(maxWidth: geo.size.width*0.5)
}
}.transition(.enterFromBottom)
}
Spacer()
}
.frame(maxWidth: .infinity)
.padding()
.animation(.default, value: viewModel.pageThree)
}
}
}