From d546c84a2c124334463e779524890fb81b78f9d3 Mon Sep 17 00:00:00 2001 From: Phillip Caudell Date: Tue, 28 Nov 2023 15:26:09 +0000 Subject: [PATCH] Fixes an issue where ScrollPageViewStyle may perform an unnecessary redraw on iOS. Fixes an issue in ExampleGridToPageView where the aspect ratio wouldn't be respected during transition. --- .../Examples/ExampleGridToPageView.swift | 17 ++++++++++++----- .../Platform/PlatformPageView+iOS.swift | 12 +++++++----- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Sources/BigUIPaging/Examples/ExampleGridToPageView.swift b/Sources/BigUIPaging/Examples/ExampleGridToPageView.swift index 16afd24..1b605b9 100644 --- a/Sources/BigUIPaging/Examples/ExampleGridToPageView.swift +++ b/Sources/BigUIPaging/Examples/ExampleGridToPageView.swift @@ -25,10 +25,13 @@ struct ExampleGridToPageView: View { Color.clear } else { ExampleCardPage(value: id) - .aspectRatio(0.7, contentMode: .fit) - // Keep the selected card on top + // Keep the selected card on top .zIndex(id == selection ? 100 : 0.0) - .matchedGeometryEffect(id: id, in: transition) + .matchedGeometryEffect( + id: id, + in: transition + ) + .aspectRatio(1.0, contentMode: .fit) .onTapGesture { // Keep track of which card we opened with so // we know if user has swiped in PageView. @@ -66,9 +69,12 @@ struct ExampleGridToPageView: View { } .pageViewStyle(.scroll) .pageViewSpacing(15) - .aspectRatio(0.7, contentMode: .fit) .cardMask() - .matchedGeometryEffect(id: selection, in: transition) + .matchedGeometryEffect( + id: selection, + in: transition + ) + .aspectRatio(0.7, contentMode: .fit) .dragToDismiss($isOpen, progress: $dismissProgress) // We need a transition to prevent the opacity transition. // Scale works, but for whatever reason 1.0 gives us a flash. @@ -78,6 +84,7 @@ struct ExampleGridToPageView: View { } } } +// .animation(.easeInOut(duration: 2), value: isOpen) .animation(.spring(response: 0.4, dampingFraction: 0.8), value: isOpen) #if os(macOS) .frame(minWidth: 300, minHeight: 300) diff --git a/Sources/BigUIPaging/Implementations/PageView/Platform/PlatformPageView+iOS.swift b/Sources/BigUIPaging/Implementations/PageView/Platform/PlatformPageView+iOS.swift index 72ece7e..47abb88 100644 --- a/Sources/BigUIPaging/Implementations/PageView/Platform/PlatformPageView+iOS.swift +++ b/Sources/BigUIPaging/Implementations/PageView/Platform/PlatformPageView+iOS.swift @@ -29,11 +29,13 @@ extension PlatformPageView: UIViewControllerRepresentable { context: Context ) { let isAnimated = context.transaction.animation != nil - context.coordinator.go( - to: selection, - in: pageViewController, - animated: isAnimated - ) + DispatchQueue.main.async { + context.coordinator.go( + to: selection, + in: pageViewController, + animated: isAnimated + ) + } fixNavigationControllerContentScrollView(pageViewController) }