Skip to content

Commit

Permalink
Merge pull request #7 from GlennBrann/glenn/bumping-version-and-acces…
Browse files Browse the repository at this point in the history
…sibility

bumping version to 15.0 and accessibility updates to default bottom sheet
  • Loading branch information
GlennBrann authored Feb 23, 2024
2 parents 236c946 + 26cf54a commit 0e68e6a
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 42 deletions.
6 changes: 3 additions & 3 deletions ManySheetsExample/ManySheetsExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 52;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
110 changes: 75 additions & 35 deletions ManySheetsExample/ManySheetsExample/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import ManySheets

struct ContentView: View {
@State var showSheet: Bool = false
@State var nativeSheet: Bool = false

let bottomSheetStyle = DefaultBottomSheetStyle(backgroundColor: .white)

Expand All @@ -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())
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// 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

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.
Expand Down
34 changes: 32 additions & 2 deletions Sources/ManySheets/DefaultBottomSheet/DefaultBottomSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public struct DefaultBottomSheet<Content: View>: View {

@State private var previousDragValue: DragGesture.Value?

@AccessibilityFocusState private var focused: Bool

public init(
isOpen: Binding<Bool>,
style: DefaultBottomSheetStyle = .defaultStyle(),
Expand All @@ -85,6 +87,9 @@ public struct DefaultBottomSheet<Content: View>: View {
if isOpen, (tapAwayToDismiss || blockContent) {
style.dimmingColor.opacity(0.25)
.ignoresSafeArea()
.accessibilityAction(.escape, {
isOpen = false
})
.onTapGesture {
if tapAwayToDismiss {
self.isOpen = false
Expand All @@ -96,8 +101,10 @@ public struct DefaultBottomSheet<Content: View>: 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)
Expand All @@ -112,17 +119,40 @@ public struct DefaultBottomSheet<Content: View>: 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
}
}
}
}

Expand Down

0 comments on commit 0e68e6a

Please sign in to comment.