Skip to content

Commit 1702332

Browse files
authored
New Year Update (#38)
- Update Copyright - Update swift-tools-version - Update deprecated code (real fix for #19, replaces #20) - Add `.absolutePositionValue` option (closes #37) - Add `BottomSheetPositionAbsolute` - Use explicit animations (fixes #31) - Hide examples in ReadMe - Implement and fix `.appleScrollBehavior` (closes #37)
1 parent 737c239 commit 1702332

14 files changed

+344
-93
lines changed

BottomSheetSwiftUI.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'BottomSheetSwiftUI'
3-
s.version = '2.4.0'
3+
s.version = '2.5.0'
44
s.summary = 'A sliding Sheet from the bottom of the Screen with 3 States build with SwiftUI.'
55

66
s.homepage = 'https://github.com/LucasMucGH/BottomSheet'

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
BottomSheet Changelog
22
==================
33

4+
#### v2.5.0
5+
- Update Copyright
6+
- Update swift-tools-version
7+
- Update deprecated code (real fix for #19, replaces #20)
8+
- Add `.absolutePositionValue` option #37
9+
- Add `BottomSheetPositionAbsolute`
10+
- Use explicit animations #31
11+
- Hide examples in ReadMe
12+
- Update and fix `.appleScrollBehavior` #37
13+
- Code clean up
14+
415
#### v2.4.0
516
- Add option to enable shadow
617
- Add pod install

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.3
1+
// swift-tools-version:5.1
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription

README.md

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ struct ContentView: View {
136136

137137
### Options
138138

139+
`.absolutePositionValue` Allows absolute values in pixels to be used as BottomSheetPosition values.
140+
139141
`.allowContentDrag` Allows the BottomSheet to move when dragging the mainContent.
140142

141143
- Do not use if the mainContent is packed into a ScrollView.
@@ -173,15 +175,15 @@ struct ContentView: View {
173175

174176
## Custom States
175177

176-
177178
You can create your own custom BottomSheetPosition enum:
178179
- The enum must be conforming to `CGFloat` and `CaseIterable`
179180
- The case and enum name doesnt matter
180181
- The case/state with `rawValue == 0` is hiding the BottomSheet
181-
- The value can be anythig between `0` and `1` (`x <= 1`, `x >= 0`)
182-
- The value is the height of the BottomSheet propotional to the screen height (`1 == 100% == full screen`)
182+
- The value can be anythig between `0` and `1` (`x <= 1`, `x >= 0`) or anything above `0` (`x >= 0`) when using the`.absolutePositionValue` option
183+
- The value is the height of the BottomSheet propotional to the screen height (`1 == 100% == full screen`) or the height of the BottomSheet in pixel (`1 == 1px`) when using the`.absolutePositionValue` option
183184
- The lowest value (greater than 0) automaticly gets the `.bottom` behavior. To prevent this please use the option `.noBottomPosition`
184185

186+
This BottomSheetPosition uses relative values.
185187
```swift
186188
import SwiftUI
187189

@@ -190,6 +192,13 @@ enum CustomBottomSheetPosition: CGFloat, CaseIterable {
190192
}
191193
```
192194

195+
This BottomSheetPositionAbsolute uses absolute values and requires the the`.absolutePositionValue` option.
196+
```swift
197+
public enum BottomSheetPositionAbsolute: CGFloat, CaseIterable {
198+
case top = 750, middle = 300, bottom = 100, hidden = 0
199+
}
200+
```
201+
193202
## Examples
194203

195204
**PLEASE NOTE:** When installed via Cocoapods, please keep in mind that the pod is called `BottomSheetSwiftUI` and not `BottomSheet`; so please use `import BottomSheetSwiftUI` instead.
@@ -198,22 +207,26 @@ enum CustomBottomSheetPosition: CGFloat, CaseIterable {
198207

199208
This BottomSheet shows additional information about a book.
200209
You can close it by swiping it away, by tapping on the background or the close button.
201-
It also uses a custom `enum` for the states, since only the states `.middle`, `.bottom` and `.hidden` should exist.
210+
The drag indicator is hidden.
211+
It uses a custom `enum` for the states with absolute values, since only the states `.middle`, `.bottom` and `.hidden` should exist with a predefined absolute height.
202212

203213
<img src="https://user-images.githubusercontent.com/63545066/132514316-c0d723c6-37fc-4104-b04c-6cf7bbcb0899.gif" height="600">
204214

215+
<details>
216+
<summary>Source Code</summary>
217+
205218
```swift
206219
import SwiftUI
207220
import BottomSheet
208221

209-
//The custom BottomSheetPosition enum.
222+
//The custom BottomSheetPosition enum with absolute values.
210223
enum BookBottomSheetPosition: CGFloat, CaseIterable {
211-
case middle = 0.4, bottom = 0.125, hidden = 0
224+
case middle = 300, bottom = 100, hidden = 0
212225
}
213226

214227
struct BookDetailView: View {
215228

216-
@State private var bottomSheetPosition: BookBottomSheetPosition = .middle
229+
@State var bottomSheetPosition: BookBottomSheetPosition = .middle
217230

218231
let backgroundColors: [Color] = [Color(red: 0.2, green: 0.85, blue: 0.7), Color(red: 0.13, green: 0.55, blue: 0.45)]
219232
let readMoreColors: [Color] = [Color(red: 0.70, green: 0.22, blue: 0.22), Color(red: 1, green: 0.32, blue: 0.32)]
@@ -224,7 +237,7 @@ struct BookDetailView: View {
224237
LinearGradient(gradient: Gradient(colors: self.backgroundColors), startPoint: .topLeading, endPoint: .bottomTrailing)
225238
.edgesIgnoringSafeArea(.all)
226239

227-
.bottomSheet(bottomSheetPosition: self.$bottomSheetPosition, options: [.allowContentDrag, .showCloseButton(), .swipeToDismiss, .tapToDissmiss], headerContent: {
240+
.bottomSheet(bottomSheetPosition: self.$bottomSheetPosition, options: [.noDragIndicator, .allowContentDrag, .showCloseButton(), .swipeToDismiss, .tapToDissmiss, .absolutePositionValue], headerContent: {
228241
//The name of the book as the heading and the author as the subtitle with a divider.
229242
VStack(alignment: .leading) {
230243
Text("Wuthering Heights")
@@ -279,27 +292,36 @@ struct BookButton: ButtonStyle {
279292
}
280293
}
281294
```
295+
</details>
282296

283297
### Word Search View
284298

285299
This BottomSheet shows nouns which can be filtered by searching.
286-
It adopts the scrolling behavior of apple, so that you can only scroll the `ScrollView` in the `.top` position.
300+
It adopts the scrolling behavior of apple, so that you can only scroll the `ScrollView` in the `.top` position.
287301
The higher the BottomSheet is dragged, the more blurry the background becomes (with the BlurEffect .dark) to move the focus to the BottomSheet.
288302

289303
<img src="https://user-images.githubusercontent.com/63545066/132514347-57c5397b-ec03-4716-8e01-4e693082e844.gif" height="600">
290304

305+
<details>
306+
<summary>Source Code</summary>
307+
291308
```swift
292309
import SwiftUI
293310
import BottomSheet
294311

295312
struct WordSearchView: View {
296313

297-
@State private var bottomSheetPosition: BottomSheetPosition = .middle
314+
@State var bottomSheetPosition: BottomSheetPosition = .middle
315+
@State var searchText: String = ""
298316

299-
@State private var searchText: String = ""
300317
let backgroundColors: [Color] = [Color(red: 0.28, green: 0.28, blue: 0.53), Color(red: 1, green: 0.69, blue: 0.26)]
301318
let words: [String] = ["birthday", "pancake", "expansion", "brick", "bushes", "coal", "calendar", "home", "pig", "bath", "reading", "cellar", "knot", "year", "ink"]
302319

320+
var filteredWords: [String] {
321+
self.words.filter({ $0.contains(self.searchText.lowercased()) || self.searchText.isEmpty })
322+
}
323+
324+
303325
var body: some View {
304326
//A green gradient as a background that ignores the safe area.
305327
LinearGradient(gradient: Gradient(colors: self.backgroundColors), startPoint: .topLeading, endPoint: .bottomTrailing)
@@ -322,20 +344,21 @@ struct WordSearchView: View {
322344
}
323345
}) {
324346
//The list of nouns that will be filtered by the searchText.
325-
ForEach(self.words.filter({ $0.contains(self.searchText.lowercased()) || self.searchText.isEmpty}), id: \.self) { word in
347+
ForEach(self.filteredWords, id: \.self) { word in
326348
Text(word)
327349
.font(.title)
328350
.padding([.leading, .bottom])
329351
.frame(maxWidth: .infinity, alignment: .leading)
330352
}
331353
.frame(maxWidth: .infinity, alignment: .leading)
332354
.transition(.opacity)
333-
.animation(.easeInOut)
355+
.animation(.easeInOut, value: self.filteredWords)
334356
.padding(.top)
335357
}
336358
}
337359
}
338360
```
361+
</details>
339362

340363
### Artist Songs View
341364

@@ -344,13 +367,16 @@ It has a custom animation and color for the drag indicator and the background, a
344367

345368
<img src="https://user-images.githubusercontent.com/63545066/132514283-b14b2977-c5d1-4b49-96b1-19995cd5a41f.gif" height="600">
346369

370+
<details>
371+
<summary>Source Code</summary>
372+
347373
```swift
348374
import SwiftUI
349375
import BottomSheet
350376

351377
struct ArtistSongsView: View {
352378

353-
@State private var bottomSheetPosition: BottomSheetPosition = .middle
379+
@State var bottomSheetPosition: BottomSheetPosition = .middle
354380

355381
let backgroundColors: [Color] = [Color(red: 0.17, green: 0.17, blue: 0.33), Color(red: 0.80, green: 0.38, blue: 0.2)]
356382
let songs: [String] = ["One Dance (feat. Wizkid & Kyla)", "God's Plan", "SICKO MODE", "In My Feelings", "Work (feat. Drake)", "Nice For What", "Hotline Bling", "Too Good (feat. Rihanna)", "Life Is Good (feat. Drake)"]
@@ -374,6 +400,7 @@ struct ArtistSongsView: View {
374400
}
375401
}
376402
```
403+
</details>
377404

378405
## Contributing
379406

Sources/BottomSheet/BottomSheet.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// BottomSheet.swift
33
//
44
// Created by Lucas Zischka.
5-
// Copyright © 2021 Lucas Zischka. All rights reserved.
5+
// Copyright © 2021-2022 Lucas Zischka. All rights reserved.
66
//
77

88
import SwiftUI
@@ -14,6 +14,8 @@ public struct BottomSheet {
1414
return lhs.rawValue == rhs.rawValue
1515
}
1616

17+
///Allows absolute values in pixels to be used as BottomSheetPosition values.
18+
case absolutePositionValue
1719
///Allows the BottomSheet to move when dragging the mainContent. Do not use if the mainContent is packed into a ScrollView.
1820
case allowContentDrag
1921
///Sets the animation for opening and closing the BottomSheet.
@@ -62,6 +64,8 @@ public struct BottomSheet {
6264
*/
6365
public var rawValue: String {
6466
switch self {
67+
case .absolutePositionValue:
68+
return "absolutePositionValue"
6569
case .allowContentDrag:
6670
return "allowContentDrag"
6771
case .animation:

Sources/BottomSheet/BottomSheetArray.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
// BottomSheetArray.swift
33
//
44
// Created by Lucas Zischka.
5-
// Copyright © 2021 Lucas Zischka. All rights reserved.
5+
// Copyright © 2021-2022 Lucas Zischka. All rights reserved.
66
//
77

88
import SwiftUI
99

1010
internal extension Array where Element == BottomSheet.Options {
11+
var absolutePositionValue: Bool {
12+
return self.contains(BottomSheet.Options.absolutePositionValue)
13+
}
14+
1115
var allowContentDrag: Bool {
1216
return self.contains(BottomSheet.Options.allowContentDrag)
1317
}

Sources/BottomSheet/BottomSheetPosition.swift

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,55 @@
22
// BottomSheetPosition.swift
33
//
44
// Created by Lucas Zischka.
5-
// Copyright © 2021 Lucas Zischka. All rights reserved.
5+
// Copyright © 2021-2022 Lucas Zischka. All rights reserved.
66
//
77

88
import SwiftUI
99

1010
/**
11-
The default BottomSheetPosition; it has the following cases and values: `top = 0.975`, `middle = 0.4`, `bottom = 0.125`, `hidden = 0`
11+
The default BottomSheetPosition; it has the following cases and values: `top = 0.975`, `middle = 0.4`, `bottom = 0.125`, `hidden = 0`.
12+
13+
This BottomSheetPosition uses relative values. For absolute values in pixels, see BottomSheetPositionAbsolute.
1214

1315
You can create your own custom BottomSheetPosition enum:
1416
- The enum must be conforming to `CGFloat` and `CaseIterable`
1517
- The case and enum name doesnt matter
1618
- The case/state with `rawValue == 0` is hiding the BottomSheet
17-
- The value can be anythig between `0` and `1` (`x <= 1`, `x >= 0`)
18-
- The value is the height of the BottomSheet propotional to the screen height (`1 == 100% == full screen`)
19+
- The value can be anythig between `0` and `1` (`x <= 1`, `x >= 0`) or anything above `0` (`x >= 0`) when using the`.absolutePositionValue` option
20+
- The value is the height of the BottomSheet propotional to the screen height (`1 == 100% == full screen`) or the height of the BottomSheet in pixel (`1 == 1px`) when using the`.absolutePositionValue` option
1921
- The lowest value (greater than 0) automaticly gets the `.bottom` behavior. To prevent this please use the option `.noBottomPosition`
2022
*/
2123
public enum BottomSheetPosition: CGFloat, CaseIterable {
22-
//The state where the height of the BottomSheet is 97.5%
24+
///The state where the height of the BottomSheet is 97.5%
2325
case top = 0.975
24-
//The state where the height of the BottomSheet is 40%
26+
///The state where the height of the BottomSheet is 40%
2527
case middle = 0.4
26-
//The state where the height of the BottomSheet is 12.5% and the `mainContent` is hidden
28+
///The state where the height of the BottomSheet is 12.5% and the `mainContent` is hidden
2729
case bottom = 0.125
28-
//The state where the BottomSheet is hidden
30+
///The state where the BottomSheet is hidden
31+
case hidden = 0
32+
}
33+
34+
/**
35+
The default BottomSheetPositionAbsolute; it has the following cases and values: `top = 750`, `middle = 300`, `bottom = 100`, `hidden = 0`.
36+
37+
This BottomSheetPositionAbsolute uses absolute values and requires the the`.absolutePositionValue` option. For relative values in pixels, see BottomSheetPosition.
38+
39+
You can create your own custom BottomSheetPosition enum:
40+
- The enum must be conforming to `CGFloat` and `CaseIterable`
41+
- The case and enum name doesnt matter
42+
- The case/state with `rawValue == 0` is hiding the BottomSheet
43+
- The value can be anythig between `0` and `1` (`x <= 1`, `x >= 0`) or anything above `0` (`x >= 0`) when using the`.absolutePositionValue` option
44+
- The value is the height of the BottomSheet propotional to the screen height (`1 == 100% == full screen`) or the height of the BottomSheet in pixel (`1 == 1px`) when using the`.absolutePositionValue` option
45+
- The lowest value (greater than 0) automaticly gets the `.bottom` behavior. To prevent this please use the option `.noBottomPosition`
46+
*/
47+
public enum BottomSheetPositionAbsolute: CGFloat, CaseIterable {
48+
///The state where the height of the BottomSheet is 750px
49+
case top = 750
50+
///The state where the height of the BottomSheet is 300px
51+
case middle = 300
52+
///The state where the height of the BottomSheet is 100px and the `mainContent` is hidden
53+
case bottom = 100
54+
///The state where the BottomSheet is hidden
2955
case hidden = 0
3056
}

0 commit comments

Comments
 (0)