This repository has been archived by the owner on Aug 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release-candidate' into stable
- Loading branch information
Showing
13 changed files
with
320 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
Copyright 2017-present The Material Motion Authors. All Rights Reserved. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import UIKit | ||
import MotionTransitioning | ||
|
||
// This example demonstrates how to build a custom UINavigationController transition using the | ||
// Motion Transitioning APIs in Swift. The essential steps have been documented below. | ||
|
||
class NavControllerFadeExampleViewController: ExampleViewController { | ||
|
||
func didTap() { | ||
let modalViewController = ModalViewController() | ||
modalViewController.title = "Example view controller" | ||
|
||
// The transition controller is an associated object on all UIViewController instances that | ||
// allows you to customize the way the view controller is presented. The primary API on the | ||
// controller that you'll make use of is the `transition` property. Setting this property will | ||
// dictate how the view controller is presented. For this example we've built a custom | ||
// FadeTransition, so we'll make use of that now: | ||
modalViewController.transitionController.transition = FadeTransition() | ||
|
||
cachedNavDelegate = navigationController?.delegate | ||
|
||
// In order to customize navigation controller transitions you must implement the necessary | ||
// delegate methods. By setting the shared transition navigation controller delegate instance | ||
// we're able to customize push/pop transitions using our transitionController. | ||
|
||
navigationController?.delegate = TransitionNavigationControllerDelegate.sharedDelegate() | ||
|
||
navigationController?.pushViewController(modalViewController, animated: true) | ||
} | ||
private var cachedNavDelegate: UINavigationControllerDelegate? | ||
|
||
override func viewDidDisappear(_ animated: Bool) { | ||
super.viewDidDisappear(animated) | ||
|
||
if parent == nil { // Popped off | ||
// Restore the previous delegate, if any. | ||
navigationController?.delegate = cachedNavDelegate | ||
|
||
cachedNavDelegate = nil | ||
} | ||
} | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
let label = UILabel(frame: view.bounds) | ||
label.autoresizingMask = [.flexibleWidth, .flexibleHeight] | ||
label.textColor = .white | ||
label.textAlignment = .center | ||
label.text = "Tap to start the transition" | ||
view.addSubview(label) | ||
|
||
let tap = UITapGestureRecognizer(target: self, action: #selector(didTap)) | ||
view.addGestureRecognizer(tap) | ||
} | ||
|
||
override func exampleInformation() -> ExampleInfo { | ||
return .init(title: type(of: self).catalogBreadcrumbs().last!, | ||
instructions: "Tap to present a modal transition.") | ||
} | ||
} | ||
|
||
// Transitions must be NSObject types that conform to the Transition protocol. | ||
private final class FadeTransition: NSObject, Transition { | ||
|
||
// The sole method we're expected to implement, start is invoked each time the view controller is | ||
// presented or dismissed. | ||
func start(with context: TransitionContext) { | ||
CATransaction.begin() | ||
|
||
CATransaction.setCompletionBlock { | ||
// Let UIKit know that the transition has come to an end. | ||
context.transitionDidEnd() | ||
} | ||
|
||
let fade = CABasicAnimation(keyPath: "opacity") | ||
|
||
fade.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut) | ||
|
||
// Define our animation assuming that we're going forward (presenting)... | ||
fade.fromValue = 0 | ||
fade.toValue = 1 | ||
|
||
// ...and reverse it if we're going backwards (dismissing). | ||
if context.direction == .backward { | ||
let swap = fade.fromValue | ||
fade.fromValue = fade.toValue | ||
fade.toValue = swap | ||
} | ||
|
||
// Add the animation... | ||
context.foreViewController.view.layer.add(fade, forKey: fade.keyPath) | ||
|
||
// ...and ensure that our model layer reflects the final value. | ||
context.foreViewController.view.layer.setValue(fade.toValue, forKeyPath: fade.keyPath!) | ||
|
||
CATransaction.commit() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
Copyright 2017-present The Material Motion Authors. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
/** | ||
This class provides a singleton implementation of UINavigationControllerDelegate that makes it | ||
possible to configure view controller transitions using each view controller's transition | ||
controller. | ||
This class is not meant to be instantiated directly. | ||
The +delegate should be assigned as the delegate for any UINavigationController instance that | ||
wishes to configure transitions using the mdm_transitionController (transitionController in Swift) | ||
property on a view controller. | ||
If a navigation controller already has its own delegate, then that delegate can simply forward | ||
the two necessary methods to the +sharedInstance of this class. | ||
*/ | ||
NS_SWIFT_NAME(TransitionNavigationControllerDelegate) | ||
@interface MDMTransitionNavigationControllerDelegate : NSObject | ||
|
||
/** | ||
Use when directly invoking methods. | ||
Only supported methods are exposed. | ||
*/ | ||
+ (instancetype)sharedInstance; | ||
|
||
/** | ||
Can be set as a navigation controller's delegate. | ||
*/ | ||
+ (id<UINavigationControllerDelegate>)sharedDelegate; | ||
|
||
#pragma mark <UINavigationControllerDelegate> Support | ||
|
||
- (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController | ||
animationControllerForOperation:(UINavigationControllerOperation)operation | ||
fromViewController:(UIViewController *)fromVC | ||
toViewController:(UIViewController *)toVC; | ||
- (id<UIViewControllerInteractiveTransitioning>)navigationController:(UINavigationController *)navigationController | ||
interactionControllerForAnimationController:(id<UIViewControllerAnimatedTransitioning>)animationController; | ||
|
||
@end |
Oops, something went wrong.