Skip to content

Commit 5484912

Browse files
authored
Merge pull request #6 from maustinstar/new-features-0.1.0-dev
New features 0.1.0 dev
2 parents c773cc5 + 929f989 commit 5484912

File tree

5 files changed

+231
-141
lines changed

5 files changed

+231
-141
lines changed

Docs/Examples.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Examples
2+
3+
## Basic Usage
4+
5+
Embed your view content in a `ZStack` with the Drawer as the last element. The `heights` parameter defines a list of resting heights for the drawer.
6+
7+
```swift
8+
ZStack {
9+
10+
ScrollView {
11+
//...
12+
}
13+
14+
Drawer(heights: [100, 340]) {
15+
Color.blue
16+
}
17+
}
18+
```
19+
20+
## Multi-height drawer with haptic impact
21+
22+
<img src=https://raw.githubusercontent.com/maustinstar/swiftui-drawer/master/Docs/Media/white-drawer.gif width=200 />
23+
24+
```swift
25+
Drawer {
26+
ZStack {
27+
28+
RoundedRectangle(cornerRadius: 12)
29+
.foregroundColor(.white)
30+
.shadow(radius: 100)
31+
32+
VStack(alignment: .center) {
33+
Spacer().frame(height: 4.0)
34+
RoundedRectangle(cornerRadius: 3.0)
35+
.foregroundColor(.gray)
36+
.frame(width: 30.0, height: 6.0)
37+
Spacer()
38+
}
39+
}
40+
}
41+
.rest(at: .constant([100, 340, UIScreen.main.bounds.height - 40]))
42+
.impact(.light)
43+
```
44+
45+
## Example 2
46+
47+
<img src=https://raw.githubusercontent.com/maustinstar/swiftui-drawer/master/Docs/Media/blue-drawer.gif width=200 />
48+
49+
A basic two-height drawer.
50+
51+
```swift
52+
Drawer {
53+
Color.blue
54+
}.rest(at: .constant([100, 340]))
55+
```
File renamed without changes.
File renamed without changes.

Docs/Reference.md

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# Reference
2+
3+
## View Modifiers
4+
5+
Following SwiftUI's declarative syntax, these view modifiers return a modified Drawer.
6+
7+
### Rest
8+
9+
#### 🛏️ `rest(at heights: Binding<[CGFloat]>) -> Drawer`
10+
11+
Sets the active possible resting heights of the drawer.
12+
13+
**Usage**
14+
Set a spring distance
15+
```swift
16+
Drawer {
17+
Color.blue
18+
}.rest(at: $heights)
19+
```
20+
21+
### Impact
22+
23+
#### 💥 `impact(_: UIImpactFeedbackGenerator.FeedbackStyle) -> Drawer`
24+
25+
Sets the haptic impact of the drawer when resting.
26+
27+
**Feedback Style**
28+
Choose from the possible impact styles. [Apple Docs](https://developer.apple.com/documentation/uikit/uiimpactfeedbackgenerator/feedbackstyle)
29+
```swift
30+
public enum FeedbackStyle : Int {
31+
32+
/// A collision between small, light user interface elements.
33+
case light = 0
34+
35+
/// A collision between moderately sized user interface elements.
36+
case medium = 1
37+
38+
/// A collision between large, heavy user interface elements.
39+
case heavy = 2
40+
41+
@available(iOS 13.0, *)
42+
case soft = 3
43+
44+
@available(iOS 13.0, *)
45+
case rigid = 4
46+
}
47+
```
48+
49+
**Usage**
50+
```swift
51+
Drawer(heights: [100, 340]) {
52+
Color.blue
53+
}.impact(.light)
54+
```
55+
56+
### Spring
57+
58+
#### 🪀 `spring(_: CGFloat) -> Drawer`
59+
60+
Sets the springiness of the drawer when pulled past boundaries.
61+
62+
**Spring Level**
63+
A positive number, in pixels, to define how far the drawer can be streched beyond bounds.
64+
65+
A spring of 0 will not let the user drag the drawer beyond the bound of the minimum and maximum heights.
66+
67+
A positive spring level will allow users to pull the drawer a specified number of pixels beyond the bounds. The user's drag displacement is transformed by a [logistic curve](https://en.wikipedia.org/wiki/Logistic_function) for a natural hard-spring pull that reaches an asymptote.
68+
69+
Default is 12px.
70+
71+
**Usage**
72+
Set a spring distance
73+
```swift
74+
Drawer(heights: [100, 340]) {
75+
Color.blue
76+
}.spring(20)
77+
```
78+
79+
Toggle a spring distance
80+
```swift
81+
Drawer(heights: [100, 340]) {
82+
Color.blue
83+
}.spring(isSpringy ? 0 : 20)
84+
```
85+
86+
### OnRest
87+
88+
#### 😴 `onRest(_: @escaping (_ height: CGFloat) -> ()) -> Drawer`
89+
90+
A callback to receive updates when the drawer reaches a new resting level.
91+
92+
**Closure**
93+
This closure is executed every time the drawer reaches a new resting hieght. Use this when you want to receive updates on the drawer's changes.
94+
95+
**Usage**
96+
Lock into a fixed position.
97+
```swift
98+
Drawer(heights: [100, 340]) {
99+
Color.blue
100+
}.onRest { (restingHeight) in
101+
print(restingHeight)
102+
}
103+
```
104+
105+
### OnLayoutForSizeClass
106+
107+
#### 🔄 `onLayoutForSizeClass(_: @escaping (SizeClass) -> ()) -> Drawer`
108+
109+
A callback to receive updates when the drawer is layed out for a new size class.
110+
111+
**Closure**
112+
This closure is executed every time the device layout changes (portrait, landscape, and splitview).
113+
Use this to modify your view when the drawer's layout changes.
114+
115+
**Usage**
116+
Alter the resting heights and alignment when the screen layout changes.
117+
```swift
118+
Drawer(heights: [100, 340]) {
119+
Color.blue
120+
}
121+
.rest(at: $heights)
122+
.onLayoutForSizeClass { (sizeClass) in
123+
switch (sizeClass.horizontal, sizeClass.vertical) {
124+
case (.compact, .compact):
125+
// smaller iPhone landscape
126+
self.heights = [100, UIScreen.main.bounds.height - 40]
127+
break
128+
case (.compact, .regular):
129+
// iPhone portrait
130+
// iPad portrait splitview
131+
// iPad landscape smaller splitview
132+
self.heights = [100, 340, UIScreen.main.bounds.height - 40]
133+
break
134+
case (.regular, .compact):
135+
// larger iPhone landscape
136+
self.heights = [100, UIScreen.main.bounds.height - 40]
137+
break
138+
case (.regular, .regular):
139+
// iPad fullscreen
140+
// iPad landscape larger splitview
141+
self.heights = [100, UIScreen.main.bounds.height - 40]
142+
break
143+
default:
144+
// Unknown layout
145+
break
146+
}
147+
}
148+
```

0 commit comments

Comments
 (0)