A lightweight paging view solution for SwiftUI

Today, I was going through some research on a cross-platform paging view library and it got me thinking: what if we could create a paging view library that would work on both iOS and OSX? Obviously, this library would be limited to the functionality of a simple paging view, but it would be a very useful addition to the SwiftUI and UIKit toolchains and allow for creating something more than just a simple list.

As far as I know, there’s no rich UI component that has a paging view (for showing data in multiple pages). So I created SwiftUi PagingViewController to implement one, and this is the story of the journey.

When it comes to applications, there are many different views in which to see what is happening. Some views are more useful than others, but most are just temporary holding bins for the most recent data you have added.  One of these is typically a paging view.  A paging view allows you to view the last  items you have added to your  list of  items,  while the  main view  is  currently  on  screen.  This  can be  really  useful  for  viewing  overview  trends  and  the most  recent  data  added

1630627476_150_A-lightweight-paging-view-solution-for-SwiftUI

The First Steps | Personalization | Setup

1630627479_914_A-lightweight-paging-view-solution-for-SwiftUI

art-demo onboarding-demo book-preview

Getting Started

The fundamentals

It’s as simple as this to use Pages:

Pages struct import @State var index: Int = 0 WelcomeView: View body variable: some View Pages ($index)(currentPage: $index)(currentPage: $index)(currentPage: $index)(current { Text(“Welcome! This is the first page “( a text (“This is Page 2”) Circle() / The 4th page is a Circle Text(“…and this is Page 3”) Text(“…and this is Page 3”) Text(“…and this is Page 3”) Text(“…and this is Page 3”) Text(“…and this is Page 3”)

Pages with dynamic content may also be used:

Pages to Import var model: String struct Car struct CarsView: This is a view of cars. let vehicles = [Car(model: “Ferrari”), Car(model: “Ford”)] @State Int = 0 for index body variable: some View ModelPages(cars, currentPage: $index, currentPage: $index, currentPage: $index, currentPage: $index, currentPage: text(“The (pageIndex) car is a (car.model)”), pageIndex, car in Text(“The (pageIndex) car is a (car.model)”), pageIndex, car in Text(“The (pageIndex) car is a padding(50) padding(50) padding(50) padding(50) padding(50 foregroundColor(.white) is the color of the foreground. (Color.blue) as a backdrop. cornerRadius(10)

How does it work?

While Pages utilizes a UIPageViewController behind the hood, it uses a function builder to get a SwiftUI feel. The current maximum for adding pages in a static manner using the Pages view is ten, same like in VStack or HStack. Use a ModelPages instead if more are required. The Pages view will take up all of the space allocated to it.

Note that the Pages view requires several pages. Otherwise, the compiler considers the contents of Pages to be a closure.

Customization

Pages may be modified in the following ways:

  • navigation Whether to paginate horizontally or vertically is determined on the orientation. The default value is.horizontal.

a few pages (navigationOrientation: .vertical) Text(“Page 1”), Text(“Page 2”), Text(“Page 3”), Text(“Page 4”), Text(“Page 5”), Text(“

  • On page turn, choose whether to execute a page curl or a scroll effect. In the GIFs above, the first two instances utilize a scroll effect, while the final one uses page curl. .scroll is the default.

Navigation (pages) (.pageCurl,.vertical,.vertical,.vertical,.vertical,.vertical,.vertical,.vertical,.vertical,.vertical,.vertical Text(“Page 1”), Text(“Page 2”), Text(“Page 3”), Text(“Page 4”), Text(“Page 5”), Text(“

  • If the user attempts to scroll beyond the amount of pages, a bounce effect will be applied. True is the default value.

Navigation (pages) bounce: false,.vertical, transitionStyle:.pageCurl, Orientation:.vertical) Message (“Page 1”) a text(“Page 2”) a text(“Page 2”) a text(“Page

  • wrap: Whether or not to wrap the pages when a user attempts to go on to the next page after leaving the previous one. Similarly, when the user goes to the previous page of the first page, whether to proceed to the final page. The default value is false.

Navigation (pages) Transition:.vertical, orientation:.vertical, orientation:.vertical, orientation:.vertical, orientation:. bounce: false, wrap: true ) Style:.pageCurl, bounce: false, wrap: true ) Message (“Page 1”) a text(“Page 2”) a text(“Page 2”) a text(“Page

  • hasControl: Whether or not to show a page control. True is the default value.

Navigation (pages) bounce: false, wrap: true, hasControl: false) Orientation:.vertical, transitionStyle:.pageCurl, bounce: false, wrap: true, hasControl: false) Message (“Page 1”) a text(“Page 2”) a text(“Page 2”) a text(“Page

  • If you wish to adjust it, you may utilize a user-defined control. The traditional iOS page control will be utilized if this parameter is not supplied and hasControl is true. UIPageControl must be followed while controlling notes.

Navigation (pages) TransitionStyle:.page, Orientation:.vertical Curl, bounce: false, wrap: true, MyPageControl() control) Message (“Page 1”) a text(“Page 2”) a text(“Page 2”) a text(“Page

  • control Alignment: Where should the page control be placed inside Pages? .bottom is the default value.

Navigation (pages) Transition:.vertical, orientation:.vertical, orientation:.vertical, orientation:.vertical, orientation:. control,.pageCurl, bounce: false, wrap: true, style:.pageCurl .topLeading ) Alignment Message (“Page 1”) a text(“Page 2”) a text(“Page 2”) a text(“Page

FAQ

Demos

The demo repo contains all of the demonstrations shown in the GIF.

Installation

Using the Swift Package Manager, you can get Pages:

Using Xcode 11, go to File -> Swift Packages -> Add Package Dependency and enter https://github.com/nachonavarro/Pages

Executing the tests

To run the tests, hit U after selecting an iPhone target in Xcode. Alternatively, use the terminal to execute xcodebuild test -destination ‘name=iPhone 11’ -scheme ‘Pages’.

Requirements

TODOs

  • Unit and UI tests should be included.
  • Conditional clauses should be added to the function constructor.
  • Is it possible to combine ModelPages and Pages into a single view?

Contributing

Contribute to Pages if you’d like!

  1. Pages that have been forked
  2. Create a feature branch using the modifications you’ve made.
  3. Make a pull request

License

The MIT license governs the use of Pages. For additional information, see the LICENSE.

GitHub

https://github.com/nachonavarro/Pages

SwiftUI is a lightweight UI framework for iOS written in Swift. It is designed to be simple yet powerful, and follows the MVVM pattern. It also can be used in other platforms.. Read more about swiftui infinite horizontal scroll and let us know what you think.

Related Tags

  • swiftui vertical paging
  • swiftui pagination
  • swiftui lazyvstack paging
  • scrollview proxy swiftui
  • swiftui lazyvgrid paging
Scroll to Top