Skip to content

Commit

Permalink
Fixes an issue where ScrollPageViewStyle may perform an unnecessary r…
Browse files Browse the repository at this point in the history
…edraw on iOS.

Fixes an issue in ExampleGridToPageView where the aspect ratio wouldn't be respected during transition.
  • Loading branch information
Phillip Caudell committed Nov 28, 2023
1 parent 0bf239b commit d546c84
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
17 changes: 12 additions & 5 deletions Sources/BigUIPaging/Examples/ExampleGridToPageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit d546c84

Please sign in to comment.