Display a sheet that can be displayed as a sidebar on iPad in SwiftUI.
Note: This package is still a work in progress, and not everything may be fully documented. Proceed with caution!
This package provides a view that displays a sheet similar to Apple Maps that can also be presented as a sidebar on wider size classes.
Clone this repository via git clone or add the following dependency to
your package or project:
dependencies: [
.package(url: "https://github.com/alicerunsonfedora/adaptablesidebarsheetview", branch: "main")
]To display this view in your SwiftUI project, import the package and add
an AdaptableSidebarSheet:
import AdaptableSidebarSheetView
import SwiftUI
struct MyView: View {
var body: some View {
AdaptableSidebarSheet {
mainContent
} sheet: {
sheet
}
}
private var mainContent: some View { ... }
private var sheet: some View {
mySheet
.presentationDetents([.medium, .large])
}
}The sidebar sheet is configured to display the sidebar at a width similar
to UIKit's UISplitViewController's sidebar. This can be adjusted with the
preferredSidebarWidthFraction argument in the view's initializer:
import AdaptableSidebarSheet
import SwiftUI
struct MyView: View {
var body: some View {
AdaptableSidebarSheet(preferredSidebarWidthFraction: 0.4) {
...
} sheet: {
...
}
}
}The sidebar sheet can handle presentation automatically based on the horizontal size class. However, you may wish to control this behavior with more complex logic.
The sidebar sheet can accept a Binding to a boolean value that will be used
to handle presentation via
init(isPresented:preferredSidebarWidthFraction:content:sheet:):
import AdaptableSidebarSheet
import SwiftUI
struct MyView: View {
@State private var displaySheet = false
var body: some View {
AdaptableSidebarSheet(isPresented: $displaySheet) {
...
} sheet: {
...
}
}
}AdaptableSidebarSheetView is free and open-source software under the Mozilla Public License, v2.