@@ -12,33 +12,26 @@ import UIKit
1212public class BottomSheetController : UIViewController {
1313 // Holds the sheet content until the view is loaded
1414 private let content : Content
15- private enum Content {
16- case view( title: String , view: UIView )
17- case controller( _: UIViewController )
18- }
19-
2015 private var shadowSize : CGSize = . zero
2116 private let minimumTopOffset : CGFloat = 44
2217 private let minimumContentHeight : CGFloat = 88
2318 private var topAnchor : NSLayoutConstraint ?
2419 private var indicatorTopAnchor : NSLayoutConstraint ?
2520 private var childHeightAnchor : NSLayoutConstraint ?
2621 private var panGesture : UIPanGestureRecognizer ?
27- internal lazy var lastYOffset : CGFloat = {
28- sheetView. frame. origin. y
29- } ( )
22+ internal lazy var lastYOffset : CGFloat = { sheetView. frame. origin. y } ( )
3023
3124 /// Minimum downward velocity beyond which we interpret a pan gesture as a downward swipe.
3225 public var dismissThresholdVelocity : CGFloat = 1000
33-
34- /// Priorities for various non-required constraints.
35- enum Priorities {
36- static let panGesture = UILayoutPriority ( 775 )
37- static let sheetContentHugging = UILayoutPriority ( 751 )
38- static let sheetCompressionResistanceLow = UILayoutPriority . defaultLow
39- static let sheetCompressionResistanceHigh = UILayoutPriority ( 800 )
40- }
41-
26+
27+ /// Dimmer tap view
28+ let dimmerTapView : UIView = {
29+ let view = UIView ( )
30+ view . accessibilityTraits = . button
31+ view . accessibilityLabel = BottomSheetController . Strings . closeButton . localized
32+ view . accessibilityIdentifier = AccessibilityIdentifiers . dimmerId
33+ return view
34+ } ( )
4235 /// Dimmer view.
4336 let dimmerView = UIView ( )
4437 /// Bottom sheet view.
@@ -133,7 +126,14 @@ public class BottomSheetController: UIViewController {
133126 super. viewDidLoad ( )
134127 build ( )
135128 }
136-
129+
130+ /// :nodoc:
131+ public override func viewDidAppear( _ animated: Bool ) {
132+ super. viewDidAppear ( animated)
133+ // set initial VO focus to the sheet not the dimmer
134+ UIAccessibility . post ( notification: . screenChanged, argument: sheetView)
135+ }
136+
137137 /// :nodoc:
138138 public override func viewDidLayoutSubviews( ) {
139139 super. viewDidLayoutSubviews ( )
@@ -204,13 +204,13 @@ private extension BottomSheetController {
204204 func buildSheet( ) {
205205 buildViews ( )
206206 buildConstraints ( )
207- view. layoutIfNeeded ( )
208207 updateViewAppearance ( )
209208 addGestures ( )
210209 }
211210
212211 func buildViews( ) {
213212 view. addSubview ( dimmerView)
213+ view. addSubview ( dimmerTapView)
214214 view. addSubview ( sheetView)
215215 sheetView. addSubview ( stackView)
216216 stackView. addArrangedSubview ( indicatorContainer)
@@ -220,8 +220,10 @@ private extension BottomSheetController {
220220
221221 func buildConstraints( ) {
222222 dimmerView. constrainEdges ( )
223+ dimmerTapView. constrainEdges ( . notBottom)
224+ dimmerTapView. constrain ( . bottomAnchor, to: sheetView. topAnchor)
225+
223226 sheetView. constrainEdges ( . notTop)
224-
225227 sheetView. constrain (
226228 . topAnchor,
227229 to: view. safeAreaLayoutGuide. topAnchor,
@@ -246,6 +248,7 @@ private extension BottomSheetController {
246248 }
247249
248250 func updateViewAppearance( ) {
251+ dimmerTapView. isAccessibilityElement = appearance. isDismissAllowed
249252 sheetView. layer. cornerRadius = appearance. layout. cornerRadius
250253 updateShadow ( )
251254 dimmerView. backgroundColor = appearance. dimmerColor
@@ -316,7 +319,7 @@ private extension BottomSheetController {
316319 swipeGesture. direction = . down
317320 view. addGestureRecognizer ( swipeGesture)
318321 let tapGesture = UITapGestureRecognizer ( target: self , action: #selector( onDimmerTap) )
319- dimmerView . addGestureRecognizer ( tapGesture)
322+ dimmerTapView . addGestureRecognizer ( tapGesture)
320323 }
321324
322325 func onDismiss( ) {
@@ -344,7 +347,7 @@ private extension BottomSheetController {
344347 }
345348
346349 @objc
347- private func handlePan( _ gesture: UIPanGestureRecognizer ) {
350+ func handlePan( _ gesture: UIPanGestureRecognizer ) {
348351 switch gesture. state {
349352 case . began, . changed:
350353 let translation = gesture. translation ( in: sheetView)
@@ -383,8 +386,7 @@ internal extension BottomSheetController {
383386 onDimmerTap ( sender: UITapGestureRecognizer ( ) )
384387 }
385388
386- @objc
387- @discardableResult
389+ @objc @discardableResult
388390 func simulateDragging( _ gesture: UIPanGestureRecognizer ) -> Bool {
389391 guard isResizable else { return false }
390392 handlePan ( gesture)
0 commit comments