From 8f595ccd15d7be84bcb0ccd8ff2f9d90bbec6c36 Mon Sep 17 00:00:00 2001 From: Nico Hinderling Date: Tue, 6 Aug 2024 12:37:18 -0700 Subject: [PATCH 1/2] Get off of accessibilitySnapshot fork --- Package.swift | 2 +- Sources/SnapshotPreviewsCore/View+Snapshot.swift | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Package.swift b/Package.swift index a7ae7610..e5963cd2 100644 --- a/Package.swift +++ b/Package.swift @@ -34,7 +34,7 @@ let package = Package( ], dependencies: [ .package(url: "https://github.com/EmergeTools/FlyingFox.git", exact: "1.0.0"), - .package(url: "https://github.com/EmergeTools/AccessibilitySnapshot.git", exact: "1.0.2"), + .package(url: "https://github.com/cashapp/AccessibilitySnapshot.git", exact: "0.7.0"), ], targets: [ // Targets are the basic building blocks of a package, defining a module or a test suite. diff --git a/Sources/SnapshotPreviewsCore/View+Snapshot.swift b/Sources/SnapshotPreviewsCore/View+Snapshot.swift index d37b34c6..3e4c1974 100644 --- a/Sources/SnapshotPreviewsCore/View+Snapshot.swift +++ b/Sources/SnapshotPreviewsCore/View+Snapshot.swift @@ -84,7 +84,8 @@ extension View { a11yView.center = window.center window.addSubview(a11yView) - let elements = try? a11yView.parseAccessibility(useMonochromeSnapshot: false) + try? a11yView.parseAccessibility(useMonochromeSnapshot: false) + let elements = a11yView.accessibilityElements as? [any AccessibilityMark] a11yView.sizeToFit() let result = Self.takeSnapshot(layout: .sizeThatFits, renderingMode: renderingMode, rootVC: containerVC, targetView: a11yView) a11yView.removeFromSuperview() From fcd17a082001ddfb856c70771296fe3472abdd5d Mon Sep 17 00:00:00 2001 From: Nico Hinderling Date: Thu, 8 Aug 2024 10:33:10 -0700 Subject: [PATCH 2/2] include string localization to demonstrate the NSDoubleLocalizedStrings argument working properly --- DemoApp/DemoApp.xcodeproj/project.pbxproj | 12 ++++++++++++ DemoApp/DemoApp/Extensions/String+Localization.swift | 7 +++++++ DemoApp/DemoApp/TestViews/RideShareButton.swift | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 DemoApp/DemoApp/Extensions/String+Localization.swift diff --git a/DemoApp/DemoApp.xcodeproj/project.pbxproj b/DemoApp/DemoApp.xcodeproj/project.pbxproj index 712476ff..1a7adc5e 100644 --- a/DemoApp/DemoApp.xcodeproj/project.pbxproj +++ b/DemoApp/DemoApp.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + C33735B42C6537E6001054FE /* String+Localization.swift in Sources */ = {isa = PBXBuildFile; fileRef = C33735B22C6537E6001054FE /* String+Localization.swift */; }; FA0B20F12A7DA20200EC91D3 /* AnyViewPreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA0B20F02A7DA20200EC91D3 /* AnyViewPreview.swift */; }; FA0B20FA2A7DCB0100EC91D3 /* ArrayBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA0B20F82A7DCB0100EC91D3 /* ArrayBuilder.swift */; }; FA0B20FB2A7DCB0100EC91D3 /* PreviewVariants.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA0B20F92A7DCB0100EC91D3 /* PreviewVariants.swift */; }; @@ -138,6 +139,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + C33735B22C6537E6001054FE /* String+Localization.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "String+Localization.swift"; path = "DemoApp/Extensions/String+Localization.swift"; sourceTree = SOURCE_ROOT; }; FA0B20F02A7DA20200EC91D3 /* AnyViewPreview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnyViewPreview.swift; sourceTree = ""; }; FA0B20F82A7DCB0100EC91D3 /* ArrayBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ArrayBuilder.swift; sourceTree = ""; }; FA0B20F92A7DCB0100EC91D3 /* PreviewVariants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PreviewVariants.swift; sourceTree = ""; }; @@ -234,6 +236,14 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + C33735B32C6537E6001054FE /* Extensions */ = { + isa = PBXGroup; + children = ( + C33735B22C6537E6001054FE /* String+Localization.swift */, + ); + path = Extensions; + sourceTree = ""; + }; FA1671B62A5367A800A42DB0 = { isa = PBXGroup; children = ( @@ -268,6 +278,7 @@ FABCCD922AC39081008F4D3A /* EMGTestHandler.swift */, FA1671C42A5367A800A42DB0 /* ContentView.swift */, FAD52BF02A7B5EBB001F1832 /* TestViews */, + C33735B32C6537E6001054FE /* Extensions */, FA1671C62A5367A800A42DB0 /* Assets.xcassets */, FA1671C82A5367A800A42DB0 /* DemoApp.entitlements */, FA1671C92A5367A800A42DB0 /* Preview Content */, @@ -609,6 +620,7 @@ FAD52BF72A7B5EEA001F1832 /* CodeEntryView.swift in Sources */, FAD52BF62A7B5EEA001F1832 /* ExpandingView.swift in Sources */, FAD52BF92A7B5EEA001F1832 /* RideShareButton.swift in Sources */, + C33735B42C6537E6001054FE /* String+Localization.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/DemoApp/DemoApp/Extensions/String+Localization.swift b/DemoApp/DemoApp/Extensions/String+Localization.swift new file mode 100644 index 00000000..777b7c30 --- /dev/null +++ b/DemoApp/DemoApp/Extensions/String+Localization.swift @@ -0,0 +1,7 @@ +import Foundation + +extension String { + var localized: String { + return NSLocalizedString(self, comment: "") + } +} \ No newline at end of file diff --git a/DemoApp/DemoApp/TestViews/RideShareButton.swift b/DemoApp/DemoApp/TestViews/RideShareButton.swift index 4287b6f4..01ab7170 100644 --- a/DemoApp/DemoApp/TestViews/RideShareButton.swift +++ b/DemoApp/DemoApp/TestViews/RideShareButton.swift @@ -46,7 +46,7 @@ struct RideShareButtonView_Previews: PreviewProvider { .previewLayout(.sizeThatFits) .padding() - RideShareButtonView(title: "Request Ride") { + RideShareButtonView(title: "Request Ride".localized) { print("Button tapped") } .previewLayout(.sizeThatFits)