Skip to content

Commit 6d8e2e4

Browse files
committed
Remove lock features. Opt to alter heights instead
1 parent 9e252e5 commit 6d8e2e4

File tree

4 files changed

+5
-64
lines changed

4 files changed

+5
-64
lines changed

Sources/Drawer/Drawer+Computed.swift

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,12 @@ extension Drawer {
1616
}
1717

1818
internal var activeBound: ClosedRange<CGFloat> {
19-
let height = lockedHeight(restingHeight)
20-
return locked
21-
? height...height
22-
: heights.min()!...heights.max()!
19+
return heights.min()!...heights.max()!
2320
}
2421

2522
// MARK: View
2623

2724
private var offset: CGFloat {
28-
if locked && !dragging {
29-
DispatchQueue.main.async {
30-
let newHeight = self.lockedHeight(self.restingHeight)
31-
self.restingHeight = newHeight
32-
self.height = newHeight
33-
}
34-
}
3525
if !dragging && !heights.contains(restingHeight) {
3626
DispatchQueue.main.async {
3727
let newHeight = Drawer.closest(self.restingHeight, markers: self.heights)

Sources/Drawer/Drawer+Drag.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ internal extension Drawer {
3333

3434
func dragEnded(_ value: DragGesture.Value) {
3535
dragging = false
36-
if locked {
37-
height = restingHeight
38-
animation = Animation.spring()
39-
return
40-
}
4136

4237
let change = value.startLocation.y
4338
- value.predictedEndLocation.y + restingHeight

Sources/Drawer/Drawer+Modifiers.swift

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ import SwiftUI
99

1010
public extension Drawer {
1111

12-
/// Locks the drawer in a controlled position
13-
/// - Parameters:
14-
/// - locked: Indicates if the drawer is locked
15-
/// - height: A function reading the current resting height of the drawer and returning the height to lock the drawer
12+
/// Sets the resting heights of the drawer
13+
/// - Parameter heights: Possible resting heights for the drawer
1614
/// - Returns: Drawer
1715
func rest(at heights: Binding<[CGFloat]>) -> Drawer {
1816
return Drawer(
@@ -23,27 +21,6 @@ public extension Drawer {
2321
didRest: didRest,
2422
didLayoutForSizeClass: didLayoutForSizeClass,
2523
impactGenerator: impactGenerator,
26-
locked: $locked,
27-
lockedHeight: lockedHeight,
28-
content: content)
29-
}
30-
31-
/// Locks the drawer in a controlled position
32-
/// - Parameters:
33-
/// - locked: Indicates if the drawer is locked
34-
/// - height: A function reading the current resting height of the drawer and returning the height to lock the drawer
35-
/// - Returns: Drawer
36-
func locked(_ locked: Binding<Bool>, to height: @escaping (_ restingHeight: CGFloat) -> CGFloat) -> Drawer {
37-
return Drawer(
38-
heights: $heights,
39-
height: self.height,
40-
restingHeight: restingHeight,
41-
springHeight: springHeight,
42-
didRest: didRest,
43-
didLayoutForSizeClass: didLayoutForSizeClass,
44-
impactGenerator: impactGenerator,
45-
locked: locked,
46-
lockedHeight: height,
4724
content: content)
4825
}
4926

@@ -59,8 +36,6 @@ public extension Drawer {
5936
didRest: didRest,
6037
didLayoutForSizeClass: didLayoutForSizeClass,
6138
impactGenerator: impactGenerator,
62-
locked: $locked,
63-
lockedHeight: lockedHeight,
6439
content: content)
6540
}
6641

@@ -77,8 +52,6 @@ public extension Drawer {
7752
didRest: didRest,
7853
didLayoutForSizeClass: didLayoutForSizeClass,
7954
impactGenerator: impactGenerator,
80-
locked: $locked,
81-
lockedHeight: lockedHeight,
8255
content: content)
8356
}
8457

@@ -94,8 +67,6 @@ public extension Drawer {
9467
didRest: didRest,
9568
didLayoutForSizeClass: didLayoutForSizeClass,
9669
impactGenerator: impactGenerator,
97-
locked: $locked,
98-
lockedHeight: lockedHeight,
9970
content: content)
10071
}
10172

@@ -112,8 +83,6 @@ public extension Drawer {
11283
didRest: didRest,
11384
didLayoutForSizeClass: didLayoutForSizeClass,
11485
impactGenerator: impactGenerator,
115-
locked: $locked,
116-
lockedHeight: lockedHeight,
11786
content: content)
11887
}
11988
}

Sources/Drawer/Drawer.swift

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ public struct Drawer<Content>: View where Content: View {
2828
/// A callback executed when the drawer reaches a restingHeight
2929
internal var didRest: ((_ height: CGFloat) -> ())? = nil
3030

31-
@Binding internal var locked: Bool
32-
33-
internal var lockedHeight: (_ restingHeight: CGFloat) -> CGFloat
34-
3531
// MARK: Orientation
3632

3733
public struct SizeClass: Equatable {
@@ -88,8 +84,6 @@ public extension Drawer {
8884
self._height = .init(initialValue: startingHeight ?? heights.wrappedValue.first!)
8985
self._restingHeight = .init(initialValue: startingHeight ?? heights.wrappedValue.first!)
9086
self.content = content()
91-
self._locked = .constant(false)
92-
self.lockedHeight = { _ in return CGFloat.zero }
9387
}
9488

9589
/// A bottom-up view that conforms to multiple heights
@@ -107,8 +101,6 @@ public extension Drawer {
107101
self._height = .init(initialValue: startingHeight ?? heights.first!)
108102
self._restingHeight = .init(initialValue: startingHeight ?? heights.first!)
109103
self.content = content()
110-
self._locked = .constant(false)
111-
self.lockedHeight = { _ in return CGFloat.zero }
112104
}
113105

114106
// MARK: Deprecated Inits
@@ -132,11 +124,11 @@ public extension Drawer {
132124
if let impact = impact {
133125
self.impactGenerator = UIImpactFeedbackGenerator(style: impact)
134126
}
135-
self._locked = .constant(false)
136-
self.lockedHeight = { _ in return CGFloat.zero }
137127
}
138128
}
139129

130+
// MARK: Internal Init
131+
140132
internal extension Drawer {
141133
init(
142134
heights: Binding<[CGFloat]>,
@@ -146,8 +138,6 @@ internal extension Drawer {
146138
didRest: ((_ height: CGFloat) -> ())?,
147139
didLayoutForSizeClass: ((SizeClass) -> ())?,
148140
impactGenerator: UIImpactFeedbackGenerator?,
149-
locked: Binding<Bool>,
150-
lockedHeight: @escaping (CGFloat) -> CGFloat,
151141
content: Content
152142
) {
153143
self._heights = heights
@@ -158,9 +148,6 @@ internal extension Drawer {
158148
self.didLayoutForSizeClass = didLayoutForSizeClass
159149
self.content = content
160150
self.impactGenerator = impactGenerator
161-
self.lockedHeight = lockedHeight
162-
self._locked = locked
163-
164151
}
165152
}
166153

0 commit comments

Comments
 (0)