diff --git a/ManySheetsExample/ManySheetsExample.xcodeproj/project.pbxproj b/ManySheetsExample/ManySheetsExample.xcodeproj/project.pbxproj index 429bc26..9965d17 100644 --- a/ManySheetsExample/ManySheetsExample.xcodeproj/project.pbxproj +++ b/ManySheetsExample/ManySheetsExample.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 52; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -285,7 +285,7 @@ DEVELOPMENT_TEAM = 7YFWG6J4YR; ENABLE_PREVIEWS = YES; INFOPLIST_FILE = ManySheetsExample/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 14.0; + IPHONEOS_DEPLOYMENT_TARGET = 16.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -307,7 +307,7 @@ DEVELOPMENT_TEAM = 7YFWG6J4YR; ENABLE_PREVIEWS = YES; INFOPLIST_FILE = ManySheetsExample/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 14.0; + IPHONEOS_DEPLOYMENT_TARGET = 16.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", diff --git a/ManySheetsExample/ManySheetsExample/ContentView.swift b/ManySheetsExample/ManySheetsExample/ContentView.swift index 4a75d3e..22f8fd7 100644 --- a/ManySheetsExample/ManySheetsExample/ContentView.swift +++ b/ManySheetsExample/ManySheetsExample/ContentView.swift @@ -10,6 +10,7 @@ import ManySheets struct ContentView: View { @State var showSheet: Bool = false + @State var nativeSheet: Bool = false let bottomSheetStyle = DefaultBottomSheetStyle(backgroundColor: .white) @@ -18,46 +19,85 @@ struct ContentView: View { VStack { Button(action: { showSheet.toggle() }, label: { Text("Show Default Sheet") }) + + Button(action: { nativeSheet.toggle() }, + label: { Text("Show Default Sheet") }) } - DefaultBottomSheet( - isOpen: $showSheet, - style: bottomSheetStyle, - options: [.enableHandleBar, .tapAwayToDismiss, .swipeToDismiss] - ) { - VStack(alignment: .leading) { - HStack(alignment: .top) { - Image(systemName: "info.circle") - Text("Photos attached must be of cats and cats only") - .fixedSize(horizontal: false, vertical: true) - } - .padding(.bottom, 4) - Button( - action: { }, - label: { - HStack { - Image(systemName: "camera") - .foregroundColor(Color.blue) - Text("Take a photo") - } + } + .sheet(isPresented: $nativeSheet) { + VStack(alignment: .leading) { + HStack(alignment: .top) { + Image(systemName: "info.circle") + Text("Photos attached must be of cats and cats only") + .fixedSize(horizontal: false, vertical: true) + } + .padding(.bottom, 4) + Button( + action: { }, + label: { + HStack { + Image(systemName: "camera") + .foregroundColor(Color.blue) + Text("Take a photo") } - ) - .frame(height: 44) - Button( - action: { }, - label: { - HStack { - Image(systemName: "photo.on.rectangle") - .foregroundColor(Color.blue) - Text("Choose a photo") - } + } + ) + .frame(height: 44) + Button( + action: { }, + label: { + HStack { + Image(systemName: "photo.on.rectangle") + .foregroundColor(Color.blue) + Text("Choose a photo") } - ) - .frame(height: 44) + } + ) + .frame(height: 44) + } + .padding() + .padding(.bottom, 16) + .buttonStyle(PlainButtonStyle()) + .presentationDragIndicator(.visible) + } + .defaultBottomSheet( + isOpen: $showSheet, + style: bottomSheetStyle, + options: [.enableHandleBar, .tapAwayToDismiss, .swipeToDismiss] + ) { + VStack(alignment: .leading) { + HStack(alignment: .top) { + Image(systemName: "info.circle") + Text("Photos attached must be of cats and cats only") + .fixedSize(horizontal: false, vertical: true) } - .padding() - .padding(.bottom, 16) - .buttonStyle(PlainButtonStyle()) + .padding(.bottom, 4) + Button( + action: { }, + label: { + HStack { + Image(systemName: "camera") + .foregroundColor(Color.blue) + Text("Take a photo") + } + } + ) + .frame(height: 44) + Button( + action: { }, + label: { + HStack { + Image(systemName: "photo.on.rectangle") + .foregroundColor(Color.blue) + Text("Choose a photo") + } + } + ) + .frame(height: 44) } + .padding() + .padding(.bottom, 16) + .buttonStyle(PlainButtonStyle()) } } } diff --git a/Package.swift b/Package.swift index 50fa51c..a9e108c 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.4 +// swift-tools-version:5.7 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription @@ -6,7 +6,7 @@ import PackageDescription let package = Package( name: "ManySheets", platforms: [ - .iOS(.v14) + .iOS(.v15) ], products: [ // Products define the executables and libraries a package produces, and make them visible to other packages. diff --git a/Sources/ManySheets/DefaultBottomSheet/DefaultBottomSheet.swift b/Sources/ManySheets/DefaultBottomSheet/DefaultBottomSheet.swift index dcb8678..9746c3d 100644 --- a/Sources/ManySheets/DefaultBottomSheet/DefaultBottomSheet.swift +++ b/Sources/ManySheets/DefaultBottomSheet/DefaultBottomSheet.swift @@ -66,6 +66,8 @@ public struct DefaultBottomSheet: View { @State private var previousDragValue: DragGesture.Value? + @AccessibilityFocusState private var focused: Bool + public init( isOpen: Binding, style: DefaultBottomSheetStyle = .defaultStyle(), @@ -85,6 +87,9 @@ public struct DefaultBottomSheet: View { if isOpen, (tapAwayToDismiss || blockContent) { style.dimmingColor.opacity(0.25) .ignoresSafeArea() + .accessibilityAction(.escape, { + isOpen = false + }) .onTapGesture { if tapAwayToDismiss { self.isOpen = false @@ -96,8 +101,10 @@ public struct DefaultBottomSheet: View { if hasHandleBar { dragBar .frame( - width: maxWidth != nil ? maxWidth! : .infinity, - height: style.handleBarHeight + idealWidth: maxWidth != nil ? maxWidth! : .infinity, + maxWidth: maxWidth != nil ? maxWidth! : .infinity, + idealHeight: style.handleBarHeight, + maxHeight: style.handleBarHeight ) .background(style.backgroundColor) .padding(.top, 4) @@ -112,17 +119,40 @@ public struct DefaultBottomSheet: View { ) .transition(.move(edge: .bottom)) .gesture(dragGesture()) + .accessibilityAddTraits(.isModal) } } .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottom) .ignoresSafeArea() .animation(style.openAnimation, value: isOpen) + .onChange(of: isOpen) { isOpen in + if isOpen { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) { + focused = true + } + } else { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) { + focused = false + } + } + } } private var dragBar: some View { RoundedRectangle(cornerRadius: 5.0 / 2.0) .frame(width: 40, height: 5.0) .foregroundColor(style.handleBarColor) + .padding(8) + .frame(height: 44) + .accessibilityAddTraits(.isButton) + .accessibilityFocused($focused, equals: true) + .accessibilityHint("Double tap to dismiss") + .accessibilityLabel("Sheet grabber") + .accessibilityAction { + DispatchQueue.main.async { + isOpen = false + } + } } }