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 14, 2023
1 parent d4b09d0 commit 7d11237
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ struct AdaptiveModalConfig {
let snapAnimationConfig: AdaptiveModalSnapAnimationConfig;
let interpolationClampingConfig: AdaptiveModalClampingConfig;

// rename to undershootSnapPoint
let initialSnapPoint: AdaptiveModalSnapPointPreset;
let undershootSnapPoint: AdaptiveModalSnapPointPreset;
let overshootSnapPoint: AdaptiveModalSnapPointPreset;

let initialSnapPointIndex: Int;
Expand All @@ -47,7 +46,7 @@ struct AdaptiveModalConfig {

if let snapPointFirst = self.baseSnapPoints.first {
let initialSnapPointConfig = AdaptiveModalSnapPointConfig(
fromSnapPointPreset: self.initialSnapPoint,
fromSnapPointPreset: self.undershootSnapPoint,
fromBaseLayoutConfig: snapPointFirst.snapPoint
);

Expand Down Expand Up @@ -106,7 +105,7 @@ struct AdaptiveModalConfig {
snapAnimationConfig: AdaptiveModalSnapAnimationConfig = .default,
interpolationClampingConfig: AdaptiveModalClampingConfig = .default,
initialSnapPointIndex: Int = 1,
initialSnapPoint: AdaptiveModalSnapPointPreset? = nil,
undershootSnapPoint: AdaptiveModalSnapPointPreset? = nil,
overshootSnapPoint: AdaptiveModalSnapPointPreset? = nil
) {
self.baseSnapPoints = snapPoints;
Expand All @@ -119,7 +118,7 @@ struct AdaptiveModalConfig {

self.initialSnapPointIndex = initialSnapPointIndex;

self.initialSnapPoint = initialSnapPoint
self.undershootSnapPoint = undershootSnapPoint
?? .getDefaultInitialSnapPoint(forDirection: snapDirection);

self.overshootSnapPoint = overshootSnapPoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class AdaptiveModalManager: NSObject {
var backgroundDimmingView: UIView?;
var backgroundVisualEffectView: UIVisualEffectView?;

var modalFrame: CGRect! {
private var modalFrame: CGRect! {
set {
guard let newValue = newValue else { return };
self.prevModalFrame = dummyModalView.frame;
Expand All @@ -52,7 +52,7 @@ class AdaptiveModalManager: NSObject {
}
};

var layoutValueContext: RNILayoutValueContext {
private var layoutValueContext: RNILayoutValueContext {
if let targetVC = self.targetViewController {
return .init(fromTargetViewController: targetVC) ?? .default;
};
Expand Down Expand Up @@ -189,6 +189,9 @@ class AdaptiveModalManager: NSObject {
return CGPoint(x: nextX, y: nextY);
};

// MARK: - Properties - Flags
// ---------------------------

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

Expand Down Expand Up @@ -1004,7 +1007,6 @@ class AdaptiveModalManager: NSObject {
animator.startAnimation();
};


@objc private func onDragPanGesture(_ sender: UIPanGestureRecognizer) {
let gesturePoint = sender.location(in: self.targetView);
self.gesturePoint = gesturePoint;
Expand All @@ -1020,7 +1022,7 @@ class AdaptiveModalManager: NSObject {
self.modalAnimator?.stopAnimation(true);

self.applyInterpolationToModal(forGesturePoint: gesturePoint);
self.onModalWillSnap();
self.notifyOnModalWillSnap();

case .cancelled, .ended:
guard self.enableSnapping else {
Expand All @@ -1032,7 +1034,7 @@ class AdaptiveModalManager: NSObject {

self.snapToClosestSnapPoint(forPoint: gestureFinalPoint) {
self.endDisplayLink();
self.onModalDidSnap();
self.notifyOnModalDidSnap();
};

self.clearGestureValues();
Expand Down Expand Up @@ -1158,13 +1160,13 @@ class AdaptiveModalManager: NSObject {
let nextInterpolationPoint =
self.interpolationSteps[nextIndex];

self.onModalWillSnap();
self.notifyOnModalWillSnap();

self.animateModal(to: nextInterpolationPoint) { _ in
self.currentInterpolationIndex = nextIndex;
self.nextInterpolationIndex = nil;

self.onModalDidSnap();
self.notifyOnModalDidSnap();
completion?();
};
};
Expand Down Expand Up @@ -1221,17 +1223,15 @@ class AdaptiveModalManager: NSObject {
);
};

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

// MARK: - Event Functions
// -----------------------

func onModalWillSnap(){
private func notifyOnModalWillSnap(){
let interpolationSteps = self.interpolationSteps!;
let prevIndex = self.currentInterpolationIndex;

Expand All @@ -1256,7 +1256,7 @@ class AdaptiveModalManager: NSObject {
);
};

func onModalDidSnap(){
private func notifyOnModalDidSnap(){
self.eventDelegate?.notifyOnModalDidSnap(
prevSnapPointIndex:
interpolationSteps[self.prevInterpolationIndex].snapPointIndex,
Expand Down

0 comments on commit 7d11237

Please sign in to comment.