Skip to content

Commit 9b1a71d

Browse files
authored
Merge pull request #5 from cashapp/entin/core-subspec
Split framework into subspecs
2 parents 851c1bf + 0754159 commit 9b1a71d

24 files changed

+78
-41
lines changed

AccessibilitySnapshot.podspec

+24-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'AccessibilitySnapshot'
3-
s.version = '0.3.0'
3+
s.version = '0.3.1'
44
s.summary = 'Easy regression testing for iOS accessibility'
55

66
s.homepage = 'https://github.com/CashApp/AccessibilitySnapshot'
@@ -12,20 +12,31 @@ Pod::Spec.new do |s|
1212

1313
s.ios.deployment_target = '10.0'
1414

15-
s.source_files = 'AccessibilitySnapshot/Classes/**/*.{swift,h,m}'
16-
s.public_header_files = [
17-
'AccessibilitySnapshot/Classes/FBSnapshotTestCase_Accessibility.h',
18-
'AccessibilitySnapshot/Classes/UIAccessibilityStatusUtility.h',
19-
'AccessibilitySnapshot/Classes/UIView+DynamicTypeSnapshotting.h',
20-
]
15+
s.default_subspecs = 'Core', 'iOSSnapshotTestCase'
2116

22-
s.resource_bundles = {
23-
'AccessibilitySnapshot' => ['AccessibilitySnapshot/Assets/**/*.{strings,xcassets}']
24-
}
17+
s.subspec 'Core' do |ss|
18+
ss.source_files = 'AccessibilitySnapshot/Core/Classes/**/*.{swift,h,m}'
19+
ss.public_header_files = [
20+
'AccessibilitySnapshot/Core/Classes/UIAccessibilityStatusUtility.h',
21+
'AccessibilitySnapshot/Core/Classes/UIView+DynamicTypeSnapshotting.h',
22+
]
23+
ss.resource_bundles = {
24+
'AccessibilitySnapshot' => ['AccessibilitySnapshot/Core/Assets/**/*.{strings,xcassets}']
25+
}
26+
27+
ss.dependency 'fishhook', '~> 0.2'
28+
end
29+
30+
s.subspec 'iOSSnapshotTestCase' do |ss|
31+
ss.source_files = 'AccessibilitySnapshot/iOSSnapshotTestCase/Classes/**/*.{swift,h,m}'
32+
ss.public_header_files = [
33+
'AccessibilitySnapshot/iOSSnapshotTestCase/Classes/FBSnapshotTestCase_Accessibility.h',
34+
]
35+
36+
ss.dependency 'AccessibilitySnapshot/Core'
37+
ss.dependency 'iOSSnapshotTestCase', '~> 6.0'
38+
end
2539

2640
s.frameworks = 'XCTest'
2741
s.weak_frameworks = 'XCTest'
28-
29-
s.dependency 'iOSSnapshotTestCase', '~> 6.0'
30-
s.dependency 'fishhook', '~> 0.2'
3142
end

AccessibilitySnapshot/Classes/AccessibilityHierarchyParser.swift AccessibilitySnapshot/Core/Classes/AccessibilityHierarchyParser.swift

+15-11
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616

1717
import UIKit
1818

19-
struct AccessibilityMarker {
19+
public struct AccessibilityMarker {
2020

2121
// MARK: - Public Types
2222

23-
enum Shape {
23+
public enum Shape {
2424

2525
/// Accessibility frame, in the coordinate space of the view being snapshotted.
2626
case frame(CGRect)
@@ -34,29 +34,29 @@ struct AccessibilityMarker {
3434

3535
/// The description of the accessibility element that will be read by VoiceOver when the element is brought into
3636
/// focus.
37-
var description: String
37+
public var description: String
3838

3939
/// A hint that will be read by VoiceOver if focus remains on the element after the `description` is read.
40-
var hint: String?
40+
public var hint: String?
4141

4242
/// The shape that will be highlighted on screen while the element is in focus.
43-
var shape: Shape
43+
public var shape: Shape
4444

4545
/// The accessibility activation point, in the coordinate space of the view being snapshotted.
46-
var activationPoint: CGPoint
46+
public var activationPoint: CGPoint
4747

4848
/// Whether or not the `activationPoint` is the default activation point for the object.
4949
///
5050
/// For most elements, the default activation point is the midpoint of the element's accessibility frame. Certain
5151
/// elements have distinct defaults - for example, a `UISlider` puts its activation point at the center of its thumb
5252
/// by default.
53-
var usesDefaultActivationPoint: Bool
53+
public var usesDefaultActivationPoint: Bool
5454

5555
}
5656

5757
// MARK: -
5858

59-
protocol UserInterfaceLayoutDirectionProviding {
59+
public protocol UserInterfaceLayoutDirectionProviding {
6060

6161
var userInterfaceLayoutDirection: UIUserInterfaceLayoutDirection { get }
6262

@@ -66,12 +66,12 @@ extension UIApplication: UserInterfaceLayoutDirectionProviding {}
6666

6767
// MARK: -
6868

69-
final class AccessibilityHierarchyParser {
69+
public final class AccessibilityHierarchyParser {
7070

7171
// MARK: - Public Types
7272

7373
/// Represents a context in which elements are contained.
74-
enum Context {
74+
public enum Context {
7575

7676
/// Indicates the element is part of a series of elements.
7777
/// Reads as "`index` of `count`."
@@ -138,6 +138,10 @@ final class AccessibilityHierarchyParser {
138138

139139
}
140140

141+
// MARK: - Life Cycle
142+
143+
public init() {}
144+
141145
// MARK: - Public Methods
142146

143147
/// Parses the accessibility hierarchy starting from the `root` view and returns markers for each element in the
@@ -147,7 +151,7 @@ final class AccessibilityHierarchyParser {
147151
/// relative to this view's coordinate space.
148152
/// - parameter userInterfaceLayoutDirectionProvider: The provider of the device's user interface layout direction.
149153
/// In most cases, this should use the default value, `UIApplication.shared`.
150-
func parseAccessibilityElements(
154+
public func parseAccessibilityElements(
151155
in root: UIView,
152156
userInterfaceLayoutDirectionProvider: UserInterfaceLayoutDirectionProviding = UIApplication.shared
153157
) -> [AccessibilityMarker] {

AccessibilitySnapshot/Classes/AccessibilitySnapshotView.swift AccessibilitySnapshot/Core/Classes/AccessibilitySnapshotView.swift

+19-8
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,20 @@ public enum ActivationPointDisplayMode {
3838
///
3939
/// The overlays and legend will be added when `parseAccessibility()` is called. In order for the coordinates to be
4040
/// calculated properly, the view must already be in the view hierarchy.
41-
final class AccessibilitySnapshotView: UIView {
41+
public final class AccessibilitySnapshotView: UIView {
4242

4343
// MARK: - Life Cycle
4444

45-
init(
45+
/// Initializes a new snapshot container view.
46+
///
47+
/// - parameter containedView: The view that should be snapshotted, and for which the accessibility markers should
48+
/// be generated.
49+
/// - parameter viewRenderingMode: The method to use when snapshotting the `containedView`.
50+
/// - parameter markerColors: An array of colors to use for the highlighted regions. These colors will be used in
51+
/// order, repeating through the array as necessary.
52+
/// - parameter activationPointDisplayMode: Controls when to show indicators for elements' accessibility activation
53+
/// points.
54+
public init(
4655
containedView: UIView,
4756
viewRenderingMode: ViewRenderingMode,
4857
markerColors: [UIColor] = defaultMarkerColors,
@@ -85,7 +94,7 @@ final class AccessibilitySnapshotView: UIView {
8594
/// Parse the `containedView`'s accessibility and add appropriate visual elements to represent it.
8695
///
8796
/// This must be called _after_ the view is in the view hierarchy.
88-
func parseAccessibility(useMonochromeSnapshot: Bool) {
97+
public func parseAccessibility(useMonochromeSnapshot: Bool) {
8998
// Clean up any previous markers.
9099
self.displayMarkers.forEach {
91100
$0.legendView.removeFromSuperview()
@@ -175,7 +184,7 @@ final class AccessibilitySnapshotView: UIView {
175184

176185
// MARK: - UIView
177186

178-
override func layoutSubviews() {
187+
public override func layoutSubviews() {
179188
let legendViews = displayMarkers.map { $0.legendView }
180189

181190
switch legendLocation(viewSize: snapshotView.bounds.size) {
@@ -225,7 +234,7 @@ final class AccessibilitySnapshotView: UIView {
225234
}
226235
}
227236

228-
override func sizeThatFits(_ size: CGSize) -> CGSize {
237+
public override func sizeThatFits(_ size: CGSize) -> CGSize {
229238
guard !displayMarkers.isEmpty else {
230239
return snapshotView.bounds.size
231240
}
@@ -323,9 +332,9 @@ final class AccessibilitySnapshotView: UIView {
323332
}
324333
}
325334

326-
// MARK: - Private Static Properties
335+
// MARK: - Public Static Properties
327336

328-
private static let defaultMarkerColors: [UIColor] = [ .cyan, .magenta, .green, .blue, .yellow, .purple, .orange ]
337+
public static let defaultMarkerColors: [UIColor] = [ .cyan, .magenta, .green, .blue, .yellow, .purple, .orange ]
329338

330339
// MARK: - Private Types
331340

@@ -369,10 +378,12 @@ final class AccessibilitySnapshotView: UIView {
369378

370379
extension AccessibilitySnapshotView {
371380

372-
enum ViewRenderingMode {
381+
public enum ViewRenderingMode {
373382

383+
/// Render the view's layer in a `CGContext` using the `render(in:)` method.
374384
case renderLayerInContext
375385

386+
/// Draw the view's hierarchy after screen updates using the `drawHierarchy(in:afterScreenUpdates:)` method.
376387
case drawHierarchyInRect
377388

378389
}

AccessibilitySnapshot/Classes/UIView+InvertColorsSnapshotting.swift AccessibilitySnapshot/Core/Classes/UIView+InvertColorsSnapshotting.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import UIKit
2020

2121
extension UIView {
2222

23-
// MARK: - Internal Methods
23+
// MARK: - Public Methods
2424

2525
@available(iOS 11, *)
26-
func drawHierarchyWithInvertedColors(in rect: CGRect, using context: UIGraphicsImageRendererContext) {
26+
public func drawHierarchyWithInvertedColors(in rect: CGRect, using context: UIGraphicsImageRendererContext) {
2727
if accessibilityIgnoresInvertColors {
2828
drawHierarchy(in: rect, afterScreenUpdates: false)
2929

Example/Podfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ target 'AccessibilitySnapshotDemo' do
1414
target 'UnitTests' do
1515
inherit! :search_paths
1616

17-
pod 'AccessibilitySnapshot', :path => '../AccessibilitySnapshot.podspec'
17+
pod 'AccessibilitySnapshot/Core', :path => '../AccessibilitySnapshot.podspec'
1818
end
1919
end
2020

Example/Podfile.lock

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
PODS:
2-
- AccessibilitySnapshot (0.3.0):
2+
- AccessibilitySnapshot (0.3.1):
3+
- AccessibilitySnapshot/Core (= 0.3.1)
4+
- AccessibilitySnapshot/iOSSnapshotTestCase (= 0.3.1)
5+
- AccessibilitySnapshot/Core (0.3.1):
36
- fishhook (~> 0.2)
7+
- AccessibilitySnapshot/iOSSnapshotTestCase (0.3.1):
8+
- AccessibilitySnapshot/Core
49
- iOSSnapshotTestCase (~> 6.0)
510
- fishhook (0.2)
611
- iOSSnapshotTestCase (6.2.0):
@@ -12,6 +17,7 @@ PODS:
1217

1318
DEPENDENCIES:
1419
- AccessibilitySnapshot (from `../AccessibilitySnapshot.podspec`)
20+
- AccessibilitySnapshot/Core (from `../AccessibilitySnapshot.podspec`)
1521
- Paralayout (~> 0.9)
1622

1723
SPEC REPOS:
@@ -25,11 +31,11 @@ EXTERNAL SOURCES:
2531
:path: "../AccessibilitySnapshot.podspec"
2632

2733
SPEC CHECKSUMS:
28-
AccessibilitySnapshot: 4ef5ec8d06dd9aa167fcc3afa86539a59d649161
34+
AccessibilitySnapshot: 5c623007716998e3b9d040fd28f42407c0e38502
2935
fishhook: ea19933abfe8f2f52c55fd8b6e2718467d3ebc89
3036
iOSSnapshotTestCase: 9ab44cb5aa62b84d31847f40680112e15ec579a6
3137
Paralayout: e36bf8c795ed9930159b9635ebb802d026667d0b
3238

33-
PODFILE CHECKSUM: 75c7dd396546765a95d746610aba834d2b137c84
39+
PODFILE CHECKSUM: a46ca457f96c3770fea5e16fe5218c1408222d82
3440

3541
COCOAPODS: 1.9.1

Example/UnitTests/AccessibilityHierarchyParserTests.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414
// limitations under the License.
1515
//
1616

17+
import AccessibilitySnapshot
1718
import UIKit
1819
import XCTest
1920

20-
@testable import AccessibilitySnapshot
21-
2221
final class AccessibilityHierarchyParserTests: XCTestCase {
2322

2423
func testUserInterfaceLayoutDirection() {

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ AccessibilitySnapshots makes it simple to add regression tests for accessibility
99

1010
## Getting Started
1111

12-
AccessibilitySnapshot is built on top of [iOSSnapshotTestCase](https://github.com/uber/ios-snapshot-test-case). Before setting up accessibility snapshot tests, make sure your project is set up for standard snapshot testing. Accessibility snapshot tests require that the test target has a host application.
12+
By default, AccessibilitySnapshot uses [iOSSnapshotTestCase](https://github.com/uber/ios-snapshot-test-case) to record snapshots and perform comparisons. Before setting up accessibility snapshot tests, make sure your project is set up for standard snapshot testing. Accessibility snapshot tests require that the test target has a host application.
1313

1414
### CocoaPods
1515

@@ -19,6 +19,12 @@ Install with [CocoaPods](https://cocoapods.org) by adding the following to your
1919
pod 'AccessibilitySnapshot'
2020
```
2121

22+
To use only the core accessibility parser, add a dependency on the Core subspec alone.
23+
24+
```ruby
25+
pod 'AccessibilitySnapshot/Core'
26+
```
27+
2228
## Usage
2329

2430
To run a snapshot test, simply call the `SnapshotVerifyAccessibility` method:

0 commit comments

Comments
 (0)