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 18, 2023
1 parent 9ce06dd commit 325cb81
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 34 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class AdaptiveModalManager: NSObject {
// ------------------------------------------

/// The computed frames of the modal based on the snap points
private(set) var rawInterpolationSteps: [AdaptiveModalInterpolationPoint]!;
private(set) var interpolationSteps: [AdaptiveModalInterpolationPoint]!;

var prevInterpolationIndex = 0;
var nextInterpolationIndex: Int?;
Expand All @@ -89,11 +89,6 @@ class AdaptiveModalManager: NSObject {
self.interpolationSteps[self.currentInterpolationIndex];
};

// sorted based on the modal direction
var interpolationSteps: [AdaptiveModalInterpolationPoint]! {
self.modalConfig.sortInterpolationSteps(self.rawInterpolationSteps);
};

private var interpolationRangeInput: [CGFloat]! {
self.interpolationSteps.map {
$0.percent
Expand Down Expand Up @@ -1077,7 +1072,7 @@ class AdaptiveModalManager: NSObject {
) {
let context = context ?? self.layoutValueContext;

self.rawInterpolationSteps = .Element.compute(
self.interpolationSteps = .Element.compute(
usingModalConfig: self.modalConfig,
layoutValueContext: context
);
Expand Down Expand Up @@ -1410,6 +1405,12 @@ class AdaptiveModalManager: NSObject {
if self.currentInterpolationIndex == 0 {
self.notifyOnModalDidHide();
};

print(
"self.interpolationSteps.computedRect: \n -",
self.interpolationSteps.map({ $0.computedRect }),
"\n"
);
};

private func notifyOnModalWillHide(){
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//
// RNILayoutValue+StaticInit.swift
// swift-programmatic-modal
//
// Created by Dominic Go on 6/19/23.
//

import UIKit

extension RNILayoutValue {

static let stretch: Self = .init(mode: .stretch);

static func stretch(
offsetValue: RNILayoutValueMode? = nil,
offsetOperation: RNIComputableOffset.OffsetOperation? = nil,
minValue: RNILayoutValueMode? = nil,
maxValue: RNILayoutValueMode? = nil
) -> Self {

return .init(
mode:. stretch,
offsetValue: offsetValue,
offsetOperation: offsetOperation,
minValue: minValue,
maxValue: maxValue
);
};

static func constant(_ constantValue: CGFloat) -> Self {
return .init(mode: .constant(constantValue))
};

static func percent(
relativeTo: RNILayoutValuePercentTarget = .targetSize,
percentValue: Double,
offsetValue: RNILayoutValueMode? = nil,
offsetOperation: RNIComputableOffset.OffsetOperation? = nil,
minValue: RNILayoutValueMode? = nil,
maxValue: RNILayoutValueMode? = nil
) -> Self {

return .init(
mode: .percent(
relativeTo: relativeTo,
percentValue: percentValue
),
offsetValue: offsetValue,
offsetOperation: offsetOperation,
minValue: minValue,
maxValue: maxValue
);
};

static func safeAreaInsets(
insetKey: KeyPath<UIEdgeInsets, CGFloat>,
offsetValue: RNILayoutValueMode? = nil,
offsetOperation: RNIComputableOffset.OffsetOperation? = nil,
minValue: RNILayoutValueMode? = nil,
maxValue: RNILayoutValueMode? = nil
) -> Self {

return .init(
mode: .safeAreaInsets(insetKey: insetKey),
offsetValue: offsetValue,
offsetOperation: offsetOperation,
minValue: minValue,
maxValue: maxValue
);
};

static func multipleValues(
_ values: [RNILayoutValueMode],
offsetValue: RNILayoutValueMode? = nil,
offsetOperation: RNIComputableOffset.OffsetOperation? = nil,
minValue: RNILayoutValueMode? = nil,
maxValue: RNILayoutValueMode? = nil
) -> Self {

return .init(
mode: .multipleValues(values),
offsetValue: offsetValue,
offsetOperation: offsetOperation,
minValue: minValue,
maxValue: maxValue
);
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ import UIKit

public struct RNILayoutValue {

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

public enum Axis {
case horizontal, vertical;
};

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import UIKit

enum AdaptiveModalConfigTestPresets: CaseIterable {

static let `default`: Self = .demo03;
static let `default`: Self = .testTopToBottom;

case testModalTransform01;
case testModalTransformScale;
case testModalBorderAndShadow01;
case testLeftToRight;
case testTopToBottom;

case test01;
case test02;
Expand Down Expand Up @@ -281,6 +282,23 @@ enum AdaptiveModalConfigTestPresets: CaseIterable {
layoutPreset: .edgeRight
)
);

case .testTopToBottom: return AdaptiveModalConfig(
snapPoints: [
.init(
snapPoint: .init(
horizontalAlignment: .center,
verticalAlignment: .top,
width: .stretch,
height: .percent(percentValue: 0.2)
)
)
],
snapDirection: .topToBottom,
overshootSnapPoint: .init(
layoutPreset: .fitScreenVertically
)
);

case .test01: return AdaptiveModalConfig(
snapPoints: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,19 @@ class AdaptiveModalPresentationTestViewController : UIViewController {
.demo03
];

var currentModalConfigPresetIndex = 0;
var currentModalConfigPresetCounter = 0;

var currentModalConfigPresetIndex: Int {
self.currentModalConfigPresetCounter % self.modalConfigs.count
};

var currentModalConfigPreset: AdaptiveModalConfigTestPresets {
self.modalConfigs[self.currentModalConfigPresetIndex % self.modalConfigs.count];
//self.modalConfigs[self.currentModalConfigPresetIndex];
AdaptiveModalConfigTestPresets.default;
};

var counterLabel: UILabel?;

override func viewDidLoad() {
self.view.backgroundColor = .white;

Expand All @@ -125,6 +132,18 @@ class AdaptiveModalPresentationTestViewController : UIViewController {
dummyBackgroundView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor),
]);

let counterLabel: UILabel = {
let label = UILabel();

label.text = "\(self.currentModalConfigPresetIndex)";
label.font = .systemFont(ofSize: 24, weight: .bold);
label.textColor = .white;

self.counterLabel = label;

return label;
}();

let presentButton: UIButton = {
let button = UIButton();
button.setTitle("Present View Controller", for: .normal);
Expand Down Expand Up @@ -160,6 +179,7 @@ class AdaptiveModalPresentationTestViewController : UIViewController {
stack.alignment = .center;
stack.spacing = 7;

stack.addArrangedSubview(counterLabel);
stack.addArrangedSubview(presentButton);
stack.addArrangedSubview(nextConfigButton);

Expand Down Expand Up @@ -193,7 +213,9 @@ class AdaptiveModalPresentationTestViewController : UIViewController {
};

@objc func onPressButtonNextConfig(_ sender: UIButton) {
self.currentModalConfigPresetIndex += 1;
self.currentModalConfigPresetCounter += 1;
self.counterLabel!.text = "\(self.currentModalConfigPresetIndex)";

self.adaptiveModalManager.modalConfig = self.currentModalConfigPreset.config;
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
880492582A23F89000D74E9F /* AdaptiveModalInterpolationPoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 880492572A23F89000D74E9F /* AdaptiveModalInterpolationPoint.swift */; };
88075E272A2121FE00B78388 /* AdaptiveModalUtilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88075E262A2121FE00B78388 /* AdaptiveModalUtilities.swift */; };
88203DC12A122AC20088C8E2 /* RNIDynamicModal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88203DC02A122AC20088C8E2 /* RNIDynamicModal.swift */; };
8849B6A72A3F7A7700A5F412 /* RNILayoutValue+StaticInit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8849B6A62A3F7A7700A5F412 /* RNILayoutValue+StaticInit.swift */; };
884A18F82A30516B0044AA66 /* AdaptiveModalPresentationTestViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 884A18F72A30516B0044AA66 /* AdaptiveModalPresentationTestViewController.swift */; };
884A18FA2A3146CA0044AA66 /* AdaptiveModalManager+UIViewControllerTransitioningDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 884A18F92A3146CA0044AA66 /* AdaptiveModalManager+UIViewControllerTransitioningDelegate.swift */; };
884A18FC2A3146FC0044AA66 /* AdaptiveModalManager+UIViewControllerAnimatedTransitioning.swift in Sources */ = {isa = PBXBuildFile; fileRef = 884A18FB2A3146FC0044AA66 /* AdaptiveModalManager+UIViewControllerAnimatedTransitioning.swift */; };
Expand Down Expand Up @@ -95,7 +96,6 @@
88D018822A1D09DD004664D2 /* AdaptiveModalAnimationConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88D018812A1D09DD004664D2 /* AdaptiveModalAnimationConfig.swift */; };
88D018862A1D0A1D004664D2 /* AdaptiveModalSnapPoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88D018852A1D0A1D004664D2 /* AdaptiveModalSnapPoint.swift */; };
88D018882A1D0A36004664D2 /* AdaptiveModalConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88D018872A1D0A36004664D2 /* AdaptiveModalConfig.swift */; };
88D0188C2A1DB02E004664D2 /* AdaptiveModalEntranceConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88D0188B2A1DB02E004664D2 /* AdaptiveModalEntranceConfig.swift */; };
88D0188E2A1DCA61004664D2 /* AdaptiveModalManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88D0188D2A1DCA61004664D2 /* AdaptiveModalManager.swift */; };
88E8C0182A224A8D008C2FF8 /* AdaptiveModalSnapAnimationConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88E8C0172A224A8D008C2FF8 /* AdaptiveModalSnapAnimationConfig.swift */; };
88E8C01A2A228289008C2FF8 /* AdaptiveModalClampingConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88E8C0192A228289008C2FF8 /* AdaptiveModalClampingConfig.swift */; };
Expand All @@ -107,6 +107,7 @@
880492572A23F89000D74E9F /* AdaptiveModalInterpolationPoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdaptiveModalInterpolationPoint.swift; sourceTree = "<group>"; };
88075E262A2121FE00B78388 /* AdaptiveModalUtilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdaptiveModalUtilities.swift; sourceTree = "<group>"; };
88203DC02A122AC20088C8E2 /* RNIDynamicModal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RNIDynamicModal.swift; sourceTree = "<group>"; };
8849B6A62A3F7A7700A5F412 /* RNILayoutValue+StaticInit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RNILayoutValue+StaticInit.swift"; sourceTree = "<group>"; };
884A18F72A30516B0044AA66 /* AdaptiveModalPresentationTestViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdaptiveModalPresentationTestViewController.swift; sourceTree = "<group>"; };
884A18F92A3146CA0044AA66 /* AdaptiveModalManager+UIViewControllerTransitioningDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AdaptiveModalManager+UIViewControllerTransitioningDelegate.swift"; sourceTree = "<group>"; };
884A18FB2A3146FC0044AA66 /* AdaptiveModalManager+UIViewControllerAnimatedTransitioning.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AdaptiveModalManager+UIViewControllerAnimatedTransitioning.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -196,7 +197,6 @@
88D018812A1D09DD004664D2 /* AdaptiveModalAnimationConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdaptiveModalAnimationConfig.swift; sourceTree = "<group>"; };
88D018852A1D0A1D004664D2 /* AdaptiveModalSnapPoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdaptiveModalSnapPoint.swift; sourceTree = "<group>"; };
88D018872A1D0A36004664D2 /* AdaptiveModalConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdaptiveModalConfig.swift; sourceTree = "<group>"; };
88D0188B2A1DB02E004664D2 /* AdaptiveModalEntranceConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdaptiveModalEntranceConfig.swift; sourceTree = "<group>"; };
88D0188D2A1DCA61004664D2 /* AdaptiveModalManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdaptiveModalManager.swift; sourceTree = "<group>"; };
88E8C0172A224A8D008C2FF8 /* AdaptiveModalSnapAnimationConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdaptiveModalSnapAnimationConfig.swift; sourceTree = "<group>"; };
88E8C0192A228289008C2FF8 /* AdaptiveModalClampingConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdaptiveModalClampingConfig.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -433,6 +433,7 @@
886AFCB02A325B6F004AC9FB /* RNILayoutValueContext.swift */,
886AFCAC2A3209D5004AC9FB /* RNILayoutValueMode.swift */,
886AFCAE2A320DED004AC9FB /* RNILayoutValuePercentTarget.swift */,
8849B6A62A3F7A7700A5F412 /* RNILayoutValue+StaticInit.swift */,
);
path = RNILayout;
sourceTree = "<group>";
Expand Down Expand Up @@ -543,7 +544,6 @@
88D018812A1D09DD004664D2 /* AdaptiveModalAnimationConfig.swift */,
88D018852A1D0A1D004664D2 /* AdaptiveModalSnapPoint.swift */,
88C2F45B2A275B2800DA7450 /* AdaptiveModalSnapPointPreset.swift */,
88D0188B2A1DB02E004664D2 /* AdaptiveModalEntranceConfig.swift */,
88E8C0172A224A8D008C2FF8 /* AdaptiveModalSnapAnimationConfig.swift */,
88E8C0192A228289008C2FF8 /* AdaptiveModalClampingConfig.swift */,
88D018872A1D0A36004664D2 /* AdaptiveModalConfig.swift */,
Expand Down Expand Up @@ -666,7 +666,6 @@
88D0184A2A1B3030004664D2 /* RNILayout.swift in Sources */,
88D018472A1B3030004664D2 /* RNIDictionarySynthesizable+Default.swift in Sources */,
88D0184B2A1B3030004664D2 /* RNIAnimatorSize.swift in Sources */,
88D0188C2A1DB02E004664D2 /* AdaptiveModalEntranceConfig.swift in Sources */,
88D0183B2A1B3030004664D2 /* Collection+Helpers.swift in Sources */,
88D0188E2A1DCA61004664D2 /* AdaptiveModalManager.swift in Sources */,
88D018772A1B3030004664D2 /* RNIComputableValue.swift in Sources */,
Expand All @@ -692,6 +691,7 @@
88D0187E2A1B6CB3004664D2 /* BlurEffectTestViewController.swift in Sources */,
88D018272A1B3030004664D2 /* RNIInternalCleanupMode.swift in Sources */,
88D018782A1B3030004664D2 /* RNIComputableSize.swift in Sources */,
8849B6A72A3F7A7700A5F412 /* RNILayoutValue+StaticInit.swift in Sources */,
88D018732A1B3030004664D2 /* RNIModalCustomSheetDetent.swift in Sources */,
88075E272A2121FE00B78388 /* AdaptiveModalUtilities.swift in Sources */,
88D018252A1B3030004664D2 /* UIViewController+Helpers.swift in Sources */,
Expand Down

0 comments on commit 325cb81

Please sign in to comment.