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

Custom page view controller #468

Merged
merged 12 commits into from
Apr 22, 2020
Merged

Custom page view controller #468

merged 12 commits into from
Apr 22, 2020

Conversation

rechsteiner
Copy link
Owner

@rechsteiner rechsteiner commented Apr 3, 2020

This PR tracks the process of creating a custom UIPageViewController class. The new implementation fixes a couple of issues that are present in the EMPageViewController implementation we're using today.

Appearance transitions

There's been a few issues with appearance transitions getting called out of order (#426, #373), but the current implementation makes it very hard to unit-tests that everything is working correctly. Another problem is that the appearance transitions are called a lot of times when flicking fast to the next page. This happens because the scroll view starts bouncing back and forth between the upcoming and previous view controller before landing on the new one. Here's a comparison of how the different implementations behave (using the Size Delegate example):

UIPageViewController
viewWillAppear:  Stockholm
viewWillDisappear:  Oslo
viewDidAppear:  Stockholm
viewDidDisappear:  Oslo
EMPageViewController
viewWillAppear:  Stockholm
viewWillDisappear:  Oslo
viewDidAppear:  Stockholm
viewDidDisappear:  Oslo
viewWillAppear:  Tokyo
viewWillDisappear:  Stockholm
viewWillAppear:  Stockholm
viewWillDisappear:  Tokyo
viewDidAppear:  Stockholm
viewDidDisappear:  Tokyo
viewWillAppear:  Oslo
viewWillDisappear:  Stockholm
viewWillAppear:  Stockholm
viewWillDisappear:  Oslo
viewDidAppear:  Stockholm
viewDidDisappear:  Oslo

The new implementation follows the same behaviour as UIPageViewController.

Todo

  • Fix appearance transitions
  • Vertical scrolling
  • Right-to-left languages
  • Spacing between pages
  • Documentation

The implementation is split into two classes, PageViewController and
PageViewManager. PageViewManager is responsible for all the logic
related to adding/removing view controllers and calling the correct
appearance transitions, while PageViewController is responsible for
updating the UIScrollView.
Adds another flag to the layoutViews method so we can opt-out of
accounting for the current content offset when rotating.
Make sure viewWillAppear, viewDidAppear, viewWillDisappear and
viewDidDisappear is forwarded to the selected view controller and
include the correct animated flag.
@rechsteiner rechsteiner changed the base branch from master to 3.0 April 3, 2020 20:47
Moves the PageViewManager configuration to the initializers to ensure
that we handle the selectViewController method if it's called before
viewDidLoad has been triggered.
Ideally we would keep these private, but the current implementation
exposes them so it better not to break existing apps.
@rechsteiner rechsteiner changed the title WIP: Custom page view controller Custom page view controller Apr 22, 2020
@rechsteiner rechsteiner merged commit 041a834 into 3.0 Apr 22, 2020
@rechsteiner rechsteiner deleted the page-view-controller branch April 22, 2020 17:57
This was referenced Apr 24, 2020
@rechsteiner rechsteiner mentioned this pull request Dec 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant