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 8c3a2ea commit 568bd62
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,40 @@ struct AdaptiveModalInterpolationPoint: Equatable {
// MARK: - Properties
// ------------------

let percent: CGFloat;
let snapPointIndex: Int;
var percent: CGFloat;
var snapPointIndex: Int;

/// The computed frames of the modal based on the snap points
let computedRect: CGRect;
var computedRect: CGRect;

// MARK: - Properties - Keyframes
// ------------------------------

let modalRotation: CGFloat;
var modalRotation: CGFloat;

let modalScaleX: CGFloat;
let modalScaleY: CGFloat;
var modalScaleX: CGFloat;
var modalScaleY: CGFloat;

let modalTranslateX: CGFloat;
let modalTranslateY: CGFloat;
var modalTranslateX: CGFloat;
var modalTranslateY: CGFloat;

let modalOpacity: CGFloat;
let modalBackgroundColor: UIColor;
let modalBackgroundOpacity: CGFloat;
var modalOpacity: CGFloat;
var modalBackgroundColor: UIColor;
var modalBackgroundOpacity: CGFloat;

let modalCornerRadius: CGFloat;
let modalMaskedCorners: CACornerMask;
var modalCornerRadius: CGFloat;
var modalMaskedCorners: CACornerMask;

let modalBackgroundVisualEffect: UIVisualEffect?;
let modalBackgroundVisualEffectOpacity: CGFloat;
let modalBackgroundVisualEffectIntensity: CGFloat;
var modalBackgroundVisualEffect: UIVisualEffect?;
var modalBackgroundVisualEffectOpacity: CGFloat;
var modalBackgroundVisualEffectIntensity: CGFloat;

let backgroundColor: UIColor;
let backgroundOpacity: CGFloat;
var backgroundColor: UIColor;
var backgroundOpacity: CGFloat;

let backgroundVisualEffect: UIVisualEffect?;
let backgroundVisualEffectOpacity: CGFloat;
let backgroundVisualEffectIntensity: CGFloat;
var backgroundVisualEffect: UIVisualEffect?;
var backgroundVisualEffectOpacity: CGFloat;
var backgroundVisualEffectIntensity: CGFloat;

// MARK: - Computed Properties
// ---------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extension AdaptiveModalManager: UIViewControllerAnimatedTransitioning {
};

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,8 @@ class AdaptiveModalManager: NSObject {
};

func prepareForPresentation(
presentingViewController presentingVC: UIViewController
viewControllerToPresent presentingVC: UIViewController,
presentingViewController presentedVC: UIViewController
) {
self.modalViewController = presentingVC;
self.modalView = presentingVC.view;
Expand Down Expand Up @@ -1401,7 +1402,7 @@ class AdaptiveModalManager: NSObject {
self.snapTo(interpolationIndex: nextIndex, completion: completion);
};

func dismissModal(
func hideModal(
useInBetweenSnapPoints: Bool = false,
completion: (() -> Void)? = nil
){
Expand All @@ -1413,25 +1414,46 @@ class AdaptiveModalManager: NSObject {

} else {
let currentSnapPointConfig = self.currentSnapPointConfig;
let currentInterpolationStep = self.currentInterpolationStep;

let undershootSnapPointConfig = AdaptiveModalSnapPointConfig(
fromSnapPointPreset: self.modalConfig.undershootSnapPoint,
fromBaseLayoutConfig: currentSnapPointConfig.snapPoint
);

let undershootInterpolationPoint = AdaptiveModalInterpolationPoint(
var undershootInterpolationPoint = AdaptiveModalInterpolationPoint(
usingModalConfig: self.modalConfig,
snapPointIndex: nextIndex,
layoutValueContext: self.layoutValueContext,
snapPointConfig: undershootSnapPointConfig,
prevInterpolationPoint: self.currentInterpolationStep
snapPointConfig: undershootSnapPointConfig
);

undershootInterpolationPoint.modalCornerRadius =
currentInterpolationStep.modalCornerRadius;

self.snapTo(
interpolationIndex: nextIndex,
interpolationPoint: undershootInterpolationPoint,
completion: completion
);
};
};

public func presentModal(
viewControllerToPresent modalVC: UIViewController,
presentingViewController targetVC: UIViewController,
animated: Bool = true,
completion: (() -> Void)? = nil
) {
self.prepareForPresentation(
viewControllerToPresent: modalVC,
presentingViewController: targetVC
);

targetVC.present(
modalVC,
animated: animated,
completion: completion
);
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ class AdaptiveModalPresentationTestViewController : UIViewController {
self.adaptiveModalManager.eventDelegate = testVC;
testVC.modalManager = self.adaptiveModalManager;

self.adaptiveModalManager.prepareForPresentation(
presentingViewController: testVC
);

self.present(testVC, animated: true);
self.adaptiveModalManager.presentModal(
viewControllerToPresent: testVC,
presentingViewController: self
);
};
};

0 comments on commit 568bd62

Please sign in to comment.