diff --git a/Package.swift b/Package.swift index 5e95044d9..6d2fc9657 100644 --- a/Package.swift +++ b/Package.swift @@ -25,7 +25,9 @@ let package = Package( .library(name: "ResearchKitSwiftUI", targets: ["ResearchKitSwiftUI"]), .library(name: "ResearchKitSwiftUIBridge", targets: ["ResearchKitSwiftUIBridge"]) ], - dependencies: [] + swiftLintPackage(), + dependencies: [ + .package(url: "https://github.com/StanfordSpezi/SpeziFoundation.git", from: "2.0.1"), + ] + swiftLintPackage(), targets: [ .binaryTarget( name: "ResearchKit", @@ -42,7 +44,8 @@ let package = Package( .target( name: "ResearchKitSwiftUI", dependencies: [ - .target(name: "ResearchKit") + .target(name: "ResearchKit"), + .product(name: "SpeziFoundation", package: "SpeziFoundation") ], path: "ResearchKitSwiftUI" ), diff --git a/ResearchKitSwiftUI/ResearchForm.swift b/ResearchKitSwiftUI/ResearchForm.swift index b2eee61ed..a6276c50d 100644 --- a/ResearchKitSwiftUI/ResearchForm.swift +++ b/ResearchKitSwiftUI/ResearchForm.swift @@ -28,6 +28,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import SpeziFoundation import SwiftUI /// Manages the navigation between steps in a survey. @@ -169,16 +170,20 @@ public struct ResearchFormStep: View { question } } - .onPreferenceChange(QuestionRequiredPreferenceKey.self) { - if $0 == true { - requiredQuestions.insert(question.id) + .onPreferenceChange(QuestionRequiredPreferenceKey.self) { value in + runOrScheduleOnMainActor { + if value { + requiredQuestions.insert(question.id) + } } } - .onPreferenceChange(QuestionAnsweredPreferenceKey.self) { - if $0 == true { - answeredQuestions.insert(question.id) - } else { - answeredQuestions.remove(question.id) + .onPreferenceChange(QuestionAnsweredPreferenceKey.self) { value in + runOrScheduleOnMainActor { + if value { + answeredQuestions.insert(question.id) + } else { + answeredQuestions.remove(question.id) + } } } .onAppear { @@ -197,9 +202,10 @@ public struct ResearchFormStep: View { #if os(iOS) .frame(maxWidth: .infinity, alignment: .leading) #endif - .onPreferenceChange(QuestionCardPreferenceKey.self) { - shouldWrapInQuestionCard in - self.shouldWrapInQuestionCard = shouldWrapInQuestionCard + .onPreferenceChange(QuestionCardPreferenceKey.self) { shouldWrapInQuestionCard in + runOrScheduleOnMainActor { + self.shouldWrapInQuestionCard = shouldWrapInQuestionCard + } } } diff --git a/ResearchKitSwiftUI/ResearchFormStepContentView.swift b/ResearchKitSwiftUI/ResearchFormStepContentView.swift index 83c5f7064..76200d66a 100644 --- a/ResearchKitSwiftUI/ResearchFormStepContentView.swift +++ b/ResearchKitSwiftUI/ResearchFormStepContentView.swift @@ -28,6 +28,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import SpeziFoundation import SwiftUI struct ResearchFormStepContentView: View { @@ -55,8 +56,10 @@ struct ResearchFormStepContentView: View { var body: some View { StickyScrollView { content - .onPreferenceChange(StepCompletedPreferenceKey.self) { - doneButtonEnabled = $0 + .onPreferenceChange(StepCompletedPreferenceKey.self) { value in + runOrScheduleOnMainActor { + doneButtonEnabled = value + } } .padding() #if !os(watchOS) diff --git a/ResearchKitSwiftUI/ResearchKitSwiftUI/Step Views/Question Views/Supporting Views/StickyScrollView.swift b/ResearchKitSwiftUI/ResearchKitSwiftUI/Step Views/Question Views/Supporting Views/StickyScrollView.swift index 4d4948729..cb568c360 100644 --- a/ResearchKitSwiftUI/ResearchKitSwiftUI/Step Views/Question Views/Supporting Views/StickyScrollView.swift +++ b/ResearchKitSwiftUI/ResearchKitSwiftUI/Step Views/Question Views/Supporting Views/StickyScrollView.swift @@ -28,6 +28,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import SpeziFoundation import SwiftUI /// A vertical ScrollView with a sticky footer, that returns to flow inline if @@ -224,19 +225,25 @@ struct StickyScrollView: View { } .coordinateSpace(name: scrollCoordinateSpace) .onPreferenceChange(FrameSizeKey.self) { value in - self.frameSize = value + runOrScheduleOnMainActor { + self.frameSize = value + } } .onPreferenceChange(SafeAreaInsetsKey.self) { value in - self.safeAreaInsets = value + runOrScheduleOnMainActor { + self.safeAreaInsets = value + } } .onPreferenceChange(KeyboardIgnoringSafeAreaInsets.self) { value in - self.keyboardIgnoringSafeAreaInsets = value + runOrScheduleOnMainActor { + self.keyboardIgnoringSafeAreaInsets = value + } } - .onPreferenceChange( - BodySizeKey.self, - perform: { value in + .onPreferenceChange(BodySizeKey.self) { value in + runOrScheduleOnMainActor { self.bodySize = value - }) + } + } } } }