diff --git a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift index f32db90f..af37a879 100644 --- a/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift +++ b/experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalManager.swift @@ -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, diff --git a/experiments/swift-programmatic-modal/RNILayout/RNILayout.swift b/experiments/swift-programmatic-modal/RNILayout/RNILayout.swift index 1b6d8bdd..82c0f026 100644 --- a/experiments/swift-programmatic-modal/RNILayout/RNILayout.swift +++ b/experiments/swift-programmatic-modal/RNILayout/RNILayout.swift @@ -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 @@ -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; diff --git a/experiments/swift-programmatic-modal/RNILayout/RNILayoutPreset.swift b/experiments/swift-programmatic-modal/RNILayout/RNILayoutPreset.swift index ce54ffdb..df2dfd16 100644 --- a/experiments/swift-programmatic-modal/RNILayout/RNILayoutPreset.swift +++ b/experiments/swift-programmatic-modal/RNILayout/RNILayoutPreset.swift @@ -154,7 +154,11 @@ enum RNILayoutPreset { ), height: RNILayoutValue( mode: .stretch - ) + ), + marginLeft: .constant(0), + marginRight: .constant(0), + marginTop: .constant(0), + marginBottom: .constant(0) ); case .fitScreenHorizontally: @@ -162,7 +166,9 @@ enum RNILayoutPreset { derivedFrom: baseLayoutConfig, width: RNILayoutValue( mode: .stretch - ) + ), + marginLeft: .constant(0), + marginRight: .constant(0) ); case .fitScreenVertically: @@ -170,7 +176,9 @@ enum RNILayoutPreset { derivedFrom: baseLayoutConfig, height: RNILayoutValue( mode: .stretch - ) + ), + marginTop: .constant(0), + marginBottom: .constant(0) ); case let .layoutConfig(config): diff --git a/experiments/swift-programmatic-modal/Test/RNIDraggableTestViewController.swift b/experiments/swift-programmatic-modal/Test/RNIDraggableTestViewController.swift index 631ca25c..306fa515 100644 --- a/experiments/swift-programmatic-modal/Test/RNIDraggableTestViewController.swift +++ b/experiments/swift-programmatic-modal/Test/RNIDraggableTestViewController.swift @@ -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, diff --git a/experiments/swift-programmatic-modal/Test/TestRoutes.swift b/experiments/swift-programmatic-modal/Test/TestRoutes.swift index b47ceafa..1911729f 100644 --- a/experiments/swift-programmatic-modal/Test/TestRoutes.swift +++ b/experiments/swift-programmatic-modal/Test/TestRoutes.swift @@ -8,7 +8,7 @@ import UIKit enum TestRoutes { - static let rootRouteKey: Self = .RNILayoutTest; + static let rootRouteKey: Self = .RNIDraggableTest; case RNILayoutTest; case RNIDraggableTest;