diff --git a/Sources/SpeziViews/Views/Layout/HorizontalGeometryReader.swift b/Sources/SpeziViews/Views/Layout/HorizontalGeometryReader.swift index c2a3011..bb618dd 100644 --- a/Sources/SpeziViews/Views/Layout/HorizontalGeometryReader.swift +++ b/Sources/SpeziViews/Views/Layout/HorizontalGeometryReader.swift @@ -39,7 +39,13 @@ public struct HorizontalGeometryReader: 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 { + self.width = width + } } } diff --git a/Tests/UITests/TestApp/ViewsTests/CanvasTestView.swift b/Tests/UITests/TestApp/ViewsTests/CanvasTestView.swift index 9a9eafc..f56bd36 100644 --- a/Tests/UITests/TestApp/ViewsTests/CanvasTestView.swift +++ b/Tests/UITests/TestApp/ViewsTests/CanvasTestView.swift @@ -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 + } } } } diff --git a/Tests/UITests/UITests.xcodeproj/project.pbxproj b/Tests/UITests/UITests.xcodeproj/project.pbxproj index 0ec3d25..e0036d2 100644 --- a/Tests/UITests/UITests.xcodeproj/project.pbxproj +++ b/Tests/UITests/UITests.xcodeproj/project.pbxproj @@ -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; @@ -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; @@ -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; }; @@ -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; }; @@ -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; @@ -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; };