diff --git a/Sources/iPages/PageViewController.swift b/Sources/iPages/PageViewController.swift index 49944cd..6c76896 100644 --- a/Sources/iPages/PageViewController.swift +++ b/Sources/iPages/PageViewController.swift @@ -15,12 +15,12 @@ import AppKit struct PageViewController: ControllerRepresentable { var controllers: [ViewController] @Binding var currentPage: Int - private var animated: Bool #if os(iOS) + private var animated: Bool + var wraps: Bool var navigationOrientation: UIPageViewController.NavigationOrientation var bounce: Bool - var wraps: Bool private var interPageSpacing: CGFloat = 0 #endif @@ -81,11 +81,9 @@ struct PageViewController: ControllerRepresentable { } #else init(controllers: [ViewController], - currentPage: Binding, - animated: Bool) { + currentPage: Binding) { self.controllers = controllers self._currentPage = currentPage - self.animated = animated } func makeNSViewController(context: Context) -> NSPageController { @@ -105,16 +103,11 @@ struct PageViewController: ControllerRepresentable { func updateNSViewController(_ nsPageController: NSPageController, context: Context) { context.coordinator.parent = self - if animated { - NSAnimationContext.runAnimationGroup({ NSAnimationContext in - nsPageController.animator().selectedIndex = currentPage - }, completionHandler: { - nsPageController.completeTransition() - }) - } else { - nsPageController.selectedIndex = currentPage + NSAnimationContext.runAnimationGroup({ NSAnimationContext in + nsPageController.animator().selectedIndex = currentPage + }, completionHandler: { nsPageController.completeTransition() - } + }) } #endif } diff --git a/Sources/iPages/iPages+ViewModifiers.swift b/Sources/iPages/iPages+ViewModifiers.swift index 5b7dafb..53bb14c 100644 --- a/Sources/iPages/iPages+ViewModifiers.swift +++ b/Sources/iPages/iPages+ViewModifiers.swift @@ -12,8 +12,6 @@ import UIKit import AppKit #endif -#if os(iOS) - public extension iPages { /// Modifies whether or not the page view should include the standard page control **dots**. (••••) @@ -25,6 +23,7 @@ public extension iPages { return view } + #if os(iOS) /// Modifies whether the page dots are hidden when there is only one page. 1️⃣⤵️ /// - Parameter hide: Whether the page dots are hidden when there is only one page /// - Returns: A page view with the desired dots hiding with one page settings @@ -33,6 +32,7 @@ public extension iPages { view.pageControlHidesForSinglePage = hide return view } + #endif /// Modifies **tint colors** 🟡🟢🔴🟣 to be used for the page dots. /// - Parameters: @@ -42,11 +42,17 @@ public extension iPages { @available(iOS 14, *) func dotsTintColors(currentPage: Color, otherPages: Color) -> iPages { var view = self + #if os(iOS) view.pageControlCurrentPageIndicatorTintColor = UIColor(currentPage) view.pageControlPageIndicatorTintColor = UIColor(otherPages) + #else + view.pageControlCurrentPageIndicatorTintColor = currentPage + view.pageControlPageIndicatorTintColor = otherPages + #endif return view } + #if os(iOS) /// Modifies **tint colors** 🟡🟢🔴🟣 to be used for the page dots. /// - Parameters: /// - currentPage: The tint color to be used for the current page dot ⬇️ @@ -69,7 +75,7 @@ public extension iPages { view.pageControlBackgroundStyle = style return view } - + /// Modifies the continuous interaction settings of the dots. 🔄 /// - Parameter allowContinuousInteraction: Whether the dots allow continuous interaction /// - Returns: A page view with the desired continuous interaction settings of the page dots @@ -79,7 +85,8 @@ public extension iPages { view.pageControlAllowsContinuousInteraction = allowContinuousInteraction return view } - + #endif + /// Modifies the **alignment of the page dots**. 👆 👇 /// /// *Trailing* and *leading* alignments will cause the page dots to rotate vertical @@ -91,6 +98,7 @@ public extension iPages { return view } + #if os(iOS) /// Modifies the navigation **orientation** of the page view. ↔️ ↕️ /// /// By default, moves the page dots to the trailing edge @@ -139,6 +147,5 @@ public extension iPages { view.pageViewAnimated = animated return view } + #endif } - -#endif diff --git a/Sources/iPages/iPages.swift b/Sources/iPages/iPages.swift index b71e94a..7b5ce9e 100644 --- a/Sources/iPages/iPages.swift +++ b/Sources/iPages/iPages.swift @@ -37,16 +37,20 @@ public struct iPages: View { animated: pageViewAnimated) #else return .init(controllers: viewControllers, - currentPage: selection, - animated: pageViewAnimated) + currentPage: selection) #endif } // Page control var pageControlAlignment: Alignment = .bottom - #if os(iOS) var showsPageControl: Bool = true var pageControlHidesForSinglePage: Bool = false + #if os(macOS) + var pageControlCurrentPageIndicatorTintColor: Color? + var pageControlPageIndicatorTintColor: Color? + #endif + + #if os(iOS) var pageControlCurrentPageIndicatorTintColor: UIColor? var pageControlPageIndicatorTintColor: UIColor? private var _pageControlBackgroundStyle: Any? = nil @@ -81,6 +85,14 @@ public struct iPages: View { allowsContinuousInteraction: pageControlAllowsContinuousInteraction) } } + #else + private var ipageControl: iPageControl { + .init(numberOfPages: viewControllers.count, + currentPage: selection, + hidesForSinglePage: pageControlHidesForSinglePage, + pageIndicatorTintColor: pageControlPageIndicatorTintColor, + currentPageIndicatorTintColor: pageControlCurrentPageIndicatorTintColor) + } #endif /// Initializes the page 📃📖 view. 👷‍♀️ @@ -104,24 +116,32 @@ public struct iPages: View { public var body: some View { ZStack(alignment: pageControlAlignment) { pageViewController - #if os(iOS) if showsPageControl { switch pageControlAlignment { case .leading, .trailing: VStack { if pageControlAlignment == .leading { Spacer() } + #if os(iOS) pageControl + #else + ipageControl + #endif if pageControlAlignment == .trailing { Spacer() } } .aspectRatio(1, contentMode: .fit) .rotationEffect(.degrees(layoutDirection ~= .leftToRight ? 90 : -90)) default: + #if os(iOS) pageControl .fixedSize() .padding(.vertical) + #else + ipageControl + .fixedSize() + .padding(.vertical) + #endif } } - #endif } } }