Skip to content

Commit

Permalink
Made controllers a state variable so it would stop breaking
Browse files Browse the repository at this point in the history
  • Loading branch information
blsage committed Nov 4, 2020
1 parent f6e75b6 commit 8505db2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Sources/iPages/PageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct PageViewController: UIViewControllerRepresentable {
pageViewController.setViewControllers(
[controllers[currentPage]],
direction: currentPage > previousPage ? .forward : .reverse,
animated: currentPage == previousPage ? false : animated)
animated: animated)
}

class Coordinator: NSObject, UIPageViewControllerDataSource, UIPageViewControllerDelegate {
Expand Down
4 changes: 2 additions & 2 deletions Sources/iPages/iPages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import UIKit
///
/// Binds to a zero-indexed 0️⃣1️⃣2️⃣ "current page" `Int`eger.
public struct iPages<Content: View>: View {
private var viewControllers: [UIViewController]
@State private var viewControllers: [UIViewController]

@State private var internalSelection: Int = 0
@Binding private var externalSelection: Int
Expand Down Expand Up @@ -78,7 +78,7 @@ public struct iPages<Content: View>: View {
public init(selection: Binding<Int>? = nil,
@ViewBuilder content: () -> Content)
{
viewControllers = content().decompose().map { UIHostingController(rootView: $0) }
_viewControllers = State(initialValue: content().decompose().map { UIHostingController(rootView: $0) })
if let selection = selection {
_externalSelection = selection
hasExternalSelection = true
Expand Down

0 comments on commit 8505db2

Please sign in to comment.