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

Support Xcode 16.2 onPreferenceChange SDK change #48

Merged
merged 5 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
with:
runsonlabels: '["macOS", "self-hosted"]'
scheme: SpeziViews-Package
destination: 'platform=watchOS Simulator,name=Apple Watch Series 9 (45mm)'
destination: 'platform=watchOS Simulator,name=Apple Watch Series 10 (46mm)'
resultBundle: SpeziViews-watchOS.xcresult
artifactname: SpeziViews-watchOS.xcresult
buildandtest_visionos:
Expand Down
3 changes: 1 addition & 2 deletions Sources/SpeziValidation/ValidationRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ public struct ValidationRule: Identifiable, Sendable, Equatable {
let effect: CascadingValidationEffect


// swiftlint:disable:next function_default_parameter_at_end
init(
id: UUID = UUID(),
id: UUID = UUID(), // swiftlint:disable:this function_default_parameter_at_end
ruleClosure: @escaping @Sendable (String) -> Bool,
message: LocalizedStringResource,
effect: CascadingValidationEffect = .continue
Expand Down
12 changes: 6 additions & 6 deletions Sources/SpeziViews/Views/Button/AsyncButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ public struct AsyncButton<Label: View>: View {
/// It may also be used to externally control or observe the button's processing state.
/// - action: An asynchronous button action.
@_disfavoredOverload
public init<Title: StringProtocol>( // swiftlint:disable:this function_default_parameter_at_end
public init<Title: StringProtocol>(
_ title: Title,
role: ButtonRole? = nil,
role: ButtonRole? = nil, // swiftlint:disable:this function_default_parameter_at_end
state: Binding<ViewState>,
action: @MainActor @escaping () async throws -> Void
) where Label == Text {
Expand All @@ -140,9 +140,9 @@ public struct AsyncButton<Label: View>: View {
/// - state: A ``ViewState`` binding that it used to propagate any error caught in the button action.
/// It may also be used to externally control or observe the button's processing state.
/// - action: An asynchronous button action.
public init( // swiftlint:disable:this function_default_parameter_at_end
public init(
_ title: LocalizedStringResource,
role: ButtonRole? = nil,
role: ButtonRole? = nil, // swiftlint:disable:this function_default_parameter_at_end
state: Binding<ViewState>,
action: @MainActor @escaping () async throws -> Void
) where Label == Text {
Expand All @@ -158,8 +158,8 @@ public struct AsyncButton<Label: View>: View {
/// It may also be used to externally control or observe the button's processing state.
/// - action: An asynchronous button action.
/// - label: The Button label.
public init( // swiftlint:disable:this function_default_parameter_at_end
role: ButtonRole? = nil,
public init(
role: ButtonRole? = nil, // swiftlint:disable:this function_default_parameter_at_end
state: Binding<ViewState>,
action: @MainActor @escaping () async throws -> Void,
@ViewBuilder label: () -> Label
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ public struct HorizontalGeometryReader<Content: View>: View {
}
)
.onPreferenceChange(WidthPreferenceKey.self) { width in
self.width = width
// The `onPreferenceChange` view modfier now takes a `@Sendable` closure, therefore we cannot capture `@MainActor` isolated properties
// on the `View` directly anymore: https://developer.apple.com/documentation/swiftui/view/onpreferencechange(_:perform:)?changes=latest_minor
// However, as the `@Sendable` closure is still run on the MainActor (at least in my testing on 18.2 RC SDKs), we can use `MainActor.assumeIsolated`
// to avoid scheduling a `MainActor` `Task`, which could delay execution and cause unexpected UI behavior.
MainActor.assumeIsolated {
philippzagar marked this conversation as resolved.
Show resolved Hide resolved
self.width = width
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion Tests/UITests/TestApp/ViewsTests/CanvasTestView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ struct CanvasTestView: View {
}
.navigationBarTitleDisplayMode(.inline)
.onPreferenceChange(CanvasView.CanvasSizePreferenceKey.self) { size in
self.receivedSize = size
// See `HorizontalGeometryReader.swift`
MainActor.assumeIsolated {
self.receivedSize = size
}
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions Tests/UITests/UITests.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2,3,7";
};
name = Debug;
Expand Down Expand Up @@ -606,7 +606,7 @@
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2,3,7";
};
name = Release;
Expand All @@ -629,7 +629,7 @@
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2,7";
TEST_TARGET_NAME = TestApp;
};
Expand All @@ -652,7 +652,7 @@
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2,7";
TEST_TARGET_NAME = TestApp;
};
Expand Down Expand Up @@ -753,7 +753,7 @@
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2,3,7";
};
name = Test;
Expand All @@ -776,7 +776,7 @@
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2,7";
TEST_TARGET_NAME = TestApp;
};
Expand Down
Loading