-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// iOS 16 and SwiftUI introduced presentationDetent modifier to showcase full sheet, half bottom sheet and also you can use fractioned and height to showcase | ||
// a sheet according your convenience | ||
|
||
import SwiftUI | ||
|
||
enum SheetType: CaseIterable { | ||
case half | ||
case full | ||
case heighted | ||
case fractioned | ||
|
||
var name: String { | ||
switch self { | ||
case .half: | ||
return "Half" | ||
case .full: | ||
return "Full" | ||
case .heighted: | ||
return "Height - 100" | ||
case .fractioned: | ||
return "Fraction - 3/4th" | ||
} | ||
} | ||
} | ||
|
||
struct ContentView: View { | ||
|
||
@State private var showSheet = false | ||
@State private var sheetType: SheetType = .half | ||
|
||
var body: some View { | ||
Form { | ||
Picker("Sheet Styles", selection: $sheetType) { | ||
ForEach(SheetType.allCases, id: \.self) { | ||
Text($0.name) | ||
} | ||
} | ||
Button("Show Sheet") { | ||
showSheet.toggle() | ||
} | ||
.sheet(isPresented: $showSheet) { | ||
SheetView() | ||
.presentationDetents([sheetDetent(type: sheetType)]) | ||
} | ||
} | ||
} | ||
|
||
func sheetDetent(type: SheetType) -> PresentationDetent { | ||
switch type { | ||
case .half: | ||
return .medium | ||
case .full: | ||
return .large | ||
case .heighted: | ||
return .height(100) | ||
case .fractioned: | ||
return .fraction(0.75) | ||
} | ||
} | ||
|
||
} | ||
|
||
struct SheetView: View { | ||
var body: some View { | ||
VStack { | ||
|
||
} | ||
} | ||
} | ||
|
||
|