Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Improve Performance] ViewController for PageViewController should be initialized lazily #87

Closed
muukii opened this issue Jul 2, 2017 · 7 comments

Comments

@muukii
Copy link
Contributor

muukii commented Jul 2, 2017

PageViewController display ViewController as full screen.
Therefore, Next or Previous ViewController should not be initialized when they before displaying.

But, Current DataSource APIs require all ViewControllers.

 func viewControllers(forPageboyViewController pageboyViewController: PageboyViewController) -> [UIViewController]?

I think that add below API likes UICollectionViewDataSource.
Example,

 func viewController(forPageboyViewController pageboyViewController: PageboyViewController, at index: Int) -> UIViewController

This API improves initialize performance when PageBoy has many viewControllers.

What do you think?

@muukii
Copy link
Contributor Author

muukii commented Jul 2, 2017

Or, I just have one more idea.
I think also interesting that returning factory closure for UIViewController.

[UIViewController]?
[() -> UIViewController]?

@msaps
Copy link
Member

msaps commented Jul 3, 2017

@muukii I agree completely. A more 'reusable' style data source would definitely be an improvement.

Have currently got it planned for v2.0.0 which I'm aiming to release in September time alongside Swift 4.0. 😄

@msaps
Copy link
Member

msaps commented Jul 3, 2017

Raised an issue for the changes. #88

@muukii
Copy link
Contributor Author

muukii commented Jul 4, 2017

@msaps
Sounds good!
I'm looking forward it.
Please let me know if I can do anything to help.

@msaps
Copy link
Member

msaps commented Jul 27, 2017

These changes are now available in the Pageboy 2.0 beta's 👍

Latest available here: 2.0.0 Beta 2.

Expecting final release to be available alongside Swift 4.0 support around September time.

@msaps msaps closed this as completed Jul 27, 2017
@otymartin
Copy link

@muukii @msaps
Im experiencing this problem. In one project, the VC's load lazily - "viewDidLoad" only fires when im about to scroll to that specific VC for the first time. However in another project, all VC's are initialized at the same time (ViewDidLoad fires in all of them at launch). What could possibly cause this, both are using latest version of Pageboy/Tabman

@otymartin
Copy link

Figured out the problem

When initializing VC's for your datasource, if you perform configuration work in the initialization process, the VC will not be lazily loaded.

Eg.

var viewControllers: [UIViewController] = [] // Datasource

func loadVCS() {
 let vc = UIViewController()
vc.view.backgroundColor = .black // This ensures this VC will be loaded even if it's not yet on screen. Remove it if you want the VC to be lazily loaded (ie. When you first scroll to it).
viewControllers.append(vc)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants