From cf1f342d72f2d3db1fc938117ad13937872e6633 Mon Sep 17 00:00:00 2001 From: Nicholas Entin Date: Tue, 8 Aug 2023 14:15:12 -0700 Subject: [PATCH] Remove functionality for snapshotting Dynamic Type --- .../project.pbxproj | 8 - .../DynamicTypeViewController.swift | 154 ------------------ .../RootViewController.swift | 1 - .../TextAccessibilityTests.swift | 42 ----- .../UIApplication+DynamicTypeSnapshotting.h | 27 --- .../UIApplication+DynamicTypeSnapshotting.m | 52 ------ .../ObjC/UIView+DynamicTypeSnapshotting.m | 93 ----------- .../include/UIView+DynamicTypeSnapshotting.h | 29 ---- .../SnapshotTesting+Accessibility.swift | 32 ---- .../FBSnapshotTestCase+Accessibility.swift | 57 ------- 10 files changed, 495 deletions(-) delete mode 100644 Example/AccessibilitySnapshot/DynamicTypeViewController.swift delete mode 100644 Example/SnapshotTests/TextAccessibilityTests.swift delete mode 100644 Sources/AccessibilitySnapshot/Core/ObjC/UIApplication+DynamicTypeSnapshotting.h delete mode 100644 Sources/AccessibilitySnapshot/Core/ObjC/UIApplication+DynamicTypeSnapshotting.m delete mode 100644 Sources/AccessibilitySnapshot/Core/ObjC/UIView+DynamicTypeSnapshotting.m delete mode 100644 Sources/AccessibilitySnapshot/Core/ObjC/include/UIView+DynamicTypeSnapshotting.h diff --git a/Example/AccessibilitySnapshot.xcodeproj/project.pbxproj b/Example/AccessibilitySnapshot.xcodeproj/project.pbxproj index 89e1c49c..f10f78b8 100644 --- a/Example/AccessibilitySnapshot.xcodeproj/project.pbxproj +++ b/Example/AccessibilitySnapshot.xcodeproj/project.pbxproj @@ -32,8 +32,6 @@ 3DC2C67C21F46020003184E4 /* HighlightTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DC2C67A21F45FFF003184E4 /* HighlightTests.swift */; }; 3DC488372212A7D4006D1E15 /* ModalAccessibilityViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DC488362212A7D4006D1E15 /* ModalAccessibilityViewController.swift */; }; 3DC488392212B40C006D1E15 /* ModalTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DC488382212B40C006D1E15 /* ModalTests.swift */; }; - 3DC8D04C224734E400E8A03C /* DynamicTypeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DC8D04B224734E400E8A03C /* DynamicTypeViewController.swift */; }; - 3DC8D05B224750F500E8A03C /* TextAccessibilityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DC8D05A224750F500E8A03C /* TextAccessibilityTests.swift */; }; 3DD4D5A4246E051300D4C416 /* AccessibilityHierarchyParserTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DD4D5A1246E051300D4C416 /* AccessibilityHierarchyParserTests.swift */; }; 3DD4D5A5246E051300D4C416 /* UIAccessibilityStatusUtilityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DD4D5A2246E051300D4C416 /* UIAccessibilityStatusUtilityTests.swift */; }; 3DD4D5A6246E051300D4C416 /* UIAccessibilityStatusUtilityObjCTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3DD4D5A3246E051300D4C416 /* UIAccessibilityStatusUtilityObjCTests.m */; }; @@ -108,8 +106,6 @@ 3DC2C67A21F45FFF003184E4 /* HighlightTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HighlightTests.swift; sourceTree = ""; }; 3DC488362212A7D4006D1E15 /* ModalAccessibilityViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModalAccessibilityViewController.swift; sourceTree = ""; }; 3DC488382212B40C006D1E15 /* ModalTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModalTests.swift; sourceTree = ""; }; - 3DC8D04B224734E400E8A03C /* DynamicTypeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DynamicTypeViewController.swift; sourceTree = ""; }; - 3DC8D05A224750F500E8A03C /* TextAccessibilityTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextAccessibilityTests.swift; sourceTree = ""; }; 3DD4D5A0246E051300D4C416 /* UnitTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UnitTests-Bridging-Header.h"; sourceTree = ""; }; 3DD4D5A1246E051300D4C416 /* AccessibilityHierarchyParserTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccessibilityHierarchyParserTests.swift; sourceTree = ""; }; 3DD4D5A2246E051300D4C416 /* UIAccessibilityStatusUtilityTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIAccessibilityStatusUtilityTests.swift; sourceTree = ""; }; @@ -195,7 +191,6 @@ 3DA12A3122405B9E00EB3C33 /* DataTableViewController.swift */, 3DBAC28E2242E7C700EF4D0A /* ListContainerViewController.swift */, 3DBAC2902242F9B200EF4D0A /* LandmarkContainerViewController.swift */, - 3DC8D04B224734E400E8A03C /* DynamicTypeViewController.swift */, 3D3F2E132263E6B900F7608E /* InvertColorsViewController.swift */, 3DDE7FF524C6D6BF00999ABA /* AccessibilityCustomActionsViewController.swift */, ); @@ -312,7 +307,6 @@ 3DF464FB220D4F430048D446 /* SnapshotTestCase.swift */, 1635CE4D251EAC6700907101 /* SnapshotTestingTests.swift */, 3DBEAA5C2223C0CE00FAE61D /* SwitchControlsTests.swift */, - 3DC8D05A224750F500E8A03C /* TextAccessibilityTests.swift */, 3D220A29252AF70600359C1E /* Utilities */, 607FACE91AFB9204008FA782 /* Supporting Files */, ); @@ -605,7 +599,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 3DC8D04C224734E400E8A03C /* DynamicTypeViewController.swift in Sources */, 607FACD81AFB9204008FA782 /* RootViewController.swift in Sources */, 3F8E5DB92535B25000276B32 /* SwiftUIView.swift in Sources */, 3DBEAA5F2223D0DA00FAE61D /* AccessibilityPathViewController.swift in Sources */, @@ -642,7 +635,6 @@ 3DF464FC220D4F430048D446 /* SnapshotTestCase.swift in Sources */, 3D3F2E162263E94D00F7608E /* InvertColorsTests.swift in Sources */, 3D220A2B252AF72900359C1E /* AccessibleContainerView.swift in Sources */, - 3DC8D05B224750F500E8A03C /* TextAccessibilityTests.swift in Sources */, 1635CE4E251EAC6700907101 /* SnapshotTestingTests.swift in Sources */, 3DBEAA5D2223C0CE00FAE61D /* SwitchControlsTests.swift in Sources */, 3DF46500220D5FB00048D446 /* ElementSelectionTests.swift in Sources */, diff --git a/Example/AccessibilitySnapshot/DynamicTypeViewController.swift b/Example/AccessibilitySnapshot/DynamicTypeViewController.swift deleted file mode 100644 index cdf71dba..00000000 --- a/Example/AccessibilitySnapshot/DynamicTypeViewController.swift +++ /dev/null @@ -1,154 +0,0 @@ -// -// Copyright 2019 Square Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -import Paralayout -import UIKit - -final class DynamicTypeViewController: AccessibilityViewController { - - // MARK: - Private Properties - - private let staticLabel: UILabel = .init() - - private let autoAdjustingLabel: UILabel = .init() - - private let staticCustomFontLabel: UILabel = .init() - - private let autoAdjustingCustomFontLabel: DynamicLabel = .init(autoAdjusting: true) - - private let manuallyAdjustingCustomFontLabel: DynamicLabel = .init(autoAdjusting: false) - - private var views: [UIView] { - return [ - staticLabel, - autoAdjustingLabel, - staticCustomFontLabel, - autoAdjustingCustomFontLabel, - manuallyAdjustingCustomFontLabel, - ] - } - - // MARK: - UIViewController - - override func viewDidLoad() { - super.viewDidLoad() - - staticLabel.text = "I Shouldn't Change" - staticLabel.font = UIFont.preferredFont(forTextStyle: .body) - - autoAdjustingLabel.text = "Dynamic Type" - autoAdjustingLabel.font = UIFont.preferredFont(forTextStyle: .body) - autoAdjustingLabel.adjustsFontForContentSizeCategory = true - - staticCustomFontLabel.text = "I Shouldn't Change" - staticCustomFontLabel.font = UIFont(name: "Optima", size: 17)! - - views.forEach(view.addSubview) - } - - override func viewDidLayoutSubviews() { - super.viewDidLayoutSubviews() - - views.forEach { $0.frame.size = $0.sizeThatFits(view.bounds.size) } - - let statusBarHeight = view.window?.windowScene?.statusBarManager?.statusBarFrame.height ?? 0 - - var distributionSpecifiers: [ViewDistributionSpecifying] = [ statusBarHeight.fixed, 1.flexible ] - for subview in views { - distributionSpecifiers.append(subview) - distributionSpecifiers.append(1.flexible) - } - view.applyVerticalSubviewDistribution(distributionSpecifiers) - } - -} - -// MARK: - - -private extension DynamicTypeViewController { - - final class DynamicLabel: UIView { - - // MARK: - Life Cycle - - init(autoAdjusting: Bool) { - super.init(frame: .zero) - - if autoAdjusting { - // There's a bug that causes this not to get automatically scaled after it has been sized to the default - // size (Large) on some devices. See rdar://36243585 for more details. - label.adjustsFontForContentSizeCategory = true - - } else { - notificationObserver = NotificationCenter.default.addObserver( - forName: UIContentSizeCategory.didChangeNotification, - object: nil, - queue: nil, - using: { [unowned self] _ in - self.updateFont() - } - ) - - label.adjustsFontForContentSizeCategory = false - } - - updateFont() - - label.text = "Dynamic Type" - addSubview(label) - } - - @available(*, unavailable) - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - deinit { - if let notificationObserver = notificationObserver { - NotificationCenter.default.removeObserver(notificationObserver) - } - } - - // MARK: - Private Properties - - private let label: UILabel = .init() - - private let regularFont = UIFont(name: "Optima", size: 17)! - - private var notificationObserver: Any? - - // MARK: - UIView - - override func layoutSubviews() { - label.frame = bounds - } - - override func sizeThatFits(_ size: CGSize) -> CGSize { - return label.sizeThatFits(size) - } - - // MARK: - Private Methods - - private func updateFont() { - label.font = UIFontMetrics.default.scaledFont( - for: self.regularFont, - compatibleWith: self.traitCollection - ) - } - - } - -} diff --git a/Example/AccessibilitySnapshot/RootViewController.swift b/Example/AccessibilitySnapshot/RootViewController.swift index 82f8079a..f9676fa1 100644 --- a/Example/AccessibilitySnapshot/RootViewController.swift +++ b/Example/AccessibilitySnapshot/RootViewController.swift @@ -52,7 +52,6 @@ final class RootViewController: UITableViewController { ("Accessibility Paths", { _ in return AccessibilityPathViewController() }), ("Accessibility Activation Point", { _ in return ActivationPointViewController() }), ("Accessibility Custom Actions", { _ in return AccessibilityCustomActionsViewController() }), - ("Dynamic Type", { _ in return DynamicTypeViewController() }), ("Data Table", { presentingViewController in return DataTableViewController.makeConfigurationSelectionViewController( presentingViewController: presentingViewController diff --git a/Example/SnapshotTests/TextAccessibilityTests.swift b/Example/SnapshotTests/TextAccessibilityTests.swift deleted file mode 100644 index 7a34c5e7..00000000 --- a/Example/SnapshotTests/TextAccessibilityTests.swift +++ /dev/null @@ -1,42 +0,0 @@ -// -// Copyright 2019 Square Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -import FBSnapshotTestCase - -@testable import AccessibilitySnapshotDemo - -// This class is currently testing functionality that has not yet been added to the public API. Once it has been -// completed and made public, this can be changed back to a standard import. -@testable import AccessibilitySnapshot - -final class TextAccessibilityTests: SnapshotTestCase { - - func testDynamicType() { - let viewController = DynamicTypeViewController() - viewController.view.frame = UIScreen.main.bounds - - FBSnapshotVerifyView(viewController.view) - - SnapshotVerify(viewController.view, at: .extraSmall, identifier: "XS") - SnapshotVerify(viewController.view, at: .extraExtraExtraLarge, identifier: "XXXL") - SnapshotVerify(viewController.view, at: .accessibilityExtraExtraExtraLarge, identifier: "AXXXL") - - // This has the same (empty) identifier as the initial snapshot, so it will use the same - // image to compare. This is meant to test that the view is restored to its initial state. - FBSnapshotVerifyView(viewController.view) - } - -} diff --git a/Sources/AccessibilitySnapshot/Core/ObjC/UIApplication+DynamicTypeSnapshotting.h b/Sources/AccessibilitySnapshot/Core/ObjC/UIApplication+DynamicTypeSnapshotting.h deleted file mode 100644 index c256f32f..00000000 --- a/Sources/AccessibilitySnapshot/Core/ObjC/UIApplication+DynamicTypeSnapshotting.h +++ /dev/null @@ -1,27 +0,0 @@ -// -// Copyright 2019 Square Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#import - -NS_ASSUME_NONNULL_BEGIN - -@interface UIApplication (DynamicTypeSnapshotting) - -+ (void)AS_setPreferredContentSizeCategoryOverride:(nullable UIContentSizeCategory)contentSizeCategory; - -@end - -NS_ASSUME_NONNULL_END diff --git a/Sources/AccessibilitySnapshot/Core/ObjC/UIApplication+DynamicTypeSnapshotting.m b/Sources/AccessibilitySnapshot/Core/ObjC/UIApplication+DynamicTypeSnapshotting.m deleted file mode 100644 index 63e67b22..00000000 --- a/Sources/AccessibilitySnapshot/Core/ObjC/UIApplication+DynamicTypeSnapshotting.m +++ /dev/null @@ -1,52 +0,0 @@ -// -// Copyright 2019 Square Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#import "UIApplication+DynamicTypeSnapshotting.h" - -#import - -@implementation UIApplication (DynamicTypeSnapshotting) - -static UIContentSizeCategory contentSizeCategoryOverride = nil; - -+ (void)load; -{ - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - Class class = [self class]; - - SEL originalSelector = @selector(preferredContentSizeCategory); - Method originalMethod = class_getInstanceMethod(class, originalSelector); - - SEL swizzledSelector = @selector(AS_preferredContentSizeCategory); - Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector); - - method_exchangeImplementations(originalMethod, swizzledMethod); - }); -} - -+ (void)AS_setPreferredContentSizeCategoryOverride:(nullable UIContentSizeCategory)contentSizeCategory; -{ - contentSizeCategoryOverride = contentSizeCategory; -} - -- (UIContentSizeCategory)AS_preferredContentSizeCategory; -{ - UIContentSizeCategory contentSizeCategory = [self AS_preferredContentSizeCategory]; - return contentSizeCategoryOverride ?: contentSizeCategory; -} - -@end diff --git a/Sources/AccessibilitySnapshot/Core/ObjC/UIView+DynamicTypeSnapshotting.m b/Sources/AccessibilitySnapshot/Core/ObjC/UIView+DynamicTypeSnapshotting.m deleted file mode 100644 index 8f63bcc6..00000000 --- a/Sources/AccessibilitySnapshot/Core/ObjC/UIView+DynamicTypeSnapshotting.m +++ /dev/null @@ -1,93 +0,0 @@ -// -// Copyright 2019 Square Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#import "include/UIView+DynamicTypeSnapshotting.h" - -#import - -#import "UIApplication+DynamicTypeSnapshotting.h" - -@protocol UIViewTraitProcessing - -- (void)_processDidChangeRecursivelyFromOldTraits:(UITraitCollection *)oldTraits toCurrentTraits:(UITraitCollection *)currentTraits forceNotification:(BOOL)forceNotification; - -@end - -@implementation UIView (DynamicTypeSnapshotting) - -static UIContentSizeCategory contentSizeCategoryOverride = nil; - -+ (void)load; -{ - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - Class class = [self class]; - - SEL originalSelector = @selector(traitCollection); - Method originalMethod = class_getInstanceMethod(class, originalSelector); - - SEL swizzledSelector = @selector(AS_traitCollection); - Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector); - - method_exchangeImplementations(originalMethod, swizzledMethod); - }); -} - -+ (void)AS_setPreferredContentSizeCategoryOverride:(nullable UIContentSizeCategory)contentSizeCategory; -{ - contentSizeCategoryOverride = contentSizeCategory; - - [UIApplication AS_setPreferredContentSizeCategoryOverride:contentSizeCategory]; -} - -- (UITraitCollection *)AS_traitCollection; -{ - __block UITraitCollection *traitCollection; - - if (@available(iOS 15, *)) { - // TODO: On iOS 15+ simulators there is a main queue assertion crash. - // Investigation led us to find there is some UIKit internal code calling traitCollection - // on a background thread which then causes a UIKit main thread exception (since traitCollection needs to be accessed from main). - // We have not been able to find a solution for it besides this hack to force the call to happen on the main thread. - if ([NSThread isMainThread]) { - traitCollection = [self AS_traitCollection]; - } else { - dispatch_sync(dispatch_get_main_queue(), ^{ - traitCollection = [self AS_traitCollection]; - }); - } - } else { - traitCollection = [self AS_traitCollection]; - } - - if (contentSizeCategoryOverride != nil) { - UITraitCollection *contentSizeCategoryTraitCollection = [UITraitCollection traitCollectionWithPreferredContentSizeCategory:contentSizeCategoryOverride]; - return [UITraitCollection traitCollectionWithTraitsFromCollections:@[traitCollection, contentSizeCategoryTraitCollection]]; - - } else { - return traitCollection; - } -} - -- (void)AS_processChangeFromTraits:(UITraitCollection *)oldTraits; -{ - SEL selector = @selector(_processDidChangeRecursivelyFromOldTraits:toCurrentTraits:forceNotification:); - typedef void (*ProcessChangeMethod)(id, SEL, UITraitCollection *, UITraitCollection *, BOOL); - ProcessChangeMethod processChange = (ProcessChangeMethod)[self methodForSelector:selector]; - processChange(self, selector, oldTraits, [self traitCollection], YES); -} - -@end diff --git a/Sources/AccessibilitySnapshot/Core/ObjC/include/UIView+DynamicTypeSnapshotting.h b/Sources/AccessibilitySnapshot/Core/ObjC/include/UIView+DynamicTypeSnapshotting.h deleted file mode 100644 index 040e1c8b..00000000 --- a/Sources/AccessibilitySnapshot/Core/ObjC/include/UIView+DynamicTypeSnapshotting.h +++ /dev/null @@ -1,29 +0,0 @@ -// -// Copyright 2019 Square Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#import - -NS_ASSUME_NONNULL_BEGIN - -@interface UIView (DynamicTypeSnapshotting) - -- (void)AS_processChangeFromTraits:(UITraitCollection *)oldTraits NS_SWIFT_NAME(processChange(from:)); - -+ (void)AS_setPreferredContentSizeCategoryOverride:(nullable UIContentSizeCategory)contentSizeCategory NS_SWIFT_NAME(setPreferredContentSizeCategoryOverride(_:)); - -@end - -NS_ASSUME_NONNULL_END diff --git a/Sources/AccessibilitySnapshot/SnapshotTesting/SnapshotTesting+Accessibility.swift b/Sources/AccessibilitySnapshot/SnapshotTesting/SnapshotTesting+Accessibility.swift index 2758e6ef..346af417 100644 --- a/Sources/AccessibilitySnapshot/SnapshotTesting/SnapshotTesting+Accessibility.swift +++ b/Sources/AccessibilitySnapshot/SnapshotTesting/SnapshotTesting+Accessibility.swift @@ -94,20 +94,6 @@ extension Snapshotting where Value == UIView, Format == UIImage { } } - /// Snapshots the current view using the specified content size category to test Dynamic Type. - /// - /// This method has been marked internal since it is still under development. Once it has been completed, it should - /// be made `public`. - /// - /// - parameter contentSizeCategory: The content size category to use in the snapshot - static func image( - at contentSizeCategory: UIContentSizeCategory - ) -> Snapshotting { - return Snapshotting.image( - traits: .init(preferredContentSizeCategory: contentSizeCategory) - ) - } - /// Snapshots the current view simulating the way it will appear with Smart Invert Colors enabled. public static var imageWithSmartInvert: Snapshotting { func postNotification() { @@ -198,24 +184,6 @@ extension Snapshotting where Value == UIViewController, Format == UIImage { } } - /// Snapshots the current view using the specified content size category to test Dynamic Type. - /// - /// This method has been marked internal since it is still under development. Once it has been completed, it should - /// be made `public`. - /// - /// - parameter contentSizeCategory: The content size category to use in the snapshot - static func image( - at contentSizeCategory: UIContentSizeCategory - ) -> Snapshotting { - return Snapshotting - .image( - traits: .init(preferredContentSizeCategory: contentSizeCategory) - ) - .pullback { viewController in - viewController.view - } - } - /// Snapshots the current view simulating the way it will appear with Smart Invert Colors enabled. public static var imageWithSmartInvert: Snapshotting { return Snapshotting.imageWithSmartInvert.pullback { viewController in diff --git a/Sources/AccessibilitySnapshot/iOSSnapshotTestCase/Swift/FBSnapshotTestCase+Accessibility.swift b/Sources/AccessibilitySnapshot/iOSSnapshotTestCase/Swift/FBSnapshotTestCase+Accessibility.swift index 0ab493dd..5758337b 100644 --- a/Sources/AccessibilitySnapshot/iOSSnapshotTestCase/Swift/FBSnapshotTestCase+Accessibility.swift +++ b/Sources/AccessibilitySnapshot/iOSSnapshotTestCase/Swift/FBSnapshotTestCase+Accessibility.swift @@ -89,63 +89,6 @@ extension FBSnapshotTestCase { FBSnapshotVerifyView(containerView, identifier: identifier, suffixes: suffixes, file: file, line: line) } - /// Snapshots the `view` using the specified content size category to test Dynamic Type. - /// - /// When `recordMode` is true, records a snapshot of the view. When `recordMode` is false, performs a comparison with the - /// existing snapshot. - /// - /// In preparation for beta release, this method has been marked internal since it is still under development. Once - /// it has been completed, it should be made `public`. - /// - /// - parameter view: The view that will be snapshotted. - /// - parameter contentSizeCategory: The content size category to use in the snapshot. - /// - parameter identifier: An optional identifier included in the snapshot name, for use when there are multiple snapshot tests - /// in a given test method. Defaults to no identifier. - /// - parameter suffixes: NSOrderedSet object containing strings that are appended to the reference images directory. - /// Defaults to `FBSnapshotTestCaseDefaultSuffixes()`. - /// - parameter file: The file in which the test result should be attributed. - /// - parameter line: The line in which the test result should be attributed. - func SnapshotVerify( - _ view: UIView, - at contentSizeCategory: UIContentSizeCategory, - identifier: String = "", - suffixes: NSOrderedSet = FBSnapshotTestCaseDefaultSuffixes(), - file: StaticString = #file, - line: UInt = #line - ) { - func postNotification() { - NotificationCenter.default.post( - name: UIContentSizeCategory.didChangeNotification, - object: UIScreen.main, - userInfo: [ - UIContentSizeCategory.newValueUserInfoKey: UIApplication.shared.preferredContentSizeCategory, - "UIContentSizeCategoryTextLegibilityEnabledKey": false, - ] - ) - } - - let originalTraitCollection = view.traitCollection - UIView.setPreferredContentSizeCategoryOverride(contentSizeCategory) - view.processChange(from: originalTraitCollection) - postNotification() - - // TODO: This doesn't quite match what actually happens when the Dynamic Type setting changes. There are a few different ways - // to change Dynamic Type (via the Accessibility Inspector in a simulator, exiting the app and changing the size in - // Settings.app, or via a control in Control Center on a device) and they each hit a slightly different path when it comes to - // resizing views. We should probably try to match the Control Center path since that is the most dynamic way actual users - // will be able to change the text size in production. - view.setNeedsLayout() - - FBSnapshotVerifyView(view, identifier: identifier, suffixes: suffixes, file: file, line: line) - - // Restore the original content size category. - let overriddenTraitCollection = view.traitCollection - UIView.setPreferredContentSizeCategoryOverride(nil) - view.processChange(from: overriddenTraitCollection) - postNotification() - view.setNeedsLayout() - } - /// Snapshots the `view` simulating the way it will appear with Smart Invert Colors enabled. /// /// When `recordMode` is true, records a snapshot of the view. When `recordMode` is false, performs a comparison with the