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

When device orientation change reset the modal dialog context frame Fix #515 #516

Merged

Conversation

phimage
Copy link
Member

@phimage phimage commented Oct 13, 2017

I am not sure that this is the best solution but I try to fix it.

To detect device orientation change I override AnimatableModalViewController. viewDidLayoutSubviews

When device orientation change I call the same code launched when updating AnimatableModalViewController.contextFrameForPresentation
(I make a method for that configurePresenterFrameForPresentation)

But how to update the frame without knowing the source, the segue, the parent view, ...?
I replace contextFrameForPresentation type from CGRect to closure to execute exactly the same code in PresentOverCurrentContextSegue
Maybe we can do better, find element in view hierarchy, make constraint, ...?

Then I see an issue, updating the contextFrameForPresentation in the presenter(configurePresenterFrameForPresentation) do nothing.
And I understand why. The PresentationConfiguration passed to the presentation controller is a struct, so a copy and no update in presentation controller.
By changing type to class, the object is shared.

@IBAnimatableBot
Copy link

IBAnimatableBot commented Oct 13, 2017

2 Warnings
⚠️ Consider adding supporting documentation to this change. Documentation can be found in the docs directory.
⚠️ Consider adding / updating the demo ap.

Generated by 🚫 Danger

Copy link
Member

@JakeLin JakeLin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing that 👍

@@ -179,4 +179,10 @@ open class AnimatableModalViewController: UIViewController, PresentationDesignab
super.viewDidAppear(animated)
configureDismissalTransition()
}

open override func viewDidLayoutSubviews() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's safe to use viewDidLayoutSubviews, it will update the UI when any UI has been changed. Another way would be viewWillTransitionToSize:withTransitionCoordinator: for size class. But I think viewDidLayoutSubviews is fine.

Remove trailing whitespace
Copy link
Member

@tbaranes tbaranes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@@ -103,12 +103,17 @@ public extension PresentationDesignable where Self: UIViewController {
}
}

public func configurePresenterFrameForPresentation() {
presenter?.presentationConfiguration?.contextFrameForPresentation = contextFrameForPresentation?()
print("presenter \( presenter?.presentationConfiguration?.contextFrameForPresentation)")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove this print?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oups, I forgot to remove this one

@phimage phimage merged commit b669c9c into IBAnimatable:master Oct 15, 2017
@phimage phimage deleted the fix/modal_overcontext_changeorientation branch April 22, 2018 10:46
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

5 participants