SwiftUI · Adding a UIPageController | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/4001741-swiftui/lessons/36

Hi there!
Great job!
I’m trying to wrap a player into a SwiftUIView.
Every time I update the @Binding property for the progress from the ViewController, the method updateUIViewController() gets call again.
Do you know if this is the expected behavior or I am missing something.
As I understand, every time I update a value of the parent view the method should get call as the SwiftUI protocol View gets updated as well. The question is, can I avoid the UIKit view to get updated when the state is changed from the UIKitView
I hope you understand my point.
Thank you!

Hey @jorgeb I think I understand what you mean. I don’t think you can escape the state system determining which lifecycle methods are getting called under the hood. If you have a view depending on that state the view will probably be re rendered and if it is a view controller often the entire view seems to be updated, whereas with SwiftUI views they seem to be able to re-render certain parts of the view. I’m not 100% sure how this works!

Thank you @isaacmendez!
So far I worked it around with a Bool in the source of truth used as a flag in the updateUIViewController method.
If I find something better, I’ll post it here.

1 Like

@jorgeb Do you still have issues with this?

I used a Boolean to handle that, so I can know what view is updating the state

1 Like

In this video for page view controller, you’re using an array of the same view: OnboardingView for all pages of the PageViewController and are just altering the data. How do I proceed if I want completely different views for the pages?
Thanks.

That’s a good question! You could create an array of objects conforming to View and try that?