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 084b844 commit 387e188
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1088,10 +1088,7 @@ class AdaptiveModalManager: NSObject {
func computeSnapPoints(
usingLayoutValueContext context: RNILayoutValueContext? = nil
) {
guard let context = context ?? self.layoutValueContext
else { return };

let currentSize = self.currentSizeProvider?() ?? .zero;
guard let context = context ?? self.layoutValueContext else { return };

self.interpolationSteps = .Element.compute(
usingModalConfig: self.modalConfig,
Expand Down
54 changes: 34 additions & 20 deletions experiments/swift-programmatic-modal/RNILayout/RNILayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,7 @@ public struct RNILayout {
rect.origin.x = rect.origin.x - marginRight;

case .center:
if case .stretch = self.width.mode {
rect.size.width = rect.size.width - computedMarginHorizontal;

// re-compute origin
rect = self.computeRawRectOrigin(
usingLayoutValueContext: context,
forRect: rect,
ignoreYAxis: true
);
};
break;
};

// Margin - Y-Axis
Expand All @@ -242,16 +233,39 @@ public struct RNILayout {
rect.origin.y = rect.origin.y - marginBottom;

case .center:
if case .stretch = self.height.mode {
rect.size.height = rect.size.height - computedMargiVertical;

// re-compute origin
rect = self.computeRawRectOrigin(
usingLayoutValueContext: context,
forRect: rect,
ignoreXAxis: true
);
};
break;
};

let shouldRecomputeXAxis: Bool = {
switch self.width.mode {
case .stretch: return true;
default: return false;
};
}();

let shouldRecomputeYAxis: Bool = {
switch self.height.mode {
case .stretch: return true;
default: return false;
};
}();

if shouldRecomputeXAxis {
rect.size.width = rect.size.width - computedMarginHorizontal;
};

if shouldRecomputeYAxis {
rect.size.height = rect.size.height - computedMargiVertical;
};

if shouldRecomputeXAxis || shouldRecomputeYAxis {
// re-compute origin
rect = self.computeRawRectOrigin(
usingLayoutValueContext: context,
forRect: rect,
ignoreXAxis: !shouldRecomputeXAxis,
ignoreYAxis: !shouldRecomputeYAxis
);
};

return rect;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,23 +154,31 @@ enum RNILayoutPreset {
),
height: RNILayoutValue(
mode: .stretch
)
),
marginLeft: .constant(0),
marginRight: .constant(0),
marginTop: .constant(0),
marginBottom: .constant(0)
);

case .fitScreenHorizontally:
return .init(
derivedFrom: baseLayoutConfig,
width: RNILayoutValue(
mode: .stretch
)
),
marginLeft: .constant(0),
marginRight: .constant(0)
);

case .fitScreenVertically:
return .init(
derivedFrom: baseLayoutConfig,
height: RNILayoutValue(
mode: .stretch
)
),
marginTop: .constant(0),
marginBottom: .constant(0)
);

case let .layoutConfig(config):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,9 @@ enum AdaptiveModalConfigTestPresets: CaseIterable {
mode: .stretch
),
height: RNILayoutValue(
mode: .percent(percentValue: 0.95),
maxValue: .constant(ScreenSize.iPhone8.size.height)
)
mode: .stretch
),
marginTop: .safeAreaInsets(insetKey: \.top)
),
animationKeyframe: AdaptiveModalAnimationConfig(
modalBackgroundOpacity: 0.83,
Expand Down
2 changes: 1 addition & 1 deletion experiments/swift-programmatic-modal/Test/TestRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import UIKit

enum TestRoutes {
static let rootRouteKey: Self = .RNILayoutTest;
static let rootRouteKey: Self = .RNIDraggableTest;

case RNILayoutTest;
case RNIDraggableTest;
Expand Down

0 comments on commit 387e188

Please sign in to comment.