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 e1c01dd commit a674772
Show file tree
Hide file tree
Showing 24 changed files with 584 additions and 368 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,42 @@

import UIKit


struct AdaptiveModalAnimationConfig {
var modalRotation: CGFloat?;
public struct AdaptiveModalAnimationConfig {
public var modalRotation: CGFloat?;

var modalScaleX: CGFloat?;
var modalScaleY: CGFloat?;
public var modalScaleX: CGFloat?;
public var modalScaleY: CGFloat?;

var modalTranslateX: CGFloat?;
var modalTranslateY: CGFloat?;
public var modalTranslateX: CGFloat?;
public var modalTranslateY: CGFloat?;

var modalBorderWidth: CGFloat?;
var modalBorderColor: UIColor?;
public var modalBorderWidth: CGFloat?;
public var modalBorderColor: UIColor?;

var modalShadowColor: UIColor?;
var modalShadowOffset: CGSize?;
var modalShadowOpacity: CGFloat?;
var modalShadowRadius: CGFloat?;
public var modalShadowColor: UIColor?;
public var modalShadowOffset: CGSize?;
public var modalShadowOpacity: CGFloat?;
public var modalShadowRadius: CGFloat?;

var modalCornerRadius: CGFloat?;
var modalMaskedCorners: CACornerMask?;
public var modalCornerRadius: CGFloat?;
public var modalMaskedCorners: CACornerMask?;

var modalOpacity: CGFloat?;
var modalBackgroundColor: UIColor?;
var modalBackgroundOpacity: CGFloat?;
public var modalOpacity: CGFloat?;
public var modalBackgroundColor: UIColor?;
public var modalBackgroundOpacity: CGFloat?;

var modalBackgroundVisualEffect: UIVisualEffect?;
var modalBackgroundVisualEffectOpacity: CGFloat?;
var modalBackgroundVisualEffectIntensity: CGFloat?;
public var modalBackgroundVisualEffect: UIVisualEffect?;
public var modalBackgroundVisualEffectOpacity: CGFloat?;
public var modalBackgroundVisualEffectIntensity: CGFloat?;

var backgroundColor: UIColor?;
var backgroundOpacity: CGFloat?;
public var backgroundColor: UIColor?;
public var backgroundOpacity: CGFloat?;

var backgroundVisualEffect: UIVisualEffect?;
var backgroundVisualEffectOpacity: CGFloat?;
var backgroundVisualEffectIntensity: CGFloat?;
public var backgroundVisualEffect: UIVisualEffect?;
public var backgroundVisualEffectOpacity: CGFloat?;
public var backgroundVisualEffectIntensity: CGFloat?;

init(
public init(
modalRotation: CGFloat? = nil,
modalScaleX: CGFloat? = nil,
modalScaleY: CGFloat? = nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,37 @@

import Foundation

struct AdaptiveModalClampingConfig {
static let `default`: Self = .init();
public struct AdaptiveModalClampingConfig {
public static let `default`: Self = .init();

let shouldClampModalInitHeight: Bool;
let shouldClampModalLastHeight: Bool;
public let shouldClampModalInitHeight: Bool;
public let shouldClampModalLastHeight: Bool;

let shouldClampModalInitWidth: Bool;
let shouldClampModalLastWidth: Bool;
public let shouldClampModalInitWidth: Bool;
public let shouldClampModalLastWidth: Bool;

let shouldClampModalInitX: Bool;
let shouldClampModalLastX: Bool;
public let shouldClampModalInitX: Bool;
public let shouldClampModalLastX: Bool;

let shouldClampModalInitY: Bool;
let shouldClampModalLastY: Bool;
public let shouldClampModalInitY: Bool;
public let shouldClampModalLastY: Bool;

let shouldClampModalInitRotation: Bool;
let shouldClampModalLastRotation: Bool;
public let shouldClampModalInitRotation: Bool;
public let shouldClampModalLastRotation: Bool;

let shouldClampModalInitScaleX: Bool;
let shouldClampModalLastScaleX: Bool;
public let shouldClampModalInitScaleX: Bool;
public let shouldClampModalLastScaleX: Bool;

let shouldClampModalInitScaleY: Bool;
let shouldClampModalLastScaleY: Bool;
public let shouldClampModalInitScaleY: Bool;
public let shouldClampModalLastScaleY: Bool;

let shouldClampModalInitTranslateX: Bool;
let shouldClampModalLastTranslateX: Bool;
public let shouldClampModalInitTranslateX: Bool;
public let shouldClampModalLastTranslateX: Bool;

let shouldClampModalInitTranslateY: Bool;
let shouldClampModalLastTranslateY: Bool;
public let shouldClampModalInitTranslateY: Bool;
public let shouldClampModalLastTranslateY: Bool;

init(
public init(
shouldClampModalInitHeight: Bool = false,
shouldClampModalLastHeight: Bool = false,
shouldClampModalInitWidth: Bool = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,65 +7,69 @@

import UIKit

struct AdaptiveModalConfig {
enum Direction {
public struct AdaptiveModalConfig {

// MARK: - Types
// -------------

public enum Direction {
case bottomToTop;
case topToBottom;
case leftToRight;
case rightToLeft;
};

enum SnapPercentStrategy {
public enum SnapPercentStrategy {
case index;
case position;
};

// MARK: - Properties
// ------------------

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

let snapPercentStrategy: SnapPercentStrategy;
public let snapPercentStrategy: SnapPercentStrategy;

let snapAnimationConfig: AdaptiveModalSnapAnimationConfig;
let interpolationClampingConfig: AdaptiveModalClampingConfig;
public let snapAnimationConfig: AdaptiveModalSnapAnimationConfig;
public let interpolationClampingConfig: AdaptiveModalClampingConfig;

let undershootSnapPoint: AdaptiveModalSnapPointPreset;
let overshootSnapPoint: AdaptiveModalSnapPointPreset;
public let undershootSnapPoint: AdaptiveModalSnapPointPreset;
public let overshootSnapPoint: AdaptiveModalSnapPointPreset;

// the first snap point to snap to when the modal is first shown
let initialSnapPointIndex: Int;
public let initialSnapPointIndex: Int;

// let entranceConfig: AdaptiveModalEntranceConfig;
// let snapSwipeVelocityThreshold: CGFloat = 0;

// MARK: - Computed Properties
// ---------------------------

var snapPoints: [AdaptiveModalSnapPointConfig] {
public var snapPoints: [AdaptiveModalSnapPointConfig] {
.Element.deriveSnapPoints(
undershootSnapPoint: self.undershootSnapPoint,
inBetweenSnapPoints: self.baseSnapPoints,
overshootSnapPoint: self.overshootSnapPoint
);
};

var overshootSnapPointIndex: Int {
public var overshootSnapPointIndex: Int {
self.snapPoints.count - 1;
};

/// Defines which axis of the gesture point to use to drive the interpolation
/// of the modal snap points
///
var inputValueKeyForPoint: KeyPath<CGPoint, CGFloat> {
public var inputValueKeyForPoint: KeyPath<CGPoint, CGFloat> {
switch self.snapDirection {
case .topToBottom, .bottomToTop: return \.y;
case .leftToRight, .rightToLeft: return \.x;
};
};

var inputValueKeyForRect: KeyPath<CGRect, CGFloat> {
public var inputValueKeyForRect: KeyPath<CGRect, CGFloat> {
switch self.snapDirection {
case .bottomToTop: return \.minY;
case .topToBottom: return \.maxY;
Expand All @@ -74,14 +78,14 @@ struct AdaptiveModalConfig {
};
};

var maxInputRangeKeyForRect: KeyPath<CGRect, CGFloat> {
public var maxInputRangeKeyForRect: KeyPath<CGRect, CGFloat> {
switch self.snapDirection {
case .bottomToTop, .topToBottom: return \.height;
case .leftToRight, .rightToLeft: return \.width;
};
};

var shouldInvertPercent: Bool {
public var shouldInvertPercent: Bool {
switch self.snapDirection {
case .bottomToTop, .rightToLeft: return true;
default: return false;
Expand All @@ -91,7 +95,7 @@ struct AdaptiveModalConfig {
// MARK: - Init
// ------------

init(
public init(
snapPoints: [AdaptiveModalSnapPointConfig],
snapDirection: Direction,
snapPercentStrategy: SnapPercentStrategy = .position,
Expand Down Expand Up @@ -121,7 +125,7 @@ struct AdaptiveModalConfig {
// MARK: - Functions
// -----------------

func sortInterpolationSteps<T>(_ array: [T]) -> [T] {
public func sortInterpolationSteps<T>(_ array: [T]) -> [T] {
switch self.snapDirection {
case .bottomToTop, .leftToRight:
return array;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation


protocol AdaptiveModalEventNotifiable: AnyObject {
public protocol AdaptiveModalEventNotifiable: AnyObject {

func notifyOnModalWillSnap(
prevSnapPointIndex: Int?,
Expand Down
Loading

0 comments on commit a674772

Please sign in to comment.