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 20, 2023
1 parent b75e0bb commit c71d6a7
Showing 1 changed file with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class AdaptiveModalManager: NSObject {

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

// MARK: - Properties - Interpolation Points
Expand Down Expand Up @@ -1798,27 +1798,28 @@ class AdaptiveModalManager: NSObject {
) {
self.cleanupSnapPointOverride();

let prevInterpolationPoint: AdaptiveModalInterpolationPoint = {
let prevInterpolationPoints: [AdaptiveModalInterpolationPoint] = {
let overrideInterpolationPoint = AdaptiveModalInterpolationPoint(
usingModalConfig: self.modalConfig,
snapPointIndex: 1,
layoutValueContext: self.layoutValueContext,
snapPointConfig: overrideSnapPointConfig
);

let match = self.configInterpolationSteps.first {
let items = self.configInterpolationSteps.filter {
$0.percent < overrideInterpolationPoint.percent;
};

guard let match = match else {
return self.configInterpolationSteps.first!;
guard items.count > 0 else {
return [self.configInterpolationSteps.first!];
};

return match;
return items;
}();

let prevSnapPointConfig =
self.modalConfig.snapPoints[prevInterpolationPoint.snapPointIndex];
let prevSnapPointConfigs = prevInterpolationPoints.map {
self.modalConfig.snapPoints[$0.snapPointIndex];
};

let overshootSnapPointPreset = overshootSnapPointPreset
?? .getDefaultOvershootSnapPoint(forDirection: modalConfig.snapDirection);
Expand All @@ -1828,15 +1829,17 @@ class AdaptiveModalManager: NSObject {
fromBaseLayoutConfig: overrideSnapPointConfig.snapPoint
);

let snapPoints = [
prevSnapPointConfig,
let snapPoints = prevSnapPointConfigs + [
overrideSnapPointConfig,
overshootSnapPointConfig,
];

var interpolationPoints: [AdaptiveModalInterpolationPoint] = [
prevInterpolationPoint
];
var interpolationPoints = prevInterpolationPoints.enumerated().map {
var copy = $0.element;
copy.snapPointIndex = $0.offset;

return copy;
};

let nextInterpolationPoint = AdaptiveModalInterpolationPoint(
usingModalConfig: self.modalConfig,
Expand All @@ -1862,12 +1865,6 @@ class AdaptiveModalManager: NSObject {
self.overrideSnapPoints = snapPoints;
self.overrideInterpolationPoints = interpolationPoints;

print(
"\n - interpolationPoints.percent:", interpolationPoints.map({$0.percent}),
"\n - interpolationPoints.snapPointIndex:", interpolationPoints.map({$0.snapPointIndex}),
"\n - interpolationPoints.computedRect:", interpolationPoints.map({$0.computedRect})
);

self.animateModal(to: nextInterpolationPoint) { _ in
completion?();
};
Expand Down

0 comments on commit c71d6a7

Please sign in to comment.