Closed neHCuoHEpa closed 4 years ago
I found a solution. Just need to update parent value of coordinator before any changes. Like this
func updateUIViewController(_ pageViewController: UIPageViewController, context: Context) { context.coordinator.parent = self pageViewController.setViewControllers( [controllers[currentPage]], direction: .forward, animated: false ) }
For those reading along, update your updateUIViewController
in PageViewController
to:
func updateUIViewController(_ pageViewController: UIPageViewController, context: Context) {
context.coordinator.parent = self
pageViewController.setViewControllers(
[controllers[currentPage]], direction: .forward, animated: false
)
}
Worked for me!
Awesome, thanks guys. I don't have time right now but I'll try to add it this weekend. If anybody wants to submit a pull request feel free :)
Fixed
I have follow situation.
struct HomeView { ... Pages(currentPage: self.$currentPage) { ChannelsView() PublicationsView() MarkedView() } ...
The problem is coming from that in PublicationsView, Im realoading some data and view should be rendered again. Then "controllers" array is updated and refill with newest views. But in the Coordinator the parent reference keep the first "controllers" array. That follow to a bug: in "viewControllerBefore" and "viewControllerAfter" -> "parent.controllers.firstIndex(of: viewController)" is returning nil and the pages cannot be changed. I cannot find a easy solution. Could you help me?