From 2a6f2dfb20b587574242a9bed0b7d2d126813382 Mon Sep 17 00:00:00 2001 From: Fernando Moya de Rivas Date: Wed, 22 Jan 2020 17:06:23 +0000 Subject: [PATCH 01/10] Storing page offset instead of content offset --- Sources/SwiftUIPager/Pager+Buildable.swift | 7 +++---- Sources/SwiftUIPager/Pager+Helper.swift | 5 +++++ Sources/SwiftUIPager/Pager.swift | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Sources/SwiftUIPager/Pager+Buildable.swift b/Sources/SwiftUIPager/Pager+Buildable.swift index 5bee404..68523a1 100644 --- a/Sources/SwiftUIPager/Pager+Buildable.swift +++ b/Sources/SwiftUIPager/Pager+Buildable.swift @@ -39,10 +39,9 @@ extension Pager: Buildable { .mutating(keyPath: \.shouldRotate, value: value) } - /// Provides an offset to modify the - public func contentOffset(_ pageOffset: Double) -> Self { - let contentOffset = CGFloat(pageOffset) * pageDistance - return mutating(keyPath: \.contentOffset, value: contentOffset) + /// Provides an increment to the page index offset. Use this to modify the scroll offset + public func pageOffset(_ pageOffset: Double) -> Self { + mutating(keyPath: \.pageOffset, value: pageOffset) } /// Adds space between each page diff --git a/Sources/SwiftUIPager/Pager+Helper.swift b/Sources/SwiftUIPager/Pager+Helper.swift index 4731442..9db67ec 100644 --- a/Sources/SwiftUIPager/Pager+Helper.swift +++ b/Sources/SwiftUIPager/Pager+Helper.swift @@ -15,6 +15,11 @@ extension Pager { return !isHorizontal } + /// `pageOffset` converted to scrollable offset + var contentOffset: CGFloat { + CGFloat(pageOffset) * pageDistance + } + /// Size increment to be applied to a unfocs item when it comes to focus var scaleIncrement: CGFloat { 1 - interactiveScale } diff --git a/Sources/SwiftUIPager/Pager.swift b/Sources/SwiftUIPager/Pager.swift index b2947e9..540e658 100644 --- a/Sources/SwiftUIPager/Pager.swift +++ b/Sources/SwiftUIPager/Pager.swift @@ -74,7 +74,7 @@ public struct Pager: View where Content: View, Data: Identifiabl var shouldRotate: Bool = false /// Used to modify `Pager` offset outside this view - var contentOffset: CGFloat = 0 + var pageOffset: Double = 0 /// Vertical padding var sideInsets: CGFloat = 0 From ea5a327609312682247287ea0afde35498502618 Mon Sep 17 00:00:00 2001 From: Fernando Moya de Rivas Date: Thu, 23 Jan 2020 09:40:08 +0000 Subject: [PATCH 02/10] Changing direction of offset --- Sources/SwiftUIPager/Pager+Helper.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SwiftUIPager/Pager+Helper.swift b/Sources/SwiftUIPager/Pager+Helper.swift index 9db67ec..1a5038d 100644 --- a/Sources/SwiftUIPager/Pager+Helper.swift +++ b/Sources/SwiftUIPager/Pager+Helper.swift @@ -17,7 +17,7 @@ extension Pager { /// `pageOffset` converted to scrollable offset var contentOffset: CGFloat { - CGFloat(pageOffset) * pageDistance + -CGFloat(pageOffset) * pageDistance } /// Size increment to be applied to a unfocs item when it comes to focus From 9a4ced56c49c9182d90f9c2371e831d70bdf7d5c Mon Sep 17 00:00:00 2001 From: Fernando Moya de Rivas Date: Thu, 23 Jan 2020 10:15:28 +0000 Subject: [PATCH 03/10] Limitting size updates --- Sources/SwiftUIPager/Helpers/SizeViewModifier.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sources/SwiftUIPager/Helpers/SizeViewModifier.swift b/Sources/SwiftUIPager/Helpers/SizeViewModifier.swift index b4a9057..47509ac 100644 --- a/Sources/SwiftUIPager/Helpers/SizeViewModifier.swift +++ b/Sources/SwiftUIPager/Helpers/SizeViewModifier.swift @@ -13,7 +13,11 @@ struct SizePreferenceKey: PreferenceKey { static var defaultValue: CGSize = .zero static func reduce(value: inout CGSize, nextValue: () -> CGSize) { - value = nextValue() + let newValue = nextValue() + print("newvalue: \(newValue)") + guard value != newValue else { return } + print("updated") + value = newValue } } From f6abdcfc71372dd0e35e90c9cc9ebe8a421f944b Mon Sep 17 00:00:00 2001 From: Fernando Moya de Rivas Date: Thu, 23 Jan 2020 10:19:17 +0000 Subject: [PATCH 04/10] Moving onPreferenceChanged --- Sources/SwiftUIPager/Helpers/SizeViewModifier.swift | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Sources/SwiftUIPager/Helpers/SizeViewModifier.swift b/Sources/SwiftUIPager/Helpers/SizeViewModifier.swift index 47509ac..122ec72 100644 --- a/Sources/SwiftUIPager/Helpers/SizeViewModifier.swift +++ b/Sources/SwiftUIPager/Helpers/SizeViewModifier.swift @@ -14,9 +14,7 @@ struct SizePreferenceKey: PreferenceKey { static func reduce(value: inout CGSize, nextValue: () -> CGSize) { let newValue = nextValue() - print("newvalue: \(newValue)") guard value != newValue else { return } - print("updated") value = newValue } } @@ -31,10 +29,10 @@ struct SizeViewModifier: ViewModifier { content .preference(key: SizePreferenceKey.self, value: proxy.size) + .onPreferenceChange(SizePreferenceKey.self, perform: { (newSize) in + self.size = newSize + }) } - .onPreferenceChange(SizePreferenceKey.self, perform: { (newSize) in - self.size = newSize - }) .clipped() } } From 8f0c84eb02b0952dc3253acb526fe1599ef8c29e Mon Sep 17 00:00:00 2001 From: Fernando Moya de Rivas Date: Thu, 23 Jan 2020 10:25:46 +0000 Subject: [PATCH 05/10] Revert previous commit --- Sources/SwiftUIPager/Helpers/SizeViewModifier.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/SwiftUIPager/Helpers/SizeViewModifier.swift b/Sources/SwiftUIPager/Helpers/SizeViewModifier.swift index 122ec72..4f04156 100644 --- a/Sources/SwiftUIPager/Helpers/SizeViewModifier.swift +++ b/Sources/SwiftUIPager/Helpers/SizeViewModifier.swift @@ -29,10 +29,10 @@ struct SizeViewModifier: ViewModifier { content .preference(key: SizePreferenceKey.self, value: proxy.size) - .onPreferenceChange(SizePreferenceKey.self, perform: { (newSize) in - self.size = newSize - }) } + .onPreferenceChange(SizePreferenceKey.self, perform: { (newSize) in + self.size = newSize + }) .clipped() } } From 1baa9dc59fa3418e5326413c224dbc788cb616f9 Mon Sep 17 00:00:00 2001 From: Fernando Moya de Rivas Date: Thu, 23 Jan 2020 13:57:41 +0000 Subject: [PATCH 06/10] Fixing issues with Pager inside ScrollView --- Sample/ContentView.swift | 46 ++++++++++--------- .../Helpers/SizeViewModifier.swift | 7 +-- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/Sample/ContentView.swift b/Sample/ContentView.swift index 65eec2a..18e5a55 100644 --- a/Sample/ContentView.swift +++ b/Sample/ContentView.swift @@ -20,28 +20,30 @@ struct ContentView: View { var body: some View { GeometryReader { proxy in - VStack { - Pager(page: self.$pageIndex, - data: self.data, - content: { index in - self.pageView(index) - .cornerRadius(10) - .shadow(radius: 5) - }) - .interactive(0.8) - .itemSpacing(10) - .padding(8) - .itemAspectRatio(1.5) - .vertical() - .border(Color.red, width: 2) - .frame(width: min(proxy.size.width, - proxy.size.height), - height: min(proxy.size.width, - proxy.size.height)) - Spacer() - Text("Page: \(self.pageIndex)") - .bold() - Spacer() + ScrollView { + VStack { + Pager(page: self.$pageIndex, + data: self.data, + content: { index in + self.pageView(index) + .cornerRadius(10) + .shadow(radius: 5) + }) + .interactive(0.8) + .itemSpacing(10) + .padding(8) + .itemAspectRatio(1.5) + .frame(width: min(proxy.size.width, + proxy.size.height), + height: min(proxy.size.width, + proxy.size.height)) + .border(Color.red, width: 2) + ForEach(self.data) { i in + Text("Page: \(i)") + .bold() + .padding() + } + } } } } diff --git a/Sources/SwiftUIPager/Helpers/SizeViewModifier.swift b/Sources/SwiftUIPager/Helpers/SizeViewModifier.swift index 4f04156..50cbbc4 100644 --- a/Sources/SwiftUIPager/Helpers/SizeViewModifier.swift +++ b/Sources/SwiftUIPager/Helpers/SizeViewModifier.swift @@ -29,10 +29,11 @@ struct SizeViewModifier: ViewModifier { content .preference(key: SizePreferenceKey.self, value: proxy.size) + .frame(width: proxy.size.width, height: proxy.size.height) + .onAppear (perform: { + self.size = proxy.size + }) } - .onPreferenceChange(SizePreferenceKey.self, perform: { (newSize) in - self.size = newSize - }) .clipped() } } From 6d0cd89cb735d30e372ea0d0f818f792b99cf2f7 Mon Sep 17 00:00:00 2001 From: Fernando Moya de Rivas Date: Thu, 23 Jan 2020 13:59:52 +0000 Subject: [PATCH 07/10] Referencing to last branch --- Sample.xcodeproj/project.pbxproj | 16 ++++++++-------- .../xcshareddata/swiftpm/Package.resolved | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Sample.xcodeproj/project.pbxproj b/Sample.xcodeproj/project.pbxproj index 73a2468..e71575e 100644 --- a/Sample.xcodeproj/project.pbxproj +++ b/Sample.xcodeproj/project.pbxproj @@ -13,7 +13,7 @@ 17D9E0FA23D4CF6900C5AE93 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 17D9E0F923D4CF6900C5AE93 /* Assets.xcassets */; }; 17D9E0FD23D4CF6900C5AE93 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 17D9E0FC23D4CF6900C5AE93 /* Assets.xcassets */; }; 17D9E10023D4CF6900C5AE93 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 17D9E0FE23D4CF6900C5AE93 /* LaunchScreen.storyboard */; }; - 6B3489BC23D85D46002601D8 /* SwiftUIPager in Frameworks */ = {isa = PBXBuildFile; productRef = 6B3489BB23D85D46002601D8 /* SwiftUIPager */; }; + 6BB892CF23D9DE2100AC9331 /* SwiftUIPager in Frameworks */ = {isa = PBXBuildFile; productRef = 6BB892CE23D9DE2100AC9331 /* SwiftUIPager */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -32,7 +32,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 6B3489BC23D85D46002601D8 /* SwiftUIPager in Frameworks */, + 6BB892CF23D9DE2100AC9331 /* SwiftUIPager in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -94,7 +94,7 @@ ); name = Sample; packageProductDependencies = ( - 6B3489BB23D85D46002601D8 /* SwiftUIPager */, + 6BB892CE23D9DE2100AC9331 /* SwiftUIPager */, ); productName = SwiftUIPager; productReference = 17D9E0F023D4CF6700C5AE93 /* Sample.app */; @@ -125,7 +125,7 @@ ); mainGroup = 17D9E0E723D4CF6700C5AE93; packageReferences = ( - 6B3489BA23D85D46002601D8 /* XCRemoteSwiftPackageReference "SwiftUIPager" */, + 6BB892CD23D9DE2100AC9331 /* XCRemoteSwiftPackageReference "SwiftUIPager" */, ); productRefGroup = 17D9E0F123D4CF6700C5AE93 /* Products */; projectDirPath = ""; @@ -352,20 +352,20 @@ /* End XCConfigurationList section */ /* Begin XCRemoteSwiftPackageReference section */ - 6B3489BA23D85D46002601D8 /* XCRemoteSwiftPackageReference "SwiftUIPager" */ = { + 6BB892CD23D9DE2100AC9331 /* XCRemoteSwiftPackageReference "SwiftUIPager" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/fermoya/SwiftUIPager"; requirement = { - branch = "feat/vertical-pagintation"; + branch = "fix/page-offset"; kind = branch; }; }; /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ - 6B3489BB23D85D46002601D8 /* SwiftUIPager */ = { + 6BB892CE23D9DE2100AC9331 /* SwiftUIPager */ = { isa = XCSwiftPackageProductDependency; - package = 6B3489BA23D85D46002601D8 /* XCRemoteSwiftPackageReference "SwiftUIPager" */; + package = 6BB892CD23D9DE2100AC9331 /* XCRemoteSwiftPackageReference "SwiftUIPager" */; productName = SwiftUIPager; }; /* End XCSwiftPackageProductDependency section */ diff --git a/Sample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Sample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index fcde048..d8f18eb 100644 --- a/Sample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Sample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -5,8 +5,8 @@ "package": "SwiftUIPager", "repositoryURL": "https://github.com/fermoya/SwiftUIPager", "state": { - "branch": "feat/vertical-pagintation", - "revision": "824efeeaac08717ef7d1aefc5037c3e3f32736e6", + "branch": "fix/page-offset", + "revision": "1baa9dc59fa3418e5326413c224dbc788cb616f9", "version": null } } From 80a5e5b57f919ba880d6a21fcb9bf42f9781d6b8 Mon Sep 17 00:00:00 2001 From: Fernando Moya de Rivas Date: Thu, 23 Jan 2020 14:01:39 +0000 Subject: [PATCH 08/10] version 1.1.1 in cocoapods --- SwiftUIPager.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SwiftUIPager.podspec b/SwiftUIPager.podspec index 6c0907f..806c24d 100644 --- a/SwiftUIPager.podspec +++ b/SwiftUIPager.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "SwiftUIPager" - s.version = "1.1.0" + s.version = "1.1.1" s.summary = "Native pager for SwiftUI. Easily to use, easy to customize." s.description = <<-DESC From 3b05829020ec5e10a0997455b2a7fb18dfb4af53 Mon Sep 17 00:00:00 2001 From: Fernando Moya de Rivas Date: Thu, 23 Jan 2020 15:18:51 +0000 Subject: [PATCH 09/10] Fixing gesture collisions --- .../Helpers/SizeViewModifier.swift | 13 -------- Sources/SwiftUIPager/Pager+Buildable.swift | 5 +++ Sources/SwiftUIPager/Pager+Helper.swift | 10 +++--- Sources/SwiftUIPager/Pager.swift | 32 ++++++++++++------- 4 files changed, 31 insertions(+), 29 deletions(-) diff --git a/Sources/SwiftUIPager/Helpers/SizeViewModifier.swift b/Sources/SwiftUIPager/Helpers/SizeViewModifier.swift index 50cbbc4..d678099 100644 --- a/Sources/SwiftUIPager/Helpers/SizeViewModifier.swift +++ b/Sources/SwiftUIPager/Helpers/SizeViewModifier.swift @@ -8,17 +8,6 @@ import SwiftUI -/// Tracks the size of the view -struct SizePreferenceKey: PreferenceKey { - static var defaultValue: CGSize = .zero - - static func reduce(value: inout CGSize, nextValue: () -> CGSize) { - let newValue = nextValue() - guard value != newValue else { return } - value = newValue - } -} - /// This modifier wraps a view into a `GeometryReader` and tracks the available space by using `SizePreferenceKey` on the content struct SizeViewModifier: ViewModifier { @@ -27,8 +16,6 @@ struct SizeViewModifier: ViewModifier { func body(content: Content) -> some View { GeometryReader { proxy in content - .preference(key: SizePreferenceKey.self, - value: proxy.size) .frame(width: proxy.size.width, height: proxy.size.height) .onAppear (perform: { self.size = proxy.size diff --git a/Sources/SwiftUIPager/Pager+Buildable.swift b/Sources/SwiftUIPager/Pager+Buildable.swift index 68523a1..de7397b 100644 --- a/Sources/SwiftUIPager/Pager+Buildable.swift +++ b/Sources/SwiftUIPager/Pager+Buildable.swift @@ -10,6 +10,11 @@ import SwiftUI extension Pager: Buildable { + /// Adds a `TapGesture` to the items to bring them to focus + public func itemTappable(_ value: Bool) -> Self { + mutating(keyPath: \.isItemTappable, value: value) + } + /// Returns a horizontal pager public func horizontal() -> Self { mutating(keyPath: \.isHorizontal, value: true) diff --git a/Sources/SwiftUIPager/Pager+Helper.swift b/Sources/SwiftUIPager/Pager+Helper.swift index 1a5038d..6a2bd5b 100644 --- a/Sources/SwiftUIPager/Pager+Helper.swift +++ b/Sources/SwiftUIPager/Pager+Helper.swift @@ -93,7 +93,7 @@ extension Pager { } /// Data that is being displayed at the moment - var dataDisplayed: [Data] { + var dataDisplayed: [Element] { Array(data[lowerPageDisplayed.. Angle { + func angle(for item: Element) -> Angle { guard shouldRotate else { return .zero } guard let index = data.firstIndex(of: item) else { return .zero } @@ -133,7 +133,7 @@ extension Pager { } /// Axis for the rotations effect - func axis(for item: Data) -> (CGFloat, CGFloat, CGFloat) { + func axis(for item: Element) -> (CGFloat, CGFloat, CGFloat) { guard shouldRotate else { return (0, 0, 0) } guard let index = data.firstIndex(of: item) else { return (0, 0, 0) } @@ -142,7 +142,7 @@ extension Pager { } /// Scale that applies to a particular item - func scale(for item: Data) -> CGFloat { + func scale(for item: Element) -> CGFloat { guard isDragging else { return isFocused(item) ? 1 : interactiveScale } let totalIncrement = abs(totalOffset / pageDistance) @@ -164,7 +164,7 @@ extension Pager { } /// Returns true if the item is focused on the screen. - func isFocused(_ item: Data) -> Bool { + func isFocused(_ item: Element) -> Bool { data.firstIndex(of: item) == currentPage } diff --git a/Sources/SwiftUIPager/Pager.swift b/Sources/SwiftUIPager/Pager.swift index 540e658..81d840e 100644 --- a/Sources/SwiftUIPager/Pager.swift +++ b/Sources/SwiftUIPager/Pager.swift @@ -29,7 +29,7 @@ import SwiftUI /// - 30 px of vertical insets /// - 0.6 shrink ratio for items that aren't focused. /// -public struct Pager: View where Content: View, Data: Identifiable & Equatable { +public struct Pager: View where PageView: View, Element: Identifiable & Equatable { /// `Direction` determines the direction of the swipe gesture enum Direction { @@ -58,13 +58,17 @@ public struct Pager: View where Content: View, Data: Identifiabl /*** Dependencies ***/ /// `ViewBuilder` block to create each page - let content: (Data) -> Content + let content: (Element) -> PageView /// Array of items that will populate each page - var data: [Data] + var data: [Element] /*** ViewModified properties ***/ + /// `true` if items are tapable + var isItemTappable: Bool = false + + /// `true` if the pager is horizontal var isHorizontal: Bool = true /// Shrink ratio that affects the items that aren't focused @@ -111,12 +115,12 @@ public struct Pager: View where Content: View, Data: Identifiabl /// - Parameter page: Binding to the index of the focused page /// - Parameter data: Array of items to populate the content /// - Parameter content: Factory method to build new pages - public init(page: Binding, data: [Data], @ViewBuilder content: @escaping (Data) -> Content) { + public init(page: Binding, data: [Element], @ViewBuilder content: @escaping (Element) -> PageView) { self._page = page self.data = data self.content = content } - + public var body: some View { HStack(spacing: self.interactiveItemSpacing) { ForEach(self.dataDisplayed) { item in @@ -127,11 +131,8 @@ public struct Pager: View where Content: View, Data: Identifiabl axis: (0, 0, 1)) .rotation3DEffect(self.angle(for: item), axis: self.axis(for: item)) - .onTapGesture (perform: { - withAnimation(.spring()) { - self.scrollToItem(item) - } - }) + .gesture(self.tapGesture(for: item)) + .disabled(self.isFocused(item) || !self.isItemTappable) } .offset(x: self.xOffset, y : 0) } @@ -147,11 +148,20 @@ public struct Pager: View where Content: View, Data: Identifiabl extension Pager { /// Helper function to scroll to a specific item. - func scrollToItem(_ item: Data) { + func scrollToItem(_ item: Element) { guard let index = data.firstIndex(of: item) else { return } self.page = index } + func tapGesture(for item: Element) -> some Gesture { + TapGesture(count: 1) + .onEnded({ _ in + withAnimation(.spring()) { + self.scrollToItem(item) + } + }) + } + /// `DragGesture` customized to work with `Pager` var swipeGesture: some Gesture { DragGesture() From ddea9f8ec36596ebf4d4dde74c8090447f87331d Mon Sep 17 00:00:00 2001 From: Fernando Moya de Rivas Date: Thu, 23 Jan 2020 15:39:40 +0000 Subject: [PATCH 10/10] Sample project updated to last version --- Sample.xcodeproj/project.pbxproj | 14 +++++++------- .../xcshareddata/swiftpm/Package.resolved | 2 +- Sample/ContentView.swift | 16 ++++++++++++++-- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Sample.xcodeproj/project.pbxproj b/Sample.xcodeproj/project.pbxproj index e71575e..4f21ba8 100644 --- a/Sample.xcodeproj/project.pbxproj +++ b/Sample.xcodeproj/project.pbxproj @@ -13,7 +13,7 @@ 17D9E0FA23D4CF6900C5AE93 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 17D9E0F923D4CF6900C5AE93 /* Assets.xcassets */; }; 17D9E0FD23D4CF6900C5AE93 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 17D9E0FC23D4CF6900C5AE93 /* Assets.xcassets */; }; 17D9E10023D4CF6900C5AE93 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 17D9E0FE23D4CF6900C5AE93 /* LaunchScreen.storyboard */; }; - 6BB892CF23D9DE2100AC9331 /* SwiftUIPager in Frameworks */ = {isa = PBXBuildFile; productRef = 6BB892CE23D9DE2100AC9331 /* SwiftUIPager */; }; + 6BB892E023D9F13C00AC9331 /* SwiftUIPager in Frameworks */ = {isa = PBXBuildFile; productRef = 6BB892DF23D9F13C00AC9331 /* SwiftUIPager */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -32,7 +32,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 6BB892CF23D9DE2100AC9331 /* SwiftUIPager in Frameworks */, + 6BB892E023D9F13C00AC9331 /* SwiftUIPager in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -94,7 +94,7 @@ ); name = Sample; packageProductDependencies = ( - 6BB892CE23D9DE2100AC9331 /* SwiftUIPager */, + 6BB892DF23D9F13C00AC9331 /* SwiftUIPager */, ); productName = SwiftUIPager; productReference = 17D9E0F023D4CF6700C5AE93 /* Sample.app */; @@ -125,7 +125,7 @@ ); mainGroup = 17D9E0E723D4CF6700C5AE93; packageReferences = ( - 6BB892CD23D9DE2100AC9331 /* XCRemoteSwiftPackageReference "SwiftUIPager" */, + 6BB892DE23D9F13C00AC9331 /* XCRemoteSwiftPackageReference "SwiftUIPager" */, ); productRefGroup = 17D9E0F123D4CF6700C5AE93 /* Products */; projectDirPath = ""; @@ -352,7 +352,7 @@ /* End XCConfigurationList section */ /* Begin XCRemoteSwiftPackageReference section */ - 6BB892CD23D9DE2100AC9331 /* XCRemoteSwiftPackageReference "SwiftUIPager" */ = { + 6BB892DE23D9F13C00AC9331 /* XCRemoteSwiftPackageReference "SwiftUIPager" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/fermoya/SwiftUIPager"; requirement = { @@ -363,9 +363,9 @@ /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ - 6BB892CE23D9DE2100AC9331 /* SwiftUIPager */ = { + 6BB892DF23D9F13C00AC9331 /* SwiftUIPager */ = { isa = XCSwiftPackageProductDependency; - package = 6BB892CD23D9DE2100AC9331 /* XCRemoteSwiftPackageReference "SwiftUIPager" */; + package = 6BB892DE23D9F13C00AC9331 /* XCRemoteSwiftPackageReference "SwiftUIPager" */; productName = SwiftUIPager; }; /* End XCSwiftPackageProductDependency section */ diff --git a/Sample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Sample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index d8f18eb..bea2a7f 100644 --- a/Sample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Sample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -6,7 +6,7 @@ "repositoryURL": "https://github.com/fermoya/SwiftUIPager", "state": { "branch": "fix/page-offset", - "revision": "1baa9dc59fa3418e5326413c224dbc788cb616f9", + "revision": "3b05829020ec5e10a0997455b2a7fb18dfb4af53", "version": null } } diff --git a/Sample/ContentView.swift b/Sample/ContentView.swift index 18e5a55..a631980 100644 --- a/Sample/ContentView.swift +++ b/Sample/ContentView.swift @@ -14,11 +14,22 @@ extension Int: Identifiable { } struct ContentView: View { - + + @State var isPresented: Bool = false @State var pageIndex: Int = 0 var data: [Int] = Array((0...20)) var body: some View { + Button(action: { + self.isPresented.toggle() + }, label: { + Text("Tap me") + }).sheet(isPresented: $isPresented, content: { + self.presentedView + }) + } + + var presentedView: some View { GeometryReader { proxy in ScrollView { VStack { @@ -32,7 +43,8 @@ struct ContentView: View { .interactive(0.8) .itemSpacing(10) .padding(8) - .itemAspectRatio(1.5) + .itemAspectRatio(0.8) + .itemTappable(true) .frame(width: min(proxy.size.width, proxy.size.height), height: min(proxy.size.width,