-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathContentView.swift
More file actions
128 lines (119 loc) · 4.29 KB
/
ContentView.swift
File metadata and controls
128 lines (119 loc) · 4.29 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//
// ContentView.swift
// Ciaone
//
// Created by Stefano Bertagno on 04/12/22.
//
import SwiftUI
import DropView
enum Kind: String, Identifiable {
case one
case two
var id: String { rawValue }
}
struct ContentView: View {
/// Whether it's presenting the drop view or not.
@State var item: Kind?
/// The vertical alignment.
@State var alignment: HashableVerticalAlignment = .top
/// The time interval before it auto-dismisses.
@State var timer: TimeInterval = 2
/// Whether it should auto-dismiss or not.
@State var shouldAutoDismiss: Bool = true
/// Whether the drop view should be dismissed on drag or not.
@State var shouldDismissOnDrag: Bool = true
/// The underlying view.
var body: some View {
NavigationStack {
Form {
Section(header: Text("General")) {
Picker("Vertical alignment", selection: $alignment) {
Text("Top").tag(HashableVerticalAlignment.top)
Text("Center").tag(HashableVerticalAlignment.center)
Text("Bottom").tag(HashableVerticalAlignment.bottom)
}
Toggle("Drag to dismiss", isOn: $shouldDismissOnDrag)
}
Section(header: Text("Auto dismiss")) {
Stepper(
"Timer \(Int(timer))s",
value: $timer,
in: 2 ... 10
)
.disabled(!shouldAutoDismiss)
Toggle("Auto dimiss", isOn: $shouldAutoDismiss)
}
ControlGroup {
Button {
item = .one
} label: {
Text("Default DropView")
}
Button {
item = .two
} label: {
Text("Custom View")
}
Button(role: .destructive) {
item = nil
} label: {
Text("Dismiss")
}
}
}
.navigationTitle("DropView")
}
.drop(
item: $item,
alignment: alignment.alignment,
dismissingAfter: shouldAutoDismiss ? timer : .greatestFiniteMagnitude,
dismissingOnDrag: shouldDismissOnDrag
) {
switch $0 {
case .one:
DropView(
title: "DropView",
subtitle: "github.com/sbertix/DropView"
) {
Image(systemName: "hand.wave.fill")
.imageScale(.large)
.font(.headline)
.foregroundColor(.secondary)
} trailing: {
Image(systemName: "star.circle.fill")
.resizable()
.frame(width: 40, height: 40)
.foregroundColor(.accentColor)
}
default:
VStack(alignment: .leading, spacing: 2) {
Text("This is not a DropView")
.font(.headline)
.fixedSize(horizontal: false, vertical: true)
Text(
"""
You can now use whatever you want inside of the `drop` view builder,\
getting position, transitions,\
animations and drag gesture behavior for free.
"""
)
.font(.footnote)
.foregroundStyle(.secondary)
.fixedSize(horizontal: false, vertical: true)
}
.multilineTextAlignment(.leading)
.padding()
.background(.regularMaterial, in: RoundedRectangle(cornerRadius: 12, style: .continuous))
.overlay(
RoundedRectangle(cornerRadius: 12, style: .continuous)
.strokeBorder(Color(.separator), lineWidth: 1)
)
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}