Skip to content

Commit f912cfc

Browse files
authored
Ensure updates are on the main thread onPreferenceChange.
1 parent 3ddaa02 commit f912cfc

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Sources/PartialSheet/PartialSheetViewModifier.swift

+7-3
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ struct PartialSheet: ViewModifier {
128128
notifier.removeObserver(self)
129129
}
130130
.onPreferenceChange(PresenterPreferenceKey.self, perform: { (prefData) in
131-
self.presenterContentRect = prefData.first?.bounds ?? .zero
131+
DispatchQueue.main.async {
132+
self.presenterContentRect = prefData.first?.bounds ?? .zero
133+
}
132134
})
133135
}
134136
// if the device type is not an iPhone,
@@ -234,8 +236,10 @@ extension PartialSheet {
234236
Spacer()
235237
}
236238
.onPreferenceChange(SheetPreferenceKey.self, perform: { (prefData) in
237-
withAnimation(manager.defaultAnimation) {
238-
self.sheetContentRect = prefData.first?.bounds ?? .zero
239+
DispatchQueue.main.async {
240+
withAnimation(manager.defaultAnimation) {
241+
self.sheetContentRect = prefData.first?.bounds ?? .zero
242+
}
239243
}
240244
})
241245
.frame(width: UIScreen.main.bounds.width)

0 commit comments

Comments
 (0)