From 0441586bf1f53bae517b2bed22fb4b59d0a6eb20 Mon Sep 17 00:00:00 2001 From: asc-ChoiChef Date: Wed, 5 Apr 2023 14:49:49 +0900 Subject: [PATCH] Add Pager clipped property --- Sources/SwiftUIPager/Helpers/View+Helper.swift | 10 +++++++++- Sources/SwiftUIPager/Pager+Buildable.swift | 7 +++++++ Sources/SwiftUIPager/Pager.swift | 10 +++++++--- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Sources/SwiftUIPager/Helpers/View+Helper.swift b/Sources/SwiftUIPager/Helpers/View+Helper.swift index 1f83302..02bf948 100644 --- a/Sources/SwiftUIPager/Helpers/View+Helper.swift +++ b/Sources/SwiftUIPager/Helpers/View+Helper.swift @@ -18,5 +18,13 @@ extension View { func eraseToAny() -> AnyView { AnyView(self) } - + + @ViewBuilder + func `if`(_ conditional: Bool, content: (Self) -> Content) -> some View { + if conditional { + content(self) + } else { + self + } + } } diff --git a/Sources/SwiftUIPager/Pager+Buildable.swift b/Sources/SwiftUIPager/Pager+Buildable.swift index 49f38f3..87813a6 100644 --- a/Sources/SwiftUIPager/Pager+Buildable.swift +++ b/Sources/SwiftUIPager/Pager+Buildable.swift @@ -288,6 +288,13 @@ extension Pager: Buildable { mutating(keyPath: \.itemSpacing, value: value) } + /// Sets `Pager` is clipped. Defaults to `true` + /// + /// - Parameter value: if `Pager` is clipped + public func isClipped(_ value: Bool) -> Self { + mutating(keyPath: \.isClipped, value: value) + } + /// Configures the aspect ratio of each page. This value is considered to be _width / height_. /// /// - Parameter value: aspect ratio to be applied to the page diff --git a/Sources/SwiftUIPager/Pager.swift b/Sources/SwiftUIPager/Pager.swift index ccb097e..44d6e67 100644 --- a/Sources/SwiftUIPager/Pager.swift +++ b/Sources/SwiftUIPager/Pager.swift @@ -116,6 +116,9 @@ public struct Pager: View where PageView: View, Element: /// `true` if pages should have a 3D rotation effect var shouldRotate: Bool = false + + /// `true` if `Pager` is clipped + var isClipped: Bool = true /// Used to modify `Pager` offset outside this view var pageOffset: Double = 0 @@ -155,7 +158,7 @@ public struct Pager: View where PageView: View, Element: /// Callback invoked when a new page is set var onPageChanged: ((Int) -> Void)? - + /// Callback for a dragging began event var onDraggingBegan: (() -> Void)? @@ -190,7 +193,9 @@ public struct Pager: View where PageView: View, Element: GeometryReader { proxy in self.content(for: proxy.size) } - .clipped() + .if(isClipped) { + $0.clipped() + } } func content(for size: CGSize) -> PagerContent { @@ -250,7 +255,6 @@ public struct Pager: View where PageView: View, Element: return pagerContent } - } @available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)