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 9, 2023
1 parent 387e188 commit fc5b085
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct AdaptiveModalConfig {
// MARK: - Properties
// ------------------

let snapPoints: [AdaptiveModalSnapPointConfig];
let baseSnapPoints: [AdaptiveModalSnapPointConfig];
let snapDirection: Direction;

let snapPercentStrategy: SnapPercentStrategy;
Expand All @@ -39,6 +39,32 @@ struct AdaptiveModalConfig {
// let entranceConfig: AdaptiveModalEntranceConfig;
// let snapSwipeVelocityThreshold: CGFloat = 0;

var snapPoints: [AdaptiveModalSnapPointConfig] {
var items: [AdaptiveModalSnapPointConfig] = [];

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

items.append(initialSnapPointConfig);
};

items += self.baseSnapPoints;

if let snapPointLast = self.baseSnapPoints.last {
let overshootSnapPointConfig = AdaptiveModalSnapPointConfig(
fromSnapPointPreset: self.overshootSnapPoint,
fromBaseLayoutConfig: snapPointLast.snapPoint
);

items.append(overshootSnapPointConfig);
};

return items;
};

var snapPointLastIndex: Int {
self.snapPoints.count - 1;
};
Expand Down Expand Up @@ -79,7 +105,7 @@ struct AdaptiveModalConfig {
initialSnapPoint: AdaptiveModalSnapPointPreset? = nil,
overshootSnapPoint: AdaptiveModalSnapPointPreset? = nil
) {
self.snapPoints = snapPoints;
self.baseSnapPoints = snapPoints;

self.snapDirection = snapDirection;
self.snapPercentStrategy = snapPercentStrategy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ struct AdaptiveModalInterpolationPoint: Equatable {
};
}();

let isFirstSnapPoint = snapPointIndex == 0;
let keyframeCurrent = snapPointConfig.animationKeyframe;

self.modalRotation = keyframeCurrent?.modalRotation
Expand Down Expand Up @@ -174,7 +175,7 @@ struct AdaptiveModalInterpolationPoint: Equatable {

self.modalBackgroundVisualEffectIntensity = keyframeCurrent?.modalBackgroundVisualEffectIntensity
?? keyframePrev?.modalBackgroundVisualEffectIntensity
?? 1;
?? (isFirstSnapPoint ? 0 : 1);

self.backgroundColor = keyframeCurrent?.backgroundColor
?? keyframePrev?.backgroundColor
Expand All @@ -193,7 +194,7 @@ struct AdaptiveModalInterpolationPoint: Equatable {

self.backgroundVisualEffectIntensity = keyframeCurrent?.backgroundVisualEffectIntensity
?? keyframePrev?.backgroundVisualEffectIntensity
?? 1;
?? (isFirstSnapPoint ? 0 : 1);
};

// MARK: - Functions
Expand Down Expand Up @@ -283,25 +284,6 @@ extension AdaptiveModalInterpolationPoint {

var items: [AdaptiveModalInterpolationPoint] = [];

// items.append({
// let nextSnapPointConfig = modalConfig.snapPoints.first!;
//
// let initialSnapPointConfig = AdaptiveModalSnapPointConfig(
// fromSnapPointPreset: modalConfig.initialSnapPoint,
// fromBaseLayoutConfig: nextSnapPointConfig.snapPoint,
// withTargetRect: targetRect,
// currentSize: currentSize
// );
//
// return AdaptiveModalInterpolationPoint(
// usingModalConfig: modalConfig,
// snapPointIndex: -1,
// withTargetRect: targetRect,
// currentSize: currentSize,
// snapPointConfig: initialSnapPointConfig
// );
// }());

for (index, snapConfig) in modalConfig.snapPoints.enumerated() {
items.append(
AdaptiveModalInterpolationPoint(
Expand All @@ -314,24 +296,6 @@ extension AdaptiveModalInterpolationPoint {
);
};

items.append({
let prevSnapPointConfig = modalConfig.snapPoints.last!;

let overshootSnapPointConfig = AdaptiveModalSnapPointConfig(
fromSnapPointPreset: modalConfig.overshootSnapPoint,
fromBaseLayoutConfig: prevSnapPointConfig.snapPoint
);

return AdaptiveModalInterpolationPoint(
usingModalConfig: modalConfig,
snapPointIndex: modalConfig.snapPointLastIndex + 1,
percent: 1,
layoutValueContext: context,
snapPointConfig: overshootSnapPointConfig,
prevInterpolationPoint: items.last
);
}());

return items;
};
};
Expand Down
Loading

0 comments on commit fc5b085

Please sign in to comment.