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 May 28, 2023
1 parent ec5a7e1 commit 36f9647
Show file tree
Hide file tree
Showing 7 changed files with 295 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,73 @@

import UIKit


struct AdaptiveModalInterpolationPoint {

static func compute(
modalConfig: AdaptiveModalConfig,
withTargetRect targetRect: CGRect,
currentSize: CGSize
) -> [Self] {
var items: [Self] = [];

for snapConfig in modalConfig.snapPoints {
let keyframe = snapConfig.animationKeyframe;
let prevKeyframe = items.last;

items.append(
Self.init(
withTargetRect : targetRect,
currentSize : currentSize,
snapPointConfig: snapConfig,

modalRadiusTopLeft: keyframe?.modalRadiusTopLeft
?? prevKeyframe?.modalRadiusTopLeft ?? 0,

modalRadiusTopRight: keyframe?.modalRadiusTopRight
?? prevKeyframe?.modalRadiusTopRight ?? 0,

modalRadiusBottomLeft: keyframe?.modalRadiusBottomLeft
?? prevKeyframe?.modalRadiusBottomLeft ?? 0,

modalRadiusBottomRight: keyframe?.modalRadiusBottomRight
?? prevKeyframe?.modalRadiusBottomRight ?? 0
)
);
};

return items;
};

/// The computed frames of the modal based on the snap points
let computedRect: CGRect;

let modalRadiusTopLeft: CGFloat;
let modalRadiusTopRight: CGFloat;
let modalRadiusBottomLeft: CGFloat;
let modalRadiusBottomRight: CGFloat;

init(
withTargetRect targetRect: CGRect,
currentSize: CGSize,
snapPointConfig: AdaptiveModalSnapPointConfig,
modalRadiusTopLeft: CGFloat,
modalRadiusTopRight: CGFloat,
modalRadiusBottomLeft: CGFloat,
modalRadiusBottomRight: CGFloat
) {
self.computedRect = snapPointConfig.snapPoint.computeRect(
withTargetRect: targetRect,
currentSize: currentSize
);

self.modalRadiusTopLeft = modalRadiusTopLeft;
self.modalRadiusTopRight = modalRadiusTopRight;
self.modalRadiusBottomLeft = modalRadiusBottomLeft;
self.modalRadiusBottomRight = modalRadiusBottomRight;
};
};

struct AdaptiveModalAnimationConfig {
let modalRotation: CGFloat?;

Expand All @@ -19,6 +86,11 @@ struct AdaptiveModalAnimationConfig {
let modalBackgroundColor: UIColor?;
let modalBackgroundOpacity: CGFloat?;

let modalRadiusTopLeft: CGFloat?;
let modalRadiusTopRight: CGFloat?;
let modalRadiusBottomLeft: CGFloat?;
let modalRadiusBottomRight: CGFloat?;

let modalBlurEffectStyle: UIBlurEffect.Style?;
let modalBlurEffectIntensity: CGFloat?;

Expand All @@ -36,6 +108,10 @@ struct AdaptiveModalAnimationConfig {
modalTranslateY: CGFloat? = nil,
modalBackgroundColor: UIColor? = nil,
modalBackgroundOpacity: CGFloat? = nil,
modalRadiusTopLeft: CGFloat? = nil,
modalRadiusTopRight: CGFloat? = nil,
modalRadiusBottomLeft: CGFloat? = nil,
modalRadiusBottomRight: CGFloat? = nil,
modalBlurEffectStyle: UIBlurEffect.Style? = nil,
modalBlurEffectIntensity: CGFloat? = nil,
backgroundColor: UIColor? = nil,
Expand All @@ -44,16 +120,27 @@ struct AdaptiveModalAnimationConfig {
backgroundBlurEffectIntensity: CGFloat? = nil
) {
self.modalRotation = modalRotation;

self.modalScaleX = modalScaleX;
self.modalScaleY = modalScaleY;

self.modalTranslateX = modalTranslateX;
self.modalTranslateY = modalTranslateY;

self.modalBackgroundColor = modalBackgroundColor;
self.modalBackgroundOpacity = modalBackgroundOpacity;

self.modalRadiusTopLeft = modalRadiusTopLeft;
self.modalRadiusTopRight = modalRadiusTopRight;
self.modalRadiusBottomLeft = modalRadiusBottomLeft;
self.modalRadiusBottomRight = modalRadiusBottomRight;

self.modalBlurEffectStyle = modalBlurEffectStyle;
self.modalBlurEffectIntensity = modalBlurEffectIntensity;

self.backgroundColor = backgroundColor;
self.backgroundOpacity = backgroundOpacity;

self.backgroundBlurEffectStyle = backgroundBlurEffectStyle;
self.backgroundBlurEffectIntensity = backgroundBlurEffectIntensity;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import UIKit

struct AdaptiveModalConfig {
enum Direction {
case horizontal;
case vertical;
case bottomToTop;
case topToBottom;
case leftToRight;
case rightToLeft;
};

// MARK: - Properties
Expand Down
Loading

0 comments on commit 36f9647

Please sign in to comment.