Skip to content
This repository has been archived by the owner on Aug 13, 2021. It is now read-only.

Commit

Permalink
Add a defaultModalPresentationStyle API for transitions with presenta…
Browse files Browse the repository at this point in the history
…tion.

Summary: This allows transitions with presentation to choose the default modal presentation style for a view controller. This is necessary because the transition may choose not to use a presentation controller even though it conforms to the TransitionWithPresentation protocol (e.g. a modal transition that covers the whole screen may not need a presentation controller).

Reviewers: O2 Material Motion, O4 Material Apple platform reviewers, #material_motion, randcode-generator, markwei

Reviewed By: O2 Material Motion, O4 Material Apple platform reviewers, #material_motion, randcode-generator, markwei

Tags: #material_motion

Differential Revision: http://codereview.cc/D3230
  • Loading branch information
Jeff Verkoeyen committed May 17, 2017
1 parent 5a6570a commit c11949e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/transitions/Transition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ public protocol TransitionWithTermination: Transition {
*/
public protocol TransitionWithPresentation: Transition {

/**
The modal presentation style this transition expects to use.

This value is queried when the transition is assigned to a view controller's
transitionController. The result, if any, is assigned to the view controller's
modalPresentationStyle property.

In order for a presentationController to be used, this method should return `.custom`.
*/
func defaultModalPresentationStyle() -> UIModalPresentationStyle?

/**
Queried before the Transition object is instantiated and only once, when the fore view controller
is initially presented.
Expand Down
5 changes: 3 additions & 2 deletions src/transitions/TransitionController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ public final class TransitionController {
set {
_transitioningDelegate.transition = newValue

if newValue is TransitionWithPresentation {
_transitioningDelegate.associatedViewController?.modalPresentationStyle = .custom
if let presentationTransition = newValue as? TransitionWithPresentation,
let modalPresentationStyle = presentationTransition.defaultModalPresentationStyle() {
_transitioningDelegate.associatedViewController?.modalPresentationStyle = modalPresentationStyle
}
}
get { return _transitioningDelegate.transition }
Expand Down

0 comments on commit c11949e

Please sign in to comment.