|
| 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