Skip to content

Commit

Permalink
💫 Update: Exp - AdaptiveModal
Browse files Browse the repository at this point in the history
Summary: Update experiment/test - `swift-programmatic-modal/AdaptiveModal`.
  • Loading branch information
dominicstop committed Jun 16, 2023
1 parent 8f93db6 commit e78a191
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,27 @@ extension AdaptiveModalManager: UIViewControllerAnimatedTransitioning {
func animateTransition(
using transitionContext: UIViewControllerContextTransitioning
) {
guard let fromVC = transitionContext.viewController(forKey: .from),
let toVC = transitionContext.viewController(forKey: .to)
else { return }

self.targetView = transitionContext.containerView;
self.targetViewController = fromVC;

self.prepareForPresentation();
self.showModal() {
transitionContext.completeTransition(true);
guard let fromVC = transitionContext.viewController(forKey: .from)
else { return };

switch self.presentationState {
case .presenting:
self.targetView = transitionContext.containerView;
self.targetViewController = fromVC;

self.prepareForPresentation();

self.showModal() {
transitionContext.completeTransition(true);
};

case .dismissing:
self.dismissModal(){
transitionContext.completeTransition(true);
};

case .none:
break;
};

self.debug(prefix: "AdaptiveModalPresentationController.animateTransition");




// if self.currentInterpolationIndex == 0 {
// self.prepareForPresentation(
// presentingViewController: fromVC,
// presentedViewController: toVC
// );
// };
//
// self.showModal(){
// transitionContext.completeTransition(true);
// };

print(
"AdaptiveModalPresentationController.animateTransition"
+ "\n - fromVC: \(fromVC)"
+ "\n - toVC: \(toVC)"
);
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,6 @@ extension AdaptiveModalManager: UIViewControllerTransitioningDelegate {
modalManager: self
);

print(
"AdaptiveModalManager+UIViewControllerTransitioningDelegate"
+ "\n - presentationController"
+ "\n - presented: \(presented)"
+ "\n - presented.view.frame: \(presented.view.frame)"
+ "\n - presenting: \(presenting)"
+ "\n - presenting.view.frame: \(presenting?.view.frame)"
+ "\n - source: \(source)"
+ "\n - source.view.frame: \(source.view.frame)"
+ "\n"
);

presentationController.delegate = self;
return presentationController;
};
Expand All @@ -53,14 +41,16 @@ extension AdaptiveModalManager: UIViewControllerTransitioningDelegate {
presenting: UIViewController,
source: UIViewController
) -> UIViewControllerAnimatedTransitioning? {


self.presentationState = .presenting;
return self;
};

func animationController(
forDismissed dismissed: UIViewController
) -> UIViewControllerAnimatedTransitioning? {


self.presentationState = .dismissing;
return self;
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import UIKit

class AdaptiveModalManager: NSObject {

enum PresentationState {
case presenting, dismissing, none;
};

// MARK: - Properties - Config-Related
// ------------------------------------

Expand Down Expand Up @@ -193,6 +197,7 @@ class AdaptiveModalManager: NSObject {
// -------------------

private var didTriggerSetup = false;
var presentationState: PresentationState = .none;

weak var eventDelegate: AdaptiveModalEventNotifiable?;

Expand Down Expand Up @@ -1389,4 +1394,9 @@ class AdaptiveModalManager: NSObject {
let nextIndex = self.modalConfig.initialSnapPointIndex;
self.snapTo(interpolationIndex: nextIndex, completion: completion);
};

func dismissModal(completion: (() -> Void)? = nil){
let nextIndex = 0;
self.snapTo(interpolationIndex: nextIndex, completion: completion);
};
};

0 comments on commit e78a191

Please sign in to comment.