Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Sources/BottomSheet/BottomSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ struct SheetPlus<HContent: View, MContent: View, Background: View>: ViewModifier
.onPreferenceChange(SheetPlusKey.self) { value in
/// Quick hack to prevent the scrollview from resetting the height when keyboard shows up.
/// Replace if the root cause has been located.
if value.detents.count == 0 { return }
if value.detents.count == 0 || value.selectedDetent == .hidden {
isPresented = false
return
}

sheetConfig = value
translation = value.translation
Expand Down
1 change: 1 addition & 0 deletions Sources/BottomSheet/Detents/DetentDefaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ internal struct PresentationDetentDefaults {
static let small: CGFloat = UIScreen.main.bounds.height * 0.2
static let medium: CGFloat = UIScreen.main.bounds.height * 0.5
static let large: CGFloat = UIScreen.main.bounds.height * 0.9
static let hidden: CGFloat = 0
}
2 changes: 2 additions & 0 deletions Sources/BottomSheet/Detents/DetentHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ internal func detentLimits(detents: Set<PresentationDetent>) -> (min: CGFloat, m
return PresentationDetentDefaults.medium
case .large:
return PresentationDetentDefaults.large
case .hidden:
return PresentationDetentDefaults.hidden
case .fraction(let fraction):
return UIScreen.main.bounds.height * fraction
case .height(let height):
Expand Down
37 changes: 37 additions & 0 deletions Sources/BottomSheet/Detents/Detents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,46 @@

import SwiftUI

/**
An enumeration to represent various form of PresentationDetent

- `small`: A small sized bottom sheet. `.fraction(0.2)`
- `medium`: A medium sized bottom sheet, `.fraction(0.5)`
- `large`: A large sized bottom sheet. `.fraction(0.9)`
- `hidden`: Hide bottom sheet.
- `fraction`: Relative to screen height.
- `height`: A constant height.
*/

public enum PresentationDetent: Hashable {
/**
.fraction(0.2)
*/
case small

/**
.fraction(0.5)
*/
case medium

/**
.fraction(0.9)
*/
case large

/**
Hide bottom sheet
*/
case hidden

/**
CGFloat 0 to 1
*/
case fraction(CGFloat)

/**
A constant height.
*/
case height(CGFloat)

public var size: CGFloat {
Expand All @@ -22,6 +57,8 @@ public enum PresentationDetent: Hashable {
return PresentationDetentDefaults.medium
case .large:
return PresentationDetentDefaults.large
case .hidden:
return PresentationDetentDefaults.hidden
case .fraction(let fraction):
return min(
UIScreen.main.bounds.height * fraction,
Expand Down
2 changes: 1 addition & 1 deletion Sources/BottomSheet/Preference Keys/ConfigKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct SheetPlusConfig: Equatable {
}

struct SheetPlusKey: PreferenceKey {
static var defaultValue: SheetPlusConfig = SheetPlusConfig(detents: [], selectedDetent: .constant(.height(.zero)), translation: 0)
static var defaultValue: SheetPlusConfig = SheetPlusConfig(detents: [], selectedDetent: .constant(.hidden), translation: 0)

static func reduce(value: inout SheetPlusConfig, nextValue: () -> SheetPlusConfig) {
/// This prevents the translation changes to be called whenever the keyboard is triggered.
Expand Down