Hello. I am developing an application using Swift 6 and SwiftUI.
I have custom implemented a BottomSheet that animates from bottom to top, and I attempted to achieve this animation by changing the alignmentGuide like this.
ZStack(alignment: .bottom) { dimView .opacity(isVisible ? 1 : 0) .transaction { transaction in transaction.animation = .easeInOut(duration: 0.35) } bottomSheetView .alignmentGuide(VerticalAlignment.bottom) { dimension in // compile error occur because isVisible property is state of MainActor isolated View! isVisible ? dimension[.bottom] : dimension[.top] } }
There were no issues in Swift 5, but now I am encountering compile errors because the computeValue closure of the alignmentGuide is not isolated to the MainActor, preventing me from calling view state values or functions.
So I am curious if there are any plans to isolate this closure to the MainActor. From my observation, this closure is always called on the main thread.
Thank you.
ZStack(alignment: .bottom) { ..... let isVisible = isVisible // Remove isolation bottomSheetView .alignmentGuide(VerticalAlignment.bottom) { dimension in isVisible ? dimension[.bottom] : dimension[.top] } }
or
.alignmentGuide(VerticalAlignment.bottom) { dimension in _isVisible.wrappedValue ? dimension[.bottom] : dimension[.top] }