Skip to content

Commit

Permalink
Ensure updates are on the main thread onPreferenceChange.
Browse files Browse the repository at this point in the history
  • Loading branch information
anthereum authored Sep 16, 2021
1 parent 3ddaa02 commit f912cfc
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Sources/PartialSheet/PartialSheetViewModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ struct PartialSheet: ViewModifier {
notifier.removeObserver(self)
}
.onPreferenceChange(PresenterPreferenceKey.self, perform: { (prefData) in
self.presenterContentRect = prefData.first?.bounds ?? .zero
DispatchQueue.main.async {
self.presenterContentRect = prefData.first?.bounds ?? .zero
}
})
}
// if the device type is not an iPhone,
Expand Down Expand Up @@ -234,8 +236,10 @@ extension PartialSheet {
Spacer()
}
.onPreferenceChange(SheetPreferenceKey.self, perform: { (prefData) in
withAnimation(manager.defaultAnimation) {
self.sheetContentRect = prefData.first?.bounds ?? .zero
DispatchQueue.main.async {
withAnimation(manager.defaultAnimation) {
self.sheetContentRect = prefData.first?.bounds ?? .zero
}
}
})
.frame(width: UIScreen.main.bounds.width)
Expand Down

0 comments on commit f912cfc

Please sign in to comment.