Skip to content

Commit 7aff3f6

Browse files
devkaranCTMark Pospesel
andauthored
[Issue-11] Make dimmer a Close button in VO mode. (#23)
* [CM-1254] Make dimmer a Close button in VO mode. * [CM-1254] Comment updated * [CM-1254] Swiftlint line length error fixed. * [CM-1254] Comments updated. * Update to latest dependencies * Rename files * Test with Xcode 14.3 / iOS 16.4 * Set VO focus to sheet not dimmer * Run Xcode 14.2 for CI/CD --------- Co-authored-by: Mark Pospesel <[email protected]>
1 parent 9712ae3 commit 7aff3f6

File tree

8 files changed

+77
-31
lines changed

8 files changed

+77
-31
lines changed

.github/workflows/run_linter_and_unit_tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ jobs:
2020
- name: Set Xcode version
2121
run: |
2222
ls -l /Applications | grep 'Xcode'
23-
sudo xcode-select -s /Applications/Xcode_14.0.1.app
23+
sudo xcode-select -s /Applications/Xcode_14.2.app
2424
2525
- name: Lint code using SwiftLint
2626
run: swiftlint --strict --reporter github-actions-logging
2727

2828
- name: Build iOS
2929
run: |
30-
xcodebuild -scheme YBottomSheet -sdk iphonesimulator16.0 -destination 'platform=iOS Simulator,name=iPhone 14' build-for-testing
30+
xcodebuild -scheme YBottomSheet -sdk iphonesimulator16.2 -destination 'platform=iOS Simulator,name=iPhone 14' build-for-testing
3131
3232
- name: Run tests iOS
3333
run: |
34-
xcodebuild -scheme YBottomSheet -sdk iphonesimulator16.0 -destination 'platform=iOS Simulator,name=iPhone 14' test-without-building
34+
xcodebuild -scheme YBottomSheet -sdk iphonesimulator16.2 -destination 'platform=iOS Simulator,name=iPhone 14' test-without-building

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ let package = Package(
1717
dependencies: [
1818
.package(
1919
url: "https://github.com/yml-org/YCoreUI.git",
20-
from: "1.5.0"
20+
from: "1.7.0"
2121
),
2222
.package(
2323
url: "https://github.com/yml-org/YMatterType.git",

Sources/YBottomSheet/BottomSheetController.swift

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,26 @@ import UIKit
1212
public 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)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// BottomSheetController+AccessibilityIdentifiers.swift
3+
// YBottomSheet
4+
//
5+
// Created by Dev Karan on 25/04/23.
6+
// Copyright © 2023 Y Media Labs. All rights reserved.
7+
//
8+
9+
extension BottomSheetController {
10+
/// Accessibility Identifiers
11+
enum AccessibilityIdentifiers {
12+
/// Button ID
13+
static let buttonId = "sheet.button.close"
14+
/// Dimmer ID
15+
static let dimmerId = "sheet.dimmer.close"
16+
}
17+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// BottomSheetController+Enums.swift
3+
// YBottomSheet
4+
//
5+
// Created by Dev Karan on 25/04/23.
6+
// Copyright © 2023 Y Media Labs. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import UIKit
11+
12+
internal extension BottomSheetController {
13+
/// Priorities for various non-required constraints.
14+
enum Priorities {
15+
static let panGesture = UILayoutPriority(775)
16+
static let sheetContentHugging = UILayoutPriority(751)
17+
static let sheetCompressionResistanceLow = UILayoutPriority.defaultLow
18+
static let sheetCompressionResistanceHigh = UILayoutPriority(800)
19+
}
20+
21+
/// Types of content that can populate a bottom sheet
22+
enum Content {
23+
case view(title: String, view: UIView)
24+
case controller(_: UIViewController)
25+
}
26+
}

Sources/YBottomSheet/Enums/YBottomSheet+Strings.swift renamed to Sources/YBottomSheet/Enums/BottomSheetController+Strings.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// YBottomSheet+Strings.swift
2+
// BottomSheetController+Strings.swift
33
// YBottomSheet
44
//
55
// Created by Dev Karan on 15/02/23.

Sources/YBottomSheet/SheetHeaderView/SheetHeaderView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ private extension SheetHeaderView {
6666
buildConstraints()
6767
closeButton.addTarget(self, action: #selector(closeButtonAction), for: .touchUpInside)
6868
closeButton.accessibilityLabel = BottomSheetController.Strings.closeButton.localized
69+
closeButton.accessibilityIdentifier = BottomSheetController.AccessibilityIdentifiers.buttonId
6970
}
7071

7172
func buildViews() {

Tests/YBottomSheetTests/Enums/YBottomSheet+StringsTests.swift renamed to Tests/YBottomSheetTests/Enums/BottomSheetController+StringsTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// YBottomSheet+StringsTests.swift
2+
// BottomSheetController+StringsTests.swift
33
// YBottomSheet
44
//
55
// Created by Dev Karan on 15/02/23.
@@ -10,7 +10,7 @@ import XCTest
1010
import YCoreUI
1111
@testable import YBottomSheet
1212

13-
final class YBottomSheetStringsTests: XCTestCase {
13+
final class BottomSheetControllerStringsTests: XCTestCase {
1414
func testLoad() {
1515
BottomSheetController.Strings.allCases.forEach {
1616
// Given a localized string constant

0 commit comments

Comments
 (0)