From b7faefaf9e887519bcec50444092de1b16676a86 Mon Sep 17 00:00:00 2001 From: Nick Entin Date: Sun, 4 Oct 2020 20:45:42 -0700 Subject: [PATCH] Remove unnecessary availability checks for iOS 11 --- .../AccessibilityHierarchyParser.swift | 56 +++++++------------ .../UIView+InvertColorsSnapshotting.swift | 2 - .../SnapshotTesting+Accessibility.swift | 2 - .../FBSnapshotTestCase+Accessibility.swift | 1 - .../FBSnapshotTestCase+ObjCSupport.swift | 1 - .../FBSnapshotTestCase_Accessibility.h | 24 ++++---- .../DataTableViewController.swift | 5 -- .../DynamicTypeViewController.swift | 14 ++--- .../InvertColorsViewController.swift | 1 - .../LandmarkContainerViewController.swift | 2 - .../ListContainerViewController.swift | 2 - .../RootViewController.swift | 19 +++---- .../AccessibilityContainersTests.swift | 7 --- Example/SnapshotTests/InvertColorsTests.swift | 1 - Example/SnapshotTests/ObjectiveCTests.m | 16 +++--- .../SnapshotTests/SnapshotTestingTests.swift | 5 -- 16 files changed, 47 insertions(+), 111 deletions(-) diff --git a/AccessibilitySnapshot/Core/Classes/AccessibilityHierarchyParser.swift b/AccessibilitySnapshot/Core/Classes/AccessibilityHierarchyParser.swift index 918064d1..0d5c0968 100644 --- a/AccessibilitySnapshot/Core/Classes/AccessibilityHierarchyParser.swift +++ b/AccessibilitySnapshot/Core/Classes/AccessibilityHierarchyParser.swift @@ -218,7 +218,6 @@ public final class AccessibilityHierarchyParser { case accessibilityContainer(NSObject) - @available(iOS 11, *) case dataTable(UIAccessibilityContainerDataTable) } @@ -437,26 +436,24 @@ public final class AccessibilityHierarchyParser { ) } - if #available(iOS 11, *) { - if container.accessibilityContainerType == .list { - if elementIndex == 0 { - return .listStart - } else if elementIndex == container.accessibilityElementCount() - 1 { - return .listEnd - } + if container.accessibilityContainerType == .list { + if elementIndex == 0 { + return .listStart + } else if elementIndex == container.accessibilityElementCount() - 1 { + return .listEnd } + } - if container.accessibilityContainerType == .landmark { - if elementIndex == 0 { - return .landmarkStart - } else if elementIndex == container.accessibilityElementCount() - 1 { - return .landmarkEnd - } + if container.accessibilityContainerType == .landmark { + if elementIndex == 0 { + return .landmarkStart + } else if elementIndex == container.accessibilityElementCount() - 1 { + return .landmarkEnd } } case let .dataTable(dataTable): - if #available(iOS 11, *), let cell = element as? UIAccessibilityContainerDataTableCell { + if let cell = element as? UIAccessibilityContainerDataTableCell { let rowRange = cell.accessibilityRowRange() let row = rowRange.location @@ -631,32 +628,19 @@ private extension NSObject { /// Some elements can provide context in multiple roles, which can be differentiated using the /// `providedContextAsSuperview()` and `providedContextAsContainer()` methods. private var providesContext: Bool { - if #available(iOS 11, *) { - if self is UIAccessibilityContainerDataTable && accessibilityContainerType == .dataTable { - return true - } - - if accessibilityContainerType == .list { - return true - } - - if accessibilityContainerType == .landmark { - return true - } - } - return self is UISegmentedControl || self is UITabBar || accessibilityTraits.contains(.tabBar) + || accessibilityContainerType == .list + || accessibilityContainerType == .landmark + || (self is UIAccessibilityContainerDataTable && accessibilityContainerType == .dataTable) } /// The form of context provider the object acts as for elements beneath it in the hierarchy when the elements /// beneath it are part of the view hierarchy and the object is not an accessibility container. private func providedContextAsSuperview() -> AccessibilityHierarchyParser.ContextProvider { - if #available(iOS 11, *) { - if accessibilityContainerType == .dataTable, let self = self as? UIAccessibilityContainerDataTable { - return .dataTable(self) - } + if accessibilityContainerType == .dataTable, let self = self as? UIAccessibilityContainerDataTable { + return .dataTable(self) } return .superview(self as! UIView) @@ -665,10 +649,8 @@ private extension NSObject { /// The form of context provider the object acts as for elements beneath it in the hierarchy when the object is /// being used as an accessibility container. private func providedContextAsContainer() -> AccessibilityHierarchyParser.ContextProvider { - if #available(iOS 11, *) { - if accessibilityContainerType == .dataTable, let self = self as? UIAccessibilityContainerDataTable { - return .dataTable(self) - } + if accessibilityContainerType == .dataTable, let self = self as? UIAccessibilityContainerDataTable { + return .dataTable(self) } return .accessibilityContainer(self) diff --git a/AccessibilitySnapshot/Core/Classes/UIView+InvertColorsSnapshotting.swift b/AccessibilitySnapshot/Core/Classes/UIView+InvertColorsSnapshotting.swift index 6e5d3a19..10e700c2 100644 --- a/AccessibilitySnapshot/Core/Classes/UIView+InvertColorsSnapshotting.swift +++ b/AccessibilitySnapshot/Core/Classes/UIView+InvertColorsSnapshotting.swift @@ -22,7 +22,6 @@ extension UIView { // MARK: - Public Methods - @available(iOS 11, *) public func drawHierarchyWithInvertedColors(in rect: CGRect, using context: UIGraphicsImageRendererContext) { if accessibilityIgnoresInvertColors { drawHierarchy(in: rect, afterScreenUpdates: false) @@ -87,7 +86,6 @@ extension UIView { // MARK: - Private Properties - @available(iOS 11, *) private var hasSubviewInHierarchyThatIgnoresInvertColors: Bool { if accessibilityIgnoresInvertColors { return true diff --git a/AccessibilitySnapshot/SnapshotTesting/Classes/SnapshotTesting+Accessibility.swift b/AccessibilitySnapshot/SnapshotTesting/Classes/SnapshotTesting+Accessibility.swift index f0bc69bc..ebca1b63 100644 --- a/AccessibilitySnapshot/SnapshotTesting/Classes/SnapshotTesting+Accessibility.swift +++ b/AccessibilitySnapshot/SnapshotTesting/Classes/SnapshotTesting+Accessibility.swift @@ -83,7 +83,6 @@ extension Snapshotting where Value == UIView, Format == UIImage { } /// Snapshots the current view simulating the way it will appear with Smart Invert Colors enabled. - @available(iOS 11, *) public static var imageWithSmartInvert: Snapshotting { func postNotification() { NotificationCenter.default.post( @@ -192,7 +191,6 @@ extension Snapshotting where Value == UIViewController, Format == UIImage { } /// Snapshots the current view simulating the way it will appear with Smart Invert Colors enabled. - @available(iOS 11, *) public static var imageWithSmartInvert: Snapshotting { return Snapshotting.imageWithSmartInvert.pullback { viewController in viewController.view diff --git a/AccessibilitySnapshot/iOSSnapshotTestCase/Classes/FBSnapshotTestCase+Accessibility.swift b/AccessibilitySnapshot/iOSSnapshotTestCase/Classes/FBSnapshotTestCase+Accessibility.swift index 5f2414f9..dfb89275 100644 --- a/AccessibilitySnapshot/iOSSnapshotTestCase/Classes/FBSnapshotTestCase+Accessibility.swift +++ b/AccessibilitySnapshot/iOSSnapshotTestCase/Classes/FBSnapshotTestCase+Accessibility.swift @@ -135,7 +135,6 @@ extension FBSnapshotTestCase { /// in a given test method. Defaults to no identifier. /// - parameter file: The file in which the test result should be attributed. /// - parameter line: The line in which the test result should be attributed. - @available(iOS 11, *) public func SnapshotVerifyWithInvertedColors( _ view: UIView, identifier: String = "", diff --git a/AccessibilitySnapshot/iOSSnapshotTestCase/Classes/FBSnapshotTestCase+ObjCSupport.swift b/AccessibilitySnapshot/iOSSnapshotTestCase/Classes/FBSnapshotTestCase+ObjCSupport.swift index 9ec6bb83..a74a1595 100644 --- a/AccessibilitySnapshot/iOSSnapshotTestCase/Classes/FBSnapshotTestCase+ObjCSupport.swift +++ b/AccessibilitySnapshot/iOSSnapshotTestCase/Classes/FBSnapshotTestCase+ObjCSupport.swift @@ -78,7 +78,6 @@ extension FBSnapshotTestCase { ) } - @available(iOS 11, *) @objc(snapshotVerifyWithInvertedColors:identifier:) private func snapshotVerifyWithInvertedColors(_ view: UIView, identifier: String) -> String? { func postNotification() { diff --git a/AccessibilitySnapshot/iOSSnapshotTestCase/Classes/FBSnapshotTestCase_Accessibility.h b/AccessibilitySnapshot/iOSSnapshotTestCase/Classes/FBSnapshotTestCase_Accessibility.h index f3c50fa1..b4c451ec 100644 --- a/AccessibilitySnapshot/iOSSnapshotTestCase/Classes/FBSnapshotTestCase_Accessibility.h +++ b/AccessibilitySnapshot/iOSSnapshotTestCase/Classes/FBSnapshotTestCase_Accessibility.h @@ -50,20 +50,16 @@ #define SnapshotVerifyWithInvertedColors(view__, identifier__)\ {\ - if (@available(iOS 11.0, *)) {\ - _Pragma("clang diagnostic push")\ - _Pragma("clang diagnostic ignored \"-Wundeclared-selector\"")\ - SEL selector = @selector(snapshotVerifyWithInvertedColors:identifier:);\ - _Pragma("clang diagnostic pop")\ - typedef NSString * (*SnapshotMethod)(id, SEL, UIView *, NSString *);\ - SnapshotMethod snapshotVerifyWithInvertedColors = (SnapshotMethod)[self methodForSelector:selector];\ - NSString *errorDescription = snapshotVerifyWithInvertedColors(self, selector, view__, identifier__ ?: @"");\ - if (errorDescription == nil) {\ - XCTAssertTrue(YES);\ - } else {\ - XCTFail("%@", errorDescription);\ - }\ + _Pragma("clang diagnostic push")\ + _Pragma("clang diagnostic ignored \"-Wundeclared-selector\"")\ + SEL selector = @selector(snapshotVerifyWithInvertedColors:identifier:);\ + _Pragma("clang diagnostic pop")\ + typedef NSString * (*SnapshotMethod)(id, SEL, UIView *, NSString *);\ + SnapshotMethod snapshotVerifyWithInvertedColors = (SnapshotMethod)[self methodForSelector:selector];\ + NSString *errorDescription = snapshotVerifyWithInvertedColors(self, selector, view__, identifier__ ?: @"");\ + if (errorDescription == nil) {\ + XCTAssertTrue(YES);\ } else {\ - XCTFail(@"Snapshot testing with inverted colors is only available on iOS 11 and greater.");\ + XCTFail("%@", errorDescription);\ }\ } diff --git a/Example/AccessibilitySnapshot/DataTableViewController.swift b/Example/AccessibilitySnapshot/DataTableViewController.swift index 3feb3a77..a56d4d83 100644 --- a/Example/AccessibilitySnapshot/DataTableViewController.swift +++ b/Example/AccessibilitySnapshot/DataTableViewController.swift @@ -17,7 +17,6 @@ import Paralayout import UIKit -@available(iOS 11, *) final class DataTableViewController: AccessibilityViewController { // MARK: - Public Types @@ -72,7 +71,6 @@ final class DataTableViewController: AccessibilityViewController { // MARK: - -@available(iOS 11, *) private extension DataTableViewController { class View: UIView, UIAccessibilityContainerDataTable { @@ -203,7 +201,6 @@ private extension DataTableViewController { // MARK: - -@available(iOS 11, *) private extension DataTableViewController { final class ViewWithHeaders: View { @@ -262,7 +259,6 @@ private extension DataTableViewController { // MARK: - -@available(iOS 11, *) private extension DataTableViewController { final class Cell: UIView, UIAccessibilityContainerDataTableCell { @@ -331,7 +327,6 @@ private extension DataTableViewController { // MARK: - -@available(iOS 11, *) extension DataTableViewController { static func makeConfigurationSelectionViewController( diff --git a/Example/AccessibilitySnapshot/DynamicTypeViewController.swift b/Example/AccessibilitySnapshot/DynamicTypeViewController.swift index 0086bc93..70299632 100644 --- a/Example/AccessibilitySnapshot/DynamicTypeViewController.swift +++ b/Example/AccessibilitySnapshot/DynamicTypeViewController.swift @@ -143,16 +143,10 @@ private extension DynamicTypeViewController { // MARK: - Private Methods private func updateFont() { - if #available(iOS 11, *) { - label.font = UIFontMetrics.default.scaledFont( - for: self.regularFont, - compatibleWith: self.traitCollection - ) - - } else { - let fontSize = UIFont.preferredFont(forTextStyle: .body).pointSize - label.font = regularFont.withSize(fontSize) - } + label.font = UIFontMetrics.default.scaledFont( + for: self.regularFont, + compatibleWith: self.traitCollection + ) } } diff --git a/Example/AccessibilitySnapshot/InvertColorsViewController.swift b/Example/AccessibilitySnapshot/InvertColorsViewController.swift index a73f84b4..adfe271f 100644 --- a/Example/AccessibilitySnapshot/InvertColorsViewController.swift +++ b/Example/AccessibilitySnapshot/InvertColorsViewController.swift @@ -17,7 +17,6 @@ import Paralayout import UIKit -@available(iOS 11, *) final class InvertColorsViewController: AccessibilityViewController { // MARK: - Private Properties diff --git a/Example/AccessibilitySnapshot/LandmarkContainerViewController.swift b/Example/AccessibilitySnapshot/LandmarkContainerViewController.swift index 812e463e..f17ecd9f 100644 --- a/Example/AccessibilitySnapshot/LandmarkContainerViewController.swift +++ b/Example/AccessibilitySnapshot/LandmarkContainerViewController.swift @@ -17,7 +17,6 @@ import Paralayout import UIKit -@available(iOS 11, *) final class LandmarkContainerViewController: AccessibilityViewController { // MARK: - UIViewController @@ -30,7 +29,6 @@ final class LandmarkContainerViewController: AccessibilityViewController { // MARK: - -@available(iOS 11, *) private extension LandmarkContainerViewController { final class View: UIView { diff --git a/Example/AccessibilitySnapshot/ListContainerViewController.swift b/Example/AccessibilitySnapshot/ListContainerViewController.swift index 6df97dcc..f978fe89 100644 --- a/Example/AccessibilitySnapshot/ListContainerViewController.swift +++ b/Example/AccessibilitySnapshot/ListContainerViewController.swift @@ -17,7 +17,6 @@ import Paralayout import UIKit -@available(iOS 11, *) final class ListContainerViewController: AccessibilityViewController { // MARK: - UIViewController @@ -30,7 +29,6 @@ final class ListContainerViewController: AccessibilityViewController { // MARK: - -@available(iOS 11, *) private extension ListContainerViewController { final class View: UIView { diff --git a/Example/AccessibilitySnapshot/RootViewController.swift b/Example/AccessibilitySnapshot/RootViewController.swift index 4dc20bec..e65bd66d 100644 --- a/Example/AccessibilitySnapshot/RootViewController.swift +++ b/Example/AccessibilitySnapshot/RootViewController.swift @@ -25,7 +25,7 @@ final class RootViewController: UITableViewController { // MARK: - Life Cycle init() { - var accessibilityScreens = [ + self.accessibilityScreens = [ ("View Accessibility Properties", { _ in return ViewAccessibilityPropertiesViewController() }), ("Label Accessibility Properties", { _ in return LabelAccessibilityPropertiesViewController() }), ("Button Accessibility Traits", { _ in return ButtonAccessibilityTraitsViewController() }), @@ -53,20 +53,15 @@ final class RootViewController: UITableViewController { ("Accessibility Activation Point", { _ in return ActivationPointViewController() }), ("Accessibility Custom Actions", { _ in return AccessibilityCustomActionsViewController() }), ("Dynamic Type", { _ in return DynamicTypeViewController() }), - ] - - if #available(iOS 11, *) { - accessibilityScreens.append(("Data Table", { presentingViewController in + ("Data Table", { presentingViewController in return DataTableViewController.makeConfigurationSelectionViewController( presentingViewController: presentingViewController ) - })) - accessibilityScreens.append(("List Container", { _ in return ListContainerViewController() })) - accessibilityScreens.append(("Landmark Container", { _ in return LandmarkContainerViewController() })) - accessibilityScreens.append(("Invert Colors", { _ in return InvertColorsViewController() })) - } - - self.accessibilityScreens = accessibilityScreens + }), + ("List Container", { _ in return ListContainerViewController() }), + ("Landmark Container", { _ in return LandmarkContainerViewController() }), + ("Invert Colors", { _ in return InvertColorsViewController() }), + ] super.init(nibName: nil, bundle: nil) } diff --git a/Example/SnapshotTests/AccessibilityContainersTests.swift b/Example/SnapshotTests/AccessibilityContainersTests.swift index 2ed8836d..ee80459a 100644 --- a/Example/SnapshotTests/AccessibilityContainersTests.swift +++ b/Example/SnapshotTests/AccessibilityContainersTests.swift @@ -24,21 +24,18 @@ final class AccessibilityContainersTests: SnapshotTestCase { // This test technically doesn't match VoiceOver behavior. VoiceOver says the // last cell is element "5 of 1," which seems like a bug in VoiceOver that isn't // easy to replicate in the snapshots. - @available(iOS 11, *) func testDataTable() { let viewController = DataTableViewController(configuration: .basic) viewController.view.frame = UIScreen.main.bounds SnapshotVerifyAccessibility(viewController.view) } - @available(iOS 11, *) func testDataTableWithHeaders() { let viewController = DataTableViewController(configuration: .withHeaders) viewController.view.frame = UIScreen.main.bounds SnapshotVerifyAccessibility(viewController.view) } - @available(iOS 11, *) func testDataTableWithUndefinedRows() { let viewController = DataTableViewController(configuration: .undefinedRows) viewController.view.frame = UIScreen.main.bounds @@ -48,7 +45,6 @@ final class AccessibilityContainersTests: SnapshotTestCase { // This test is disabled because it doesn't match VoiceOver behavior. The handling // of cells with `NSNotFound` columns seems to use a similar scanning algorithm to // figure out which cell is the beginning of each row. - @available(iOS 11, *) func testDataTableWithUndefinedColumns() { let viewController = DataTableViewController(configuration: .undefinedColumns) viewController.view.frame = UIScreen.main.bounds @@ -57,21 +53,18 @@ final class AccessibilityContainersTests: SnapshotTestCase { // This test is disabled because it doesn't match VoiceOver behavior. See comment // above on the handling of cells with `NSNotFound` columns. - @available(iOS 11, *) func testDataTableWithUndefinedRowsAndColumns() { let viewController = DataTableViewController(configuration: .undefinedRowsAndColumns) viewController.view.frame = UIScreen.main.bounds SnapshotVerifyAccessibility(viewController.view) } - @available(iOS 11, *) func testList() { let viewController = ListContainerViewController() viewController.view.frame = UIScreen.main.bounds SnapshotVerifyAccessibility(viewController.view) } - @available(iOS 11, *) func testLandmark() { let viewController = LandmarkContainerViewController() viewController.view.frame = UIScreen.main.bounds diff --git a/Example/SnapshotTests/InvertColorsTests.swift b/Example/SnapshotTests/InvertColorsTests.swift index 9afa305c..b5a6e9df 100644 --- a/Example/SnapshotTests/InvertColorsTests.swift +++ b/Example/SnapshotTests/InvertColorsTests.swift @@ -21,7 +21,6 @@ import FBSnapshotTestCase final class InvertColorsTests: SnapshotTestCase { - @available(iOS 11, *) func testInvertColors() { let viewController = InvertColorsViewController() viewController.view.frame = UIScreen.main.bounds diff --git a/Example/SnapshotTests/ObjectiveCTests.m b/Example/SnapshotTests/ObjectiveCTests.m index 6f9a8de4..daed4d8f 100644 --- a/Example/SnapshotTests/ObjectiveCTests.m +++ b/Example/SnapshotTests/ObjectiveCTests.m @@ -128,18 +128,16 @@ - (void)testSimpleViewWithColorSnapshots; - (void)testViewWithInvertedColors; { - if (@available(iOS 11.0, *)) { - UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; - [view setBackgroundColor:[UIColor redColor]]; + UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; + [view setBackgroundColor:[UIColor redColor]]; - UIView *subview = [[UIView alloc] initWithFrame:CGRectMake(25, 25, 50, 50)]; - [subview setBackgroundColor:[UIColor greenColor]]; + UIView *subview = [[UIView alloc] initWithFrame:CGRectMake(25, 25, 50, 50)]; + [subview setBackgroundColor:[UIColor greenColor]]; - [subview setAccessibilityIgnoresInvertColors:YES]; - [view addSubview:subview]; + [subview setAccessibilityIgnoresInvertColors:YES]; + [view addSubview:subview]; - SnapshotVerifyWithInvertedColors(view, nil); - } + SnapshotVerifyWithInvertedColors(view, nil); } @end diff --git a/Example/SnapshotTests/SnapshotTestingTests.swift b/Example/SnapshotTests/SnapshotTestingTests.swift index cfa5b803..2cb40e2d 100644 --- a/Example/SnapshotTests/SnapshotTestingTests.swift +++ b/Example/SnapshotTests/SnapshotTestingTests.swift @@ -117,11 +117,6 @@ final class SnapshotTestingTests: XCTestCase { } func testInvertColors() { - guard #available(iOS 11, *) else { - // Snapshotting with inverted colors is only available on iOS 11+. - return - } - let viewController = InvertColorsViewController() viewController.view.frame = UIScreen.main.bounds assertSnapshot(matching: viewController, as: .imageWithSmartInvert, named: nameForDevice())