Skip to content

Commit 17ff2de

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/master'
2 parents a3a455a + c773cc5 commit 17ff2de

File tree

6 files changed

+38
-191
lines changed

6 files changed

+38
-191
lines changed

Package.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import PackageDescription
66
let package = Package(
77
name: "Drawer",
88
platforms: [
9-
.iOS(.v13),
10-
.macOS(.v10_15)
9+
.iOS(.v13)
1110
],
1211
products: [
1312
// Products define the executables and libraries produced by a package, and make them visible to other packages.

Sources/Drawer/Drawer+Computed.swift

Lines changed: 13 additions & 30 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)
@@ -54,25 +44,18 @@ extension Drawer {
5444
}
5545
}
5646

57-
return VStack {
58-
Spacer()
59-
.frame(height:
60-
UIScreen.main.bounds.height + fullHeight
61-
/*+ (landscape ? 20 : 0)*/)
62-
63-
HStack {
64-
if (alignment == .trailing || alignment == .center) {
65-
Spacer().animation(.default)
66-
}
67-
content
68-
.frame(height: fullHeight)
69-
.offset(y: offset)
70-
.animation(animation)
71-
.gesture(dragGesture)
72-
.frame(width: alignment == .fullscreen ? nil : fixedWidth)
73-
if (alignment == .leading || alignment == .center) {
74-
Spacer().animation(.default)
75-
}
47+
return GeometryReader { (proxy) in
48+
VStack {
49+
Spacer()
50+
.frame(height:
51+
proxy.frame(in: .global).height + self.fullHeight
52+
/*+ (landscape ? 20 : 0)*/)
53+
54+
self.content
55+
.frame(height: self.fullHeight)
56+
.offset(y: self.offset)
57+
.animation(self.animation)
58+
.gesture(self.dragGesture)
7659
}
7760
}
7861
}

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 & 83 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(
@@ -22,32 +20,7 @@ public extension Drawer {
2220
springHeight: springHeight,
2321
didRest: didRest,
2422
didLayoutForSizeClass: didLayoutForSizeClass,
25-
alignment: $alignment,
26-
width: $fixedWidth,
2723
impactGenerator: impactGenerator,
28-
locked: $locked,
29-
lockedHeight: lockedHeight,
30-
content: content)
31-
}
32-
33-
/// Locks the drawer in a controlled position
34-
/// - Parameters:
35-
/// - locked: Indicates if the drawer is locked
36-
/// - height: A function reading the current resting height of the drawer and returning the height to lock the drawer
37-
/// - Returns: Drawer
38-
func locked(_ locked: Binding<Bool>, to height: @escaping (_ restingHeight: CGFloat) -> CGFloat) -> Drawer {
39-
return Drawer(
40-
heights: $heights,
41-
height: self.height,
42-
restingHeight: restingHeight,
43-
springHeight: springHeight,
44-
didRest: didRest,
45-
didLayoutForSizeClass: didLayoutForSizeClass,
46-
alignment: $alignment,
47-
width: $fixedWidth,
48-
impactGenerator: impactGenerator,
49-
locked: locked,
50-
lockedHeight: height,
5124
content: content)
5225
}
5326

@@ -62,11 +35,7 @@ public extension Drawer {
6235
springHeight: max(spring, 0),
6336
didRest: didRest,
6437
didLayoutForSizeClass: didLayoutForSizeClass,
65-
alignment: $alignment,
66-
width: $fixedWidth,
6738
impactGenerator: impactGenerator,
68-
locked: $locked,
69-
lockedHeight: lockedHeight,
7039
content: content)
7140
}
7241

@@ -82,11 +51,7 @@ public extension Drawer {
8251
springHeight: springHeight,
8352
didRest: didRest,
8453
didLayoutForSizeClass: didLayoutForSizeClass,
85-
alignment: $alignment,
86-
width: $fixedWidth,
8754
impactGenerator: impactGenerator,
88-
locked: $locked,
89-
lockedHeight: lockedHeight,
9055
content: content)
9156
}
9257

@@ -101,11 +66,7 @@ public extension Drawer {
10166
springHeight: springHeight,
10267
didRest: didRest,
10368
didLayoutForSizeClass: didLayoutForSizeClass,
104-
alignment: $alignment,
105-
width: $fixedWidth,
10669
impactGenerator: impactGenerator,
107-
locked: $locked,
108-
lockedHeight: lockedHeight,
10970
content: content)
11071
}
11172

@@ -121,49 +82,7 @@ public extension Drawer {
12182
springHeight: springHeight,
12283
didRest: didRest,
12384
didLayoutForSizeClass: didLayoutForSizeClass,
124-
alignment: $alignment,
125-
width: $fixedWidth,
126-
impactGenerator: impactGenerator,
127-
locked: $locked,
128-
lockedHeight: lockedHeight,
129-
content: content)
130-
}
131-
132-
/// Defines a width for the drawer when not in fullscreen alignment
133-
/// - Parameter width: Width for the drawer when not in fullscreen alignment
134-
/// - Returns: Drawer
135-
func width(_ width: Binding<CGFloat?>) -> Drawer {
136-
return Drawer(
137-
heights: $heights,
138-
height: height,
139-
restingHeight: restingHeight,
140-
springHeight: springHeight,
141-
didRest: didRest,
142-
didLayoutForSizeClass: didLayoutForSizeClass,
143-
alignment: $alignment,
144-
width: width,
145-
impactGenerator: impactGenerator,
146-
locked: $locked,
147-
lockedHeight: lockedHeight,
148-
content: content)
149-
}
150-
151-
/// Defines the alignment for the drawer
152-
/// - Parameter alignment: `leading`, `trailing`, `center`, or `fullscreen`
153-
/// - Returns: Drawer
154-
func alignment(_ alignment: Binding<DrawerAlignment>) -> Drawer {
155-
return Drawer(
156-
heights: $heights,
157-
height: height,
158-
restingHeight: restingHeight,
159-
springHeight: springHeight,
160-
didRest: didRest,
161-
didLayoutForSizeClass: didLayoutForSizeClass,
162-
alignment: alignment,
163-
width: $fixedWidth,
16485
impactGenerator: impactGenerator,
165-
locked: $locked,
166-
lockedHeight: lockedHeight,
16786
content: content)
16887
}
16988
}

Sources/Drawer/Drawer.swift

Lines changed: 2 additions & 71 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 {
@@ -50,12 +46,6 @@ public struct Drawer<Content>: View where Content: View {
5046
/// A callback executed when the drawer is layed out for a new size class
5147
internal var didLayoutForSizeClass: ((SizeClass) -> ())? = nil
5248

53-
// MARK: Width
54-
55-
@Binding internal var alignment: DrawerAlignment
56-
57-
@Binding internal var fixedWidth: CGFloat?
58-
5949
// MARK: Gestures
6050

6151
@State internal var dragging: Bool = false
@@ -94,61 +84,11 @@ public extension Drawer {
9484
self._height = .init(initialValue: startingHeight ?? heights.wrappedValue.first!)
9585
self._restingHeight = .init(initialValue: startingHeight ?? heights.wrappedValue.first!)
9686
self.content = content()
97-
self._locked = .constant(false)
98-
self.lockedHeight = { _ in return CGFloat.zero }
99-
self._alignment = .constant(.fullscreen)
100-
self._fixedWidth = .constant(nil)
101-
}
102-
103-
/// A bottom-up view that conforms to multiple heights
104-
/// - Parameters:
105-
/// - heights: The possible resting heights of the drawer
106-
/// - startingHeight: The starting height of the drawer. Defaults to the first height marker if not specified
107-
/// - content: The view that defines the drawer
108-
@available(*, deprecated)
109-
init(
110-
heights: [CGFloat],
111-
startingHeight: CGFloat? = nil,
112-
@ViewBuilder _ content: () -> Content
113-
) {
114-
self._heights = .constant(heights)
115-
self._height = .init(initialValue: startingHeight ?? heights.first!)
116-
self._restingHeight = .init(initialValue: startingHeight ?? heights.first!)
117-
self.content = content()
118-
self._locked = .constant(false)
119-
self.lockedHeight = { _ in return CGFloat.zero }
120-
self._alignment = .constant(.fullscreen)
121-
self._fixedWidth = .constant(nil)
122-
}
123-
124-
// MARK: Deprecated Inits
125-
126-
/// A bottom-up view that conforms to multiple heights
127-
/// - Parameters:
128-
/// - heights: The possible resting heights of the drawer
129-
/// - startingHeight: The starting height of the drawer. Defaults to the first height marker if not specified
130-
/// - content: The view that defines the drawer
131-
@available(*, deprecated)
132-
init(
133-
heights: [CGFloat],
134-
startingHeight: CGFloat? = nil,
135-
impact: UIImpactFeedbackGenerator.FeedbackStyle?,
136-
@ViewBuilder _ content: () -> Content
137-
) {
138-
self._heights = .constant(heights)
139-
self._height = .init(initialValue: startingHeight ?? heights.first!)
140-
self._restingHeight = .init(initialValue: startingHeight ?? heights.first!)
141-
self.content = content()
142-
if let impact = impact {
143-
self.impactGenerator = UIImpactFeedbackGenerator(style: impact)
144-
}
145-
self._locked = .constant(false)
146-
self.lockedHeight = { _ in return CGFloat.zero }
147-
self._alignment = .constant(.fullscreen)
148-
self._fixedWidth = .constant(nil)
14987
}
15088
}
15189

90+
// MARK: Internal Init
91+
15292
internal extension Drawer {
15393
init(
15494
heights: Binding<[CGFloat]>,
@@ -157,11 +97,7 @@ internal extension Drawer {
15797
springHeight: CGFloat,
15898
didRest: ((_ height: CGFloat) -> ())?,
15999
didLayoutForSizeClass: ((SizeClass) -> ())?,
160-
alignment: Binding<DrawerAlignment>,
161-
width: Binding<CGFloat?>,
162100
impactGenerator: UIImpactFeedbackGenerator?,
163-
locked: Binding<Bool>,
164-
lockedHeight: @escaping (CGFloat) -> CGFloat,
165101
content: Content
166102
) {
167103
self._heights = heights
@@ -170,13 +106,8 @@ internal extension Drawer {
170106
self.springHeight = springHeight
171107
self.didRest = didRest
172108
self.didLayoutForSizeClass = didLayoutForSizeClass
173-
self._fixedWidth = width
174-
self._alignment = alignment
175109
self.content = content
176110
self.impactGenerator = impactGenerator
177-
self.lockedHeight = lockedHeight
178-
self._locked = locked
179-
180111
}
181112
}
182113

Sources/Drawer/SwiftUIView.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// SwiftUIView.swift
3+
//
4+
//
5+
// Created by Michael Verges on 7/20/20.
6+
//
7+
8+
import SwiftUI
9+
10+
#if DEBUG
11+
struct SwiftUIView_Previews: PreviewProvider {
12+
static var previews: some View {
13+
Drawer {
14+
Color.blue
15+
}
16+
.rest(at: .constant([100, 340]))
17+
.edgesIgnoringSafeArea(.vertical)
18+
}
19+
}
20+
#endif

0 commit comments

Comments
 (0)