Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift 6 support #223

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
14 changes: 12 additions & 2 deletions .github/workflows/build-xcframework.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,21 @@ on:
jobs:
build:
runs-on: macos-14
strategy:
matrix:
xcode-version: [15.4, 16.1]

steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Xcode select
run: sudo xcode-select -s '/Applications/Xcode_15.4.app/Contents/Developer'
- name: Xcode select ${{ matrix.xcode-version }}
run: sudo xcode-select -s '/Applications/Xcode_${{ matrix.xcode-version }}.app/Contents/Developer'
- name: Get Swift Version
run: |
SWIFT_MAJOR_VERSION=$(swift --version 2>&1 | awk '/Apple Swift version/ { split($7, ver, "."); print ver[1]; exit }')
echo "Swift major version: $SWIFT_MAJOR_VERSION"
echo "SWIFT_VERSION=$SWIFT_MAJOR_VERSION.0" >> "$GITHUB_ENV"
- name: Build xcframework
run: sh build.sh
env:
SWIFT_VERSION: ${{ env.SWIFT_VERSION }}
74 changes: 61 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ on:
jobs:
build:
runs-on: macos-14

strategy:
matrix:
xcode-version: [15.4, 16.1]
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Xcode select
run: sudo xcode-select -s '/Applications/Xcode_15.4.app/Contents/Developer'
- name: Xcode select ${{ matrix.xcode-version }}
run: sudo xcode-select -s '/Applications/Xcode_${{ matrix.xcode-version }}.app/Contents/Developer'
- name: Get Swift Version
run: |
SWIFT_MAJOR_VERSION=$(swift --version 2>&1 | awk '/Apple Swift version/ { split($7, ver, "."); print ver[1]; exit }')
echo "Swift major version: $SWIFT_MAJOR_VERSION"
echo "SWIFT_VERSION=$SWIFT_MAJOR_VERSION.0" >> "$GITHUB_ENV"
- name: Build TestApp
run: cd Examples && xcodebuild build -scheme DemoApp -sdk iphonesimulator -destination 'generic/platform=iOS Simulator' -project DemoApp/DemoApp.xcodeproj
- name: Build Snapshotting
Expand All @@ -22,12 +29,20 @@ jobs:
run: xcodebuild build -scheme SnapshottingTests -sdk iphonesimulator -destination 'generic/platform=iOS Simulator'
build-tvos:
runs-on: macos-14
strategy:
matrix:
xcode-version: [15.4, 16.1]

steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Xcode select
run: sudo xcode-select -s '/Applications/Xcode_15.4.app/Contents/Developer'
- name: Xcode select ${{ matrix.xcode-version }}
run: sudo xcode-select -s '/Applications/Xcode_${{ matrix.xcode-version }}.app/Contents/Developer'
- name: Get Swift Version
run: |
SWIFT_MAJOR_VERSION=$(swift --version 2>&1 | awk '/Apple Swift version/ { split($7, ver, "."); print ver[1]; exit }')
echo "Swift major version: $SWIFT_MAJOR_VERSION"
echo "SWIFT_VERSION=$SWIFT_MAJOR_VERSION.0" >> "$GITHUB_ENV"
- name: Build PreviewGallery
run: xcodebuild build -scheme PreviewGallery -sdk appletvsimulator -destination 'generic/platform=tvOS Simulator'
- name: Build Snapshotting
Expand All @@ -36,12 +51,20 @@ jobs:
run: xcodebuild build -scheme SnapshottingTests -sdk appletvsimulator -destination 'generic/platform=tvOS Simulator'
build-visionos:
runs-on: macos-15
strategy:
matrix:
xcode-version: [15.4, 16.1]

steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Xcode select
run: sudo xcode-select -s '/Applications/Xcode_16.0.app/Contents/Developer'
- name: Xcode select ${{ matrix.xcode-version }}
run: sudo xcode-select -s '/Applications/Xcode_${{ matrix.xcode-version }}.app/Contents/Developer'
- name: Get Swift Version
run: |
SWIFT_MAJOR_VERSION=$(swift --version 2>&1 | awk '/Apple Swift version/ { split($7, ver, "."); print ver[1]; exit }')
echo "Swift major version: $SWIFT_MAJOR_VERSION"
echo "SWIFT_VERSION=$SWIFT_MAJOR_VERSION.0" >> "$GITHUB_ENV"
- name: Build TestApp
run: cd Examples && xcodebuild build -scheme DemoApp -sdk xrsimulator -destination 'generic/platform=visionOS Simulator' -project DemoApp/DemoApp.xcodeproj
- name: Build Snapshotting
Expand All @@ -50,12 +73,20 @@ jobs:
run: xcodebuild build -scheme SnapshottingTests -sdk xrsimulator -destination 'generic/platform=visionOS Simulator'
build-watchos:
runs-on: macos-14
strategy:
matrix:
xcode-version: [15.4, 16.1]

steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Xcode select
run: sudo xcode-select -s '/Applications/Xcode_15.4.app/Contents/Developer'
- name: Xcode select ${{ matrix.xcode-version }}
run: sudo xcode-select -s '/Applications/Xcode_${{ matrix.xcode-version }}.app/Contents/Developer'
- name: Get Swift Version
run: |
SWIFT_MAJOR_VERSION=$(swift --version 2>&1 | awk '/Apple Swift version/ { split($7, ver, "."); print ver[1]; exit }')
echo "Swift major version: $SWIFT_MAJOR_VERSION"
echo "SWIFT_VERSION=$SWIFT_MAJOR_VERSION.0" >> "$GITHUB_ENV"
- name: Build Test Watch App
run: cd Examples && xcodebuild build -scheme 'Demo Watch App' -sdk watchsimulator -destination 'generic/platform=watchOS Simulator' -project DemoApp/DemoApp.xcodeproj CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO
- name: Build Snapshotting
Expand All @@ -64,12 +95,20 @@ jobs:
run: xcodebuild build -scheme SnapshottingTests -sdk watchsimulator -destination 'generic/platform=watchOS Simulator'
build-macos:
runs-on: macos-14
strategy:
matrix:
xcode-version: [15.4, 16.1]

steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Xcode select
run: sudo xcode-select -s '/Applications/Xcode_15.4.app/Contents/Developer'
- name: Xcode select ${{ matrix.xcode-version }}
run: sudo xcode-select -s '/Applications/Xcode_${{ matrix.xcode-version }}.app/Contents/Developer'
- name: Get Swift Version
run: |
SWIFT_MAJOR_VERSION=$(swift --version 2>&1 | awk '/Apple Swift version/ { split($7, ver, "."); print ver[1]; exit }')
echo "Swift major version: $SWIFT_MAJOR_VERSION"
echo "SWIFT_VERSION=$SWIFT_MAJOR_VERSION.0" >> "$GITHUB_ENV"
- name: Build PreviewGallery
run: xcodebuild build -scheme PreviewGallery -sdk macosx -destination 'generic/platform=macOS'
- name: Build Snapshotting
Expand All @@ -78,11 +117,20 @@ jobs:
run: xcodebuild build -scheme SnapshottingTests -sdk macosx -destination 'generic/platform=macOS'
build-macos-catalyst:
runs-on: macos-14
strategy:
matrix:
xcode-version: [15.4, 16.1]

steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Xcode select
run: sudo xcode-select -s '/Applications/Xcode_15.4.app/Contents/Developer'
- name: Xcode select ${{ matrix.xcode-version }}
run: sudo xcode-select -s '/Applications/Xcode_${{ matrix.xcode-version }}.app/Contents/Developer'
- name: Get Swift Version
run: |
SWIFT_MAJOR_VERSION=$(swift --version 2>&1 | awk '/Apple Swift version/ { split($7, ver, "."); print ver[1]; exit }')
echo "Swift major version: $SWIFT_MAJOR_VERSION"
echo "SWIFT_VERSION=$SWIFT_MAJOR_VERSION.0" >> "$GITHUB_ENV"
- name: Build PreviewGallery
run: xcodebuild build -scheme PreviewGallery -sdk macosx -destination 'platform=macOS,variant=Mac Catalyst'
- name: Build Snapshotting
Expand Down
29 changes: 21 additions & 8 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,41 @@ on:
jobs:
release:
runs-on: macos-14
strategy:
matrix:
xcode-version: [15.4, 16.1]

steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Xcode select
run: sudo xcode-select -s '/Applications/Xcode_15.4.app/Contents/Developer'
- name: Xcode select ${{ matrix.xcode-version }}
run: sudo xcode-select -s '/Applications/Xcode_${{ matrix.xcode-version }}.app/Contents/Developer'
- name: Get Swift Version
run: |
SWIFT_MAJOR_VERSION=$(swift --version 2>&1 | awk '/Apple Swift version/ { split($7, ver, "."); print ver[1]; exit }')
echo "Swift major version: $SWIFT_MAJOR_VERSION"
echo "SWIFT_MAJOR_VERSION=$SWIFT_MAJOR_VERSION" >> "$GITHUB_ENV"
echo "SWIFT_VERSION=$SWIFT_MAJOR_VERSION.0" >> "$GITHUB_ENV"
- name: Build xcframework
run: sh build.sh
env:
SWIFT_VERSION: ${{ env.SWIFT_VERSION }}
- name: Build xcframework
run: sh build.sh
- name: Zip SnapshottingTests xcframework
run: zip -r SnapshottingTests.xcframework.zip SnapshottingTests.xcframework
run: zip -r SnapshottingTests_swift_${{ env.SWIFT_MAJOR_VERSION }}.xcframework.zip SnapshottingTests.xcframework
- name: Zip PreviewGallery xcframework
run: zip -r PreviewGallery.xcframework.zip PreviewGallery.xcframework
run: zip -r PreviewGallery_swift_${{ env.SWIFT_MAJOR_VERSION }}.xcframework.zip PreviewGallery.xcframework
- name: Zip preivews support
run: (cd PreviewsSupport && zip -r PreviewsSupport.xcframework.zip PreviewsSupport.xcframework)
run: (cd PreviewsSupport && zip -r PreviewsSupport_swift_${{ env.SWIFT_MAJOR_VERSION }}.xcframework.zip PreviewsSupport.xcframework)
- name: Upload Artifact
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
PreviewGallery.xcframework.zip
SnapshottingTests.xcframework.zip
PreviewsSupport/PreviewsSupport.xcframework.zip
PreviewGallery_swift_${{ env.SWIFT_MAJOR_VERSION }}.xcframework.zip
SnapshottingTests_swift_${{ env.SWIFT_MAJOR_VERSION }}.xcframework.zip
PreviewsSupport_swift_${{ env.SWIFT_MAJOR_VERSION }}.xcframework.zip
body:
Release ${{ github.ref }}
Automated release created by GitHub Actions.
12 changes: 11 additions & 1 deletion Examples/DemoApp/DemoApp/TestViews/PreviewVariants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,22 @@ extension View {
struct PreviewVariants: View {

init(
modifiers: [NamedViewModifier] = .previewDefault,
modifiers: [NamedViewModifier],
layout: PreviewLayout = .device,
@ArrayBuilder<PreviewView> views: () -> [PreviewView])
{
self.modifiers = modifiers
self.layout = layout
self.views = views()
}

@MainActor
init(
layout: PreviewLayout = .device,
@ArrayBuilder<PreviewView> views: () -> [PreviewView])
{
self.init(modifiers: .previewDefault, layout: layout, views: views)
}

var body: some View {
ForEach(modifiers) { modifier in
Expand Down Expand Up @@ -73,6 +81,7 @@ extension NamedViewModifier {
@available(watchOS, unavailable)
@available(visionOS, unavailable)
@available(tvOS, unavailable)
@MainActor
static var accessibility: NamedViewModifier {
.init(name: "Accessibility", value: { $0.emergeAccessibility(true) })
}
Expand All @@ -84,6 +93,7 @@ extension NamedViewModifier {

extension [NamedViewModifier] {
/// The default named view modifiers in a ``PreviewVariants``.
@MainActor
static var previewDefault: [NamedViewModifier] {
#if os(iOS)
if UserDefaults.standard.bool(forKey: "NSDoubleLocalizedStrings") {
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/swhitty/FlyingFox.git", exact: "0.16.0"),
.package(url: "https://github.com/EmergeTools/AccessibilitySnapshot.git", exact: "1.0.2"),
.package(url: "https://github.com/EmergeTools/AccessibilitySnapshot.git", branch: "feature/swift_6_support"),
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
Expand Down
2 changes: 1 addition & 1 deletion Sources/SnapshotPreferences/AccessibiltyPreference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct AccessibilityPreferenceKey: PreferenceKey {
}
}

static var defaultValue: Bool? = nil
static let defaultValue: Bool? = nil
}

extension View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct AppStoreSnapshotPreferenceKey: PreferenceKey {
}
}

static var defaultValue: Bool? = nil
static let defaultValue: Bool? = nil
}

extension View {
Expand Down
27 changes: 19 additions & 8 deletions Sources/SnapshotPreferences/EmergeModifierFinder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import SnapshotSharedModels
// The inserted test runner code finds these classes through ObjC runtime functions (NSClassFromString)
// and Swift reflection (Mirror).

@objc(EmergeModifierState)
class EmergeModifierState: NSObject {
@objc(EmergeModifierState) @MainActor
final class EmergeModifierState: NSObject {

@objc
@MainActor @objc
static let shared = EmergeModifierState()

func reset() {
Expand All @@ -35,23 +35,34 @@ class EmergeModifierState: NSObject {

@objc(EmergeModifierFinder)
class EmergeModifierFinder: NSObject {
@MainActor
let finder: (any View) -> (any View) = { view in
EmergeModifierState.shared.reset()
return view
.onPreferenceChange(ExpansionPreferenceKey.self, perform: { value in
EmergeModifierState.shared.expansionPreference = value
Task { @MainActor in
EmergeModifierState.shared.expansionPreference = value
}
})
.onPreferenceChange(RenderingModePreferenceKey.self, perform: { value in
EmergeModifierState.shared.renderingMode = value
Task { @MainActor in
EmergeModifierState.shared.renderingMode = value
}
})
.onPreferenceChange(PrecisionPreferenceKey.self, perform: { value in
EmergeModifierState.shared.precision = value
Task { @MainActor in
EmergeModifierState.shared.precision = value
}
})
.onPreferenceChange(AccessibilityPreferenceKey.self, perform: { value in
EmergeModifierState.shared.accessibilityEnabled = value
Task { @MainActor in
EmergeModifierState.shared.accessibilityEnabled = value
}
})
.onPreferenceChange(AppStoreSnapshotPreferenceKey.self, perform: { value in
EmergeModifierState.shared.appStoreSnapshot = value
Task { @MainActor in
EmergeModifierState.shared.appStoreSnapshot = value
}
})
}
}
2 changes: 1 addition & 1 deletion Sources/SnapshotPreferences/ExpansionPreference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct ExpansionPreferenceKey: PreferenceKey {
}
}

static var defaultValue: Bool? = nil
static let defaultValue: Bool? = nil
}

extension View {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SnapshotPreferences/PrecisionPreference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct PrecisionPreferenceKey: PreferenceKey {
value = nextValue()
}

static var defaultValue: Float? = nil
static let defaultValue: Float? = nil
}

extension View {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SnapshotPreferences/RenderingModePreference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct RenderingModePreferenceKey: PreferenceKey {
value = nextValue()
}

static var defaultValue: EmergeRenderingMode.RawValue? = nil
static let defaultValue: EmergeRenderingMode.RawValue? = nil
}

extension View {
Expand Down
15 changes: 9 additions & 6 deletions Sources/SnapshotPreviewsCore/ExpandingViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import SnapshotSharedModels

public final class ExpandingViewController: UIHostingController<EmergeModifierView>, ScrollExpansionProviding {

@MainActor
var supportsExpansion: Bool {
rootView.supportsExpansion
}
Expand Down Expand Up @@ -112,15 +113,17 @@ public final class ExpandingViewController: UIHostingController<EmergeModifierVi
}
startTime = Date()
timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { [weak self] _ in
Task { @MainActor in
guard let self,
let start = startTime,
Date().timeIntervalSince(start) >= HeightExpansionTimeLimitInSeconds else {
return
let start = self.startTime,
Date().timeIntervalSince(start) >= self.HeightExpansionTimeLimitInSeconds else {
return
}
let timeoutError = RenderingError.expandingViewTimeout(CGSize(width: UIScreen.main.bounds.size.width,
height: firstScrollView?.visibleContentHeight ?? -1))
NSLog("ExpandingViewController: Expanding Scroll View timed out. Current height is \(firstScrollView?.visibleContentHeight ?? -1)")
runCallback(timeoutError)
height: self.firstScrollView?.visibleContentHeight ?? -1))
NSLog("ExpandingViewController: Expanding Scroll View timed out. Current height is \(self.firstScrollView?.visibleContentHeight ?? -1)")
self.runCallback(timeoutError)
}
}
}

Expand Down
Loading