mirror of
https://github.com/ivanvorobei/SwiftUI.git
synced 2026-03-24 18:31:27 +01:00
34 lines
845 B
Swift
Executable File
34 lines
845 B
Swift
Executable File
/*
|
||
See LICENSE folder for this sample’s licensing information.
|
||
|
||
Abstract:
|
||
A view for bridging a UIPageViewController.
|
||
*/
|
||
|
||
import SwiftUI
|
||
|
||
struct PageView<Page: View>: View {
|
||
var viewControllers: [UIHostingController<Page>]
|
||
@State var currentPage = 0
|
||
|
||
init(_ views: [Page]) {
|
||
self.viewControllers = views.map { UIHostingController(rootView: $0) }
|
||
}
|
||
|
||
var body: some View {
|
||
ZStack(alignment: .bottomTrailing) {
|
||
PageViewController(controllers: viewControllers, currentPage: $currentPage)
|
||
PageControl(numberOfPages: viewControllers.count, currentPage: $currentPage)
|
||
.padding(.trailing)
|
||
}
|
||
}
|
||
}
|
||
|
||
#if DEBUG
|
||
struct PageView_Previews: PreviewProvider {
|
||
static var previews: some View {
|
||
PageView(features.map { FeatureCard(landmark: $0) })
|
||
}
|
||
}
|
||
#endif
|