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 Oct 2, 2023
1 parent a674772 commit f4f8d06
Show file tree
Hide file tree
Showing 10 changed files with 868 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,20 @@ public class AdaptiveModalManager: NSObject {
var overrideSnapPoints: [AdaptiveModalSnapPointConfig]?;
var overrideInterpolationPoints: [AdaptiveModalInterpolationPoint]?;

var currentOverrideInterpolationStep: AdaptiveModalInterpolationPoint? {
self.overrideInterpolationPoints?[self.currentOverrideInterpolationIndex];
};

private var shouldUseOverrideSnapPoints: Bool {
self.isOverridingSnapPoints
&& self.overrideSnapPoints != nil
&& self.overrideInterpolationPoints != nil
};

private var shouldClearOverrideSnapPoints: Bool {
self.shouldUseOverrideSnapPoints &&
self.currentOverrideInterpolationIndex < overrideInterpolationPoints!.count - 2;
self.shouldUseOverrideSnapPoints
&& self.currentOverrideInterpolationIndex < overrideInterpolationPoints!.count - 2
&& self.presentationState != .dismissing
};

// MARK: - Properties - Interpolation Points
Expand Down Expand Up @@ -174,12 +179,12 @@ public class AdaptiveModalManager: NSObject {

public private(set) var currentInterpolationIndex: Int {
get {
self.shouldSnapToOvershootSnapPoint
self.shouldUseOverrideSnapPoints
? self.currentOverrideInterpolationIndex
: self.currentConfigInterpolationIndex;
}
set {
if self.shouldSnapToOvershootSnapPoint {
if self.shouldUseOverrideSnapPoints {
self.currentOverrideInterpolationIndex = newValue;

} else {
Expand Down Expand Up @@ -1303,8 +1308,20 @@ public class AdaptiveModalManager: NSObject {
+ "\n - modalViewController: \(self.modalViewController?.debugDescription ?? "N/A")"
+ "\n - targetViewController: \(self.targetViewController?.debugDescription ?? "N/A")"
+ "\n - currentInterpolationIndex: \(self.currentInterpolationIndex)"
+ "\n - currentOverrideInterpolationIndex: \(self.currentOverrideInterpolationIndex)"
+ "\n - currentConfigInterpolationIndex: \(self.currentConfigInterpolationIndex)"
+ "\n - currentInterpolationStep: computedRect \(self.currentInterpolationStep.computedRect)"
+ "\n - currentConfigInterpolationStep computedRect: \(self.currentConfigInterpolationStep.computedRect)"
+ "\n - currentOverrideInterpolationStep computedRect: \(self.currentOverrideInterpolationStep?.computedRect.debugDescription ?? "N/A")"
+ "\n - modalView gestureRecognizers: \(self.modalView?.gestureRecognizers.debugDescription ?? "N/A")"
+ "\n - isOverridingSnapPoints: \(self.isOverridingSnapPoints)"
+ "\n - shouldUseOverrideSnapPoints: \(self.shouldUseOverrideSnapPoints)"
+ "\n - shouldClearOverrideSnapPoints: \(self.shouldClearOverrideSnapPoints)"
+ "\n - layoutKeyboardValues: \(self.layoutKeyboardValues.debugDescription )"
+ "\n - presentationState: \(self.presentationState )"
+ "\n - interpolationSteps.computedRect: \(self.interpolationSteps.map({ $0.computedRect }))"
+ "\n - configInterpolationSteps.computedRect: \(self.configInterpolationSteps.map({ $0.computedRect }))"
+ "\n - overrideInterpolationPoints.computedRect: \((self.overrideInterpolationPoints ?? []).map({ $0.computedRect }))"
+ "\n - interpolationSteps.percent: \(self.interpolationSteps.map({ $0.percent }))"
+ "\n - interpolationSteps.backgroundVisualEffectIntensity: \(self.interpolationSteps.map({ $0.backgroundVisualEffectIntensity }))"
+ "\n - interpolationSteps.backgroundVisualEffect: \(self.interpolationSteps.map({ $0.backgroundVisualEffect }))"
Expand Down Expand Up @@ -1364,7 +1381,6 @@ public class AdaptiveModalManager: NSObject {
let closestInterpolationIndex = closestSnapPoint.offset;

let interpolationPoint = interpolationSteps[closestInterpolationIndex];
let snapPointIndex = interpolationPoint.snapPointIndex;

return (
interpolationIndex: closestInterpolationIndex,
Expand Down Expand Up @@ -1511,8 +1527,12 @@ public class AdaptiveModalManager: NSObject {
guard let keyboardValues = RNILayoutKeyboardValues(fromNotification: notification)
else { return };

self.layoutKeyboardValues = keyboardValues;
self.computeSnapPoints();
if self.presentationState != .dismissing {
self.layoutKeyboardValues = keyboardValues;
self.computeSnapPoints();
};



self.animateModal(
to: self.currentInterpolationStep,
Expand Down Expand Up @@ -1551,9 +1571,13 @@ public class AdaptiveModalManager: NSObject {
guard let keyboardValues = RNILayoutKeyboardValues(fromNotification: notification)
else { return };

self.debug(prefix: "onKeyboardWillHide - pre");

self.clearLayoutKeyboardValues();
self.computeSnapPoints();



self.animateModal(
to: self.currentInterpolationStep,
animator: keyboardValues.keyboardAnimator
Expand Down Expand Up @@ -1591,8 +1615,10 @@ public class AdaptiveModalManager: NSObject {
guard let keyboardValues = RNILayoutKeyboardValues(fromNotification: notification)
else { return };

self.layoutKeyboardValues = keyboardValues;
self.computeSnapPoints();
if self.presentationState == .dismissing {
self.layoutKeyboardValues = keyboardValues;
self.computeSnapPoints();
};

print(
"onKeyboardWillChange",
Expand Down Expand Up @@ -1690,6 +1716,8 @@ public class AdaptiveModalManager: NSObject {
let interpolationSteps = self.interpolationSteps!;
let prevIndex = self.currentInterpolationIndex;

self.debug(prefix: "notifyOnModalWillSnap");

let nextIndexRaw: Int = {
guard let nextIndex = self.nextInterpolationIndex else {
let closestSnapPoint = self.getClosestSnapPoint();
Expand Down Expand Up @@ -1736,6 +1764,8 @@ public class AdaptiveModalManager: NSObject {
if self.shouldClearOverrideSnapPoints {
self.cleanupSnapPointOverride();
};

//self.debug(prefix: "notifyOnModalDidSnap")

self.eventDelegate?.notifyOnModalDidSnap(
prevSnapPointIndex:
Expand Down Expand Up @@ -1855,10 +1885,14 @@ public class AdaptiveModalManager: NSObject {

let nextIndex = 0;

self.debug(prefix: "hideModal");

if useInBetweenSnapPoints {
self.snapTo(interpolationIndex: nextIndex, completion: completion);

} else {
self.computeSnapPoints();

let currentSnapPointConfig = self.currentSnapPointConfig;
let currentInterpolationStep = self.currentInterpolationStep;

Expand Down Expand Up @@ -2049,6 +2083,8 @@ public class AdaptiveModalManager: NSObject {

interpolationPoints.append(nextInterpolationPoint);

let nextInterpolationPointIndex = interpolationPoints.count - 1;

let overshootSnapPoint = AdaptiveModalInterpolationPoint(
usingModalConfig: self.modalConfig,
snapPointIndex: interpolationPoints.count,
Expand All @@ -2062,8 +2098,20 @@ public class AdaptiveModalManager: NSObject {
self.isOverridingSnapPoints = true;
self.overrideSnapPoints = snapPoints;
self.overrideInterpolationPoints = interpolationPoints;
self.currentOverrideInterpolationIndex = nextInterpolationPointIndex;

print(
"snapTo",
"\n - prevInterpolationPoints:", prevInterpolationPoints.count,
"\n - interpolationPoints:", interpolationPoints.count,
"\n - nextInterpolationPointIndex:", nextInterpolationPointIndex
);

self.debug(prefix: "snapTo");


self.animateModal(to: nextInterpolationPoint, completion: { _ in
self.debug(prefix: "snapTo - completion");
completion?();
});
};
Expand Down
Loading

0 comments on commit f4f8d06

Please sign in to comment.