-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathFirefliesView.swift
48 lines (44 loc) · 1.5 KB
/
FirefliesView.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
//
// FirefliesView.swift
// Vortex
// https://www.github.com/twostraws/Vortex
// See LICENSE for license information.
//
import SwiftUI
import Vortex
/// A sample view demonstrating fireflies that are repelled from the user's touch.
struct FirefliesView: View {
@State private var isDragging = false
var body: some View {
VortexViewReader { proxy in
ZStack(alignment: .bottom) {
if isDragging {
Text("Release your drag to reset the fireflies.")
.padding(.bottom, 20)
} else {
Text("Drag anywhere to repel the fireflies.")
.padding(.bottom, 20)
}
// Show the fireflies preset using default symbols
VortexView(.fireflies)
.gesture(
DragGesture(minimumDistance: 0)
.onChanged { value in
proxy.attractTo(value.location)
proxy.particleSystem?.attractionStrength = -2
isDragging = true
}
.onEnded { _ in
proxy.particleSystem?.attractionStrength = 0
isDragging = false
}
)
}
}
.navigationSubtitle("Demonstrates the fireflies preset with repulsion")
.ignoresSafeArea(edges: .top)
}
}
#Preview {
FirefliesView()
}