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

Supporting Swift 6 #82

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
fail-fast: false
matrix:
include:
- xcode: "Xcode_15.0.1"
runsOn: macos-13
- xcode: "Xcode_14.3.1"
runsOn: macos-13
- xcode: "Xcode_16.0"
runsOn: macos-15
- xcode: "Xcode_15.4"
runsOn: macos-14
steps:
- uses: actions/checkout@v4
- name: Select Xcode
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.8
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand Down
53 changes: 53 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// swift-tools-version: 5.10
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "Prefire",
platforms: [.iOS(.v14)],
products: [
.library(
name: "Prefire",
targets: ["Prefire"]
),
.plugin(
name: "PrefirePlaybookPlugin",
targets: ["PrefirePlaybookPlugin"]
),
.plugin(
name: "PrefireTestsPlugin",
targets: ["PrefireTestsPlugin"]
),
],
targets: [
.target(
name: "Prefire",
dependencies: []
),
.plugin(
name: "PrefirePlaybookPlugin",
capability: .buildTool(),
dependencies: [
"PrefireBinary",
"PrefireSourcery",
]
),
.plugin(
name: "PrefireTestsPlugin",
capability: .buildTool(),
dependencies: [
"PrefireBinary",
"PrefireSourcery",
]
),
.binaryTarget(
name: "PrefireBinary",
path: "Binaries/PrefireBinary.artifactbundle"
),
.binaryTarget(
name: "PrefireSourcery",
path: "PrefireExecutable/Binaries/PrefireSourcery.artifactbundle"
),
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ extension PreviewLoader {

return yamlSettings +
"""
@MainActor
private struct MacroPreviews {
static var previews: [PreviewModel] = [
\(previewModels)
Expand Down
26 changes: 17 additions & 9 deletions Sources/Prefire/Playbook/PlaybookView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import SwiftUI
extension CGFloat {
static let scale: CGFloat = 0.55
static let infoViewHeight: CGFloat = 42
static let screenHeight = UIScreen.main.bounds.height
static let screeenWidth = UIScreen.main.bounds.width
@MainActor static let screenHeight = UIScreen.main.bounds.height
@MainActor static let screenWidth = UIScreen.main.bounds.width
}

/// View to show different states of components and screens
Expand Down Expand Up @@ -78,7 +78,7 @@ public struct PlaybookView: View {
private func componentList(for name: String) -> some View {
ScrollView(.horizontal, showsIndicators: false) {
HStack(alignment: .top, spacing: 16) {
ForEach($viewModels) { $viewModel in
ForEach($viewModels, id: \.id) { $viewModel in
if viewModel.name == name || viewModel.story == name {
VStack {
if !isComponent {
Expand All @@ -102,10 +102,7 @@ public struct PlaybookView: View {
}

struct PreviewView: View, Identifiable {
@inlinable
var id: String {
viewModel.id
}
let id: String

let isComponent: Bool

Expand All @@ -116,6 +113,16 @@ public struct PlaybookView: View {
@Binding var sectionNames: [String]
@Environment(\.colorScheme) private var colorScheme

init(isComponent: Bool, selectedId: Binding<String>, navigationLinkTriggered: Binding<Bool>, viewModel: Binding<PreviewModel>, viewModels: Binding<[PreviewModel]>, sectionNames: Binding<[String]>) {
self.id = viewModel.wrappedValue.id
self.isComponent = isComponent
_selectedId = selectedId
_navigationLinkTriggered = navigationLinkTriggered
_viewModel = viewModel
_viewModels = viewModels
_sectionNames = sectionNames
}

var body: some View {
Button(action: {
selectedId = viewModel.id
Expand Down Expand Up @@ -160,12 +167,13 @@ public struct PlaybookView: View {
let id: String
let isScreen: Bool
var view: Content
@Environment(\.safeAreaInsets) private var safeAreaInsets

@State private var safeAreaInsets = UIApplication.shared.windows.first?.safeAreaInsets ?? UIEdgeInsets()

var body: some View {
view
.allowsHitTesting(false)
.frame(width: .screeenWidth)
.frame(width: .screenWidth)
.transformIf(isScreen) { view in
view.frame(height: .screenHeight - safeAreaInsets.top + safeAreaInsets.bottom - .infoViewHeight)
}
Expand Down
19 changes: 0 additions & 19 deletions Sources/Prefire/Playbook/SafeAreaEnviroment.swift

This file was deleted.

10 changes: 5 additions & 5 deletions Sources/Prefire/Preview/PreferenceKeys.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SwiftUI

public struct UserStoryPreferenceKey: PreferenceKey {
public static var defaultValue: PreviewModel.UserStory?
public static let defaultValue: PreviewModel.UserStory? = nil

public static func reduce(value: inout PreviewModel.UserStory?, nextValue: () -> PreviewModel.UserStory?) {
value = nextValue()
Expand All @@ -22,7 +22,7 @@ public extension View {
// MARK: - State

public struct StatePreferenceKey: PreferenceKey {
public static var defaultValue: PreviewModel.State?
public static let defaultValue: PreviewModel.State? = nil

public static func reduce(value: inout PreviewModel.State?, nextValue: () -> PreviewModel.State?) {
value = nextValue()
Expand All @@ -43,23 +43,23 @@ public extension View {
// MARK: - Snapshot Attributes

public struct DelayPreferenceKey: PreferenceKey {
public static var defaultValue: TimeInterval = 0.0
public static let defaultValue: TimeInterval = 0.0

public static func reduce(value: inout TimeInterval, nextValue: () -> TimeInterval) {
value = nextValue()
}
}

public struct PrecisionPreferenceKey: PreferenceKey {
public static var defaultValue: Float = 1.0
public static let defaultValue: Float = 1.0

public static func reduce(value: inout Float, nextValue: () -> Float) {
value = nextValue()
}
}

public struct PerceptualPrecisionPreferenceKey: PreferenceKey {
public static var defaultValue: Float = 1.0
public static let defaultValue: Float = 1.0

public static func reduce(value: inout Float, nextValue: () -> Float) {
value = nextValue()
Expand Down
3 changes: 3 additions & 0 deletions Sources/Prefire/Preview/PreviewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public struct PreviewModel: Identifiable {
/// The time from when a view was created (`.init`) to when it was shown (`.onAppear`)
public var renderTime: String?

@MainActor
public init(
id: String? = nil,
content: @escaping () -> any View,
Expand All @@ -66,6 +67,7 @@ public struct PreviewModel: Identifiable {
self.device = device
}

@MainActor
public init(
id: String? = nil,
content: @escaping () -> UIView,
Expand All @@ -76,6 +78,7 @@ public struct PreviewModel: Identifiable {
self.init(id: id, content: { AnyView(ViewRepresentable(view: content())) }, name: name, type: type, device: device)
}

@MainActor
public init(
id: String? = nil,
content: @escaping () -> UIViewController,
Expand Down
2 changes: 2 additions & 0 deletions Templates/PreviewModels.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {{ import }}
{% endfor %}

public enum PreviewModels {
@MainActor
public static var models: [PreviewModel] = {
var views: [PreviewModel] = []
#if !PLAYBOOK_DISABLED
Expand All @@ -28,6 +29,7 @@ public enum PreviewModels {
}()

@inlinable
@MainActor
static func createModel<Preview: PreviewProvider>(for preview: Preview.Type, name: String) -> [PreviewModel] {
var views: [PreviewModel] = []

Expand Down
8 changes: 4 additions & 4 deletions Templates/PreviewTests.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ class PreviewTests: XCTestCase {
#if canImport(AccessibilitySnapshot)
let vc = UIHostingController(rootView: matchingView)
vc.view.frame = UIScreen.main.bounds
assertSnapshot(

SnapshotTesting.assertSnapshot(
matching: vc,
as: .wait(for: delay, on: .accessibilityImage(showActivationPoints: .always)),
named: prefireSnapshot.name.flatMap { $0 + ".accessibility" }{% if argument.file %},
as: .wait(for: delay, on: .accessibilityImage(showActivationPoints: .always)){% if argument.file %},
file: file{% endif %},
testName: prefireSnapshot.name
testName: prefireSnapshot.name + ".accessibility"
)
#endif
return failure
Expand Down