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

let initialSnapPoint: AdaptiveModalSnapPointPreset;
let overshootSnapPoint: AdaptiveModalSnapPointPreset;

// let entranceConfig: AdaptiveModalEntranceConfig;
Expand Down Expand Up @@ -75,17 +76,22 @@ struct AdaptiveModalConfig {
snapPercentStrategy: SnapPercentStrategy = .position,
snapAnimationConfig: AdaptiveModalSnapAnimationConfig = .default,
interpolationClampingConfig: AdaptiveModalClampingConfig = .default,
initialSnapPoint: AdaptiveModalSnapPointPreset? = nil,
overshootSnapPoint: AdaptiveModalSnapPointPreset? = nil
) {
self.snapPoints = snapPoints;

self.snapDirection = snapDirection;
self.snapPercentStrategy = snapPercentStrategy;

self.snapAnimationConfig = snapAnimationConfig;
self.interpolationClampingConfig = interpolationClampingConfig;

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

self.overshootSnapPoint = overshootSnapPoint
?? .getDefault(forDirection: snapDirection);
?? .getDefaultOvershootSnapPoint(forDirection: snapDirection);
};

// MARK: - Functions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,25 @@ 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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct AdaptiveModalSnapPointConfig {
fromBaseLayoutConfig baseLayoutConfig: RNILayout,
withTargetRect targetRect: CGRect,
currentSize: CGSize
){
) {
let snapPointLayoutPreset = snapPointPreset.snapPointPreset;

let snapPointLayout = snapPointLayoutPreset.getLayoutConfig(
Expand All @@ -37,3 +37,17 @@ struct AdaptiveModalSnapPointConfig {
self.animationKeyframe = snapPointPreset.animationKeyframe;
};
};

//extension AdaptiveModalSnapPointConfig {
//
// static func deriveSnapPoints(
// initialSnapPoint: AdaptiveModalSnapPointPreset,
// inBetweenSnapPoints: [AdaptiveModalSnapPointConfig],
// overshootSnapPoint: AdaptiveModalSnapPointPreset
// ) -> [AdaptiveModalSnapPointConfig] {
//
// var snapPoints: [AdaptiveModalSnapPointConfig] = [];
//
// return snapPoints;
// };
//};
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,35 @@ struct AdaptiveModalSnapPointPreset {
};

extension AdaptiveModalSnapPointPreset {
static func getDefaultSnapPoint(
static func getDefaultOvershootSnapPoint(
forDirection direction: AdaptiveModalConfig.Direction
) -> RNILayoutPreset {
switch direction {
case .bottomToTop: return .edgeTop;
case .topToBottom: return .edgeBottom;
case .leftToRight: return .edgeLeft;
case .rightToLeft: return .edgeRight;
};
) -> Self {

let snapPoint: RNILayoutPreset = {
switch direction {
case .bottomToTop: return .edgeTop;
case .topToBottom: return .edgeBottom;
case .leftToRight: return .edgeLeft;
case .rightToLeft: return .edgeRight;
};
}();

return self.init(snapPoint: snapPoint);
};

static func getDefault(
static func getDefaultInitialSnapPoint(
forDirection direction: AdaptiveModalConfig.Direction
) -> Self {
Self.init(
snapPoint: Self.getDefaultSnapPoint(forDirection: direction)
);

let snapPoint: RNILayoutPreset = {
switch direction {
case .bottomToTop: return .offscreenBottom;
case .topToBottom: return .offscreenTop;
case .leftToRight: return .offscreenLeft;
case .rightToLeft: return .offscreenRight;
};
}();

return self.init(snapPoint: snapPoint);
};
};

0 comments on commit b1cb0de

Please sign in to comment.