From f912cfc955728acf00dd5366d443a4b19ae3c464 Mon Sep 17 00:00:00 2001 From: anthereum <87685331+anthereum@users.noreply.github.com> Date: Thu, 16 Sep 2021 18:06:50 +1000 Subject: [PATCH] Ensure updates are on the main thread onPreferenceChange. --- Sources/PartialSheet/PartialSheetViewModifier.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Sources/PartialSheet/PartialSheetViewModifier.swift b/Sources/PartialSheet/PartialSheetViewModifier.swift index 92d61b4..9927451 100644 --- a/Sources/PartialSheet/PartialSheetViewModifier.swift +++ b/Sources/PartialSheet/PartialSheetViewModifier.swift @@ -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, @@ -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)