Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Sources/SwiftUIPager/Helpers/View+Helper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,13 @@ extension View {
func eraseToAny() -> AnyView {
AnyView(self)
}


@ViewBuilder
func `if`<Content: View>(_ conditional: Bool, content: (Self) -> Content) -> some View {
if conditional {
content(self)
} else {
self
}
}
}
7 changes: 7 additions & 0 deletions Sources/SwiftUIPager/Pager+Buildable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions Sources/SwiftUIPager/Pager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ public struct Pager<Element, ID, PageView>: 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
Expand Down Expand Up @@ -155,7 +158,7 @@ public struct Pager<Element, ID, PageView>: 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)?

Expand Down Expand Up @@ -190,7 +193,9 @@ public struct Pager<Element, ID, PageView>: View where PageView: View, Element:
GeometryReader { proxy in
self.content(for: proxy.size)
}
.clipped()
.if(isClipped) {
$0.clipped()
}
}

func content(for size: CGSize) -> PagerContent {
Expand Down Expand Up @@ -250,7 +255,6 @@ public struct Pager<Element, ID, PageView>: View where PageView: View, Element:

return pagerContent
}

}

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
Expand Down