From 6027bc6483622da4ab1b232a50c8416c1e980909 Mon Sep 17 00:00:00 2001 From: Zheng Date: Sun, 16 Jan 2022 21:44:08 -0800 Subject: [PATCH] Add tip in accessibility view example --- .../PlaygroundFiles/AccessibilityView.swift | 8 +++++++- Sources/PopoverContainerView.swift | 7 +++++-- Sources/PopoverGestureContainer.swift | 6 ++---- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Examples/PopoversXcodeApp/PopoversXcodeApp/PlaygroundFiles/AccessibilityView.swift b/Examples/PopoversXcodeApp/PopoversXcodeApp/PlaygroundFiles/AccessibilityView.swift index 201d3d0..c4c8ab4 100644 --- a/Examples/PopoversXcodeApp/PopoversXcodeApp/PlaygroundFiles/AccessibilityView.swift +++ b/Examples/PopoversXcodeApp/PopoversXcodeApp/PlaygroundFiles/AccessibilityView.swift @@ -48,13 +48,19 @@ struct AccessibilityView: View { Text("By default, a \(Image(systemName: "xmark.circle.fill")) button will appear next to popovers when VoiceOver is on. You can customize this with `attributes.accessibility.dismissButtonLabel`.") } + + HStack { + ExampleImage.tip + + Text("If you already have a button that sets `present` to `false`, remove the default dismiss button with `dismissButtonLabel = nil`.") + } } } .padding() .background(.background) .cornerRadius(12) .shadow(radius: 1) - .frame(maxWidth: 300) + .frame(maxWidth: 500) } } } diff --git a/Sources/PopoverContainerView.swift b/Sources/PopoverContainerView.swift index 6363b9b..4b23b48 100644 --- a/Sources/PopoverContainerView.swift +++ b/Sources/PopoverContainerView.swift @@ -37,8 +37,11 @@ struct PopoverContainerView: View { /// Have VoiceOver read the popover view first, before the dismiss button. .accessibility(sortPriority: 1) - /// If a `dismissButtonLabel` was set, show it. - if let dismissButtonLabel = popover.attributes.accessibility.dismissButtonLabel { + /// If VoiceOver is on and a `dismissButtonLabel` was set, show it. + if + UIAccessibility.isVoiceOverRunning, + let dismissButtonLabel = popover.attributes.accessibility.dismissButtonLabel + { Button { popover.dismiss() } label: { diff --git a/Sources/PopoverGestureContainer.swift b/Sources/PopoverGestureContainer.swift index 44c5fc5..d567ae2 100644 --- a/Sources/PopoverGestureContainer.swift +++ b/Sources/PopoverGestureContainer.swift @@ -24,7 +24,7 @@ class PopoverGestureContainer: UIView { override func layoutSubviews() { super.layoutSubviews() - /// Orientation or screen bounds changed. Update popover frames. + /// Orientation or screen bounds changed, so update popover frames. popoverModel.updateFrames() } @@ -32,9 +32,7 @@ class PopoverGestureContainer: UIView { super.didMoveToWindow() /// There might not be a window yet, but that's fine. Just wait until there's actually a window. - guard let window = window else { - return - } + guard let window = window else { return } /// Create the SwiftUI view that contains all the popovers. let popoverContainerView = PopoverContainerView(popoverModel: popoverModel)