Skip to content

Commit

Permalink
💫 Update: Exp - AdaptiveModal
Browse files Browse the repository at this point in the history
Related:
* `TODO:2023-06-04-23-45-31` - Impl: Adaptive Modal - `LayoutComputableValue`.

Summary: Update experiment/test - `swift-programmatic-modal/AdaptiveModal`.
  • Loading branch information
dominicstop committed Jun 8, 2023
1 parent 773c5fa commit 546b292
Show file tree
Hide file tree
Showing 12 changed files with 654 additions and 253 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,14 @@ struct AdaptiveModalInterpolationPoint: Equatable {
usingModalConfig modalConfig: AdaptiveModalConfig,
snapPointIndex: Int,
percent: CGFloat? = nil,
withTargetRect targetRect: CGRect,
currentSize: CGSize,
layoutValueContext context: RNILayoutValueContext,
snapPointConfig: AdaptiveModalSnapPointConfig,
prevInterpolationPoint keyframePrev: Self? = nil
) {
self.snapPointIndex = snapPointIndex;

let computedRect = snapPointConfig.snapPoint.computeRect(
withTargetRect: targetRect,
currentSize: currentSize
usingLayoutValueContext: context
);

self.computedRect = computedRect;
Expand All @@ -106,7 +104,7 @@ struct AdaptiveModalInterpolationPoint: Equatable {
switch modalConfig.snapPercentStrategy {
case .position:
let maxRangeInput =
targetRect[keyPath: modalConfig.maxInputRangeKeyForRect];
context.targetRect[keyPath: modalConfig.maxInputRangeKeyForRect];

let inputValue =
computedRect.origin[keyPath: modalConfig.inputValueKeyForPoint];
Expand Down Expand Up @@ -280,8 +278,7 @@ extension AdaptiveModalInterpolationPoint {

static func compute(
usingModalConfig modalConfig: AdaptiveModalConfig,
withTargetRect targetRect: CGRect,
currentSize: CGSize
layoutValueContext context: RNILayoutValueContext
) -> [Self] {

var items: [AdaptiveModalInterpolationPoint] = [];
Expand Down Expand Up @@ -310,8 +307,7 @@ extension AdaptiveModalInterpolationPoint {
AdaptiveModalInterpolationPoint(
usingModalConfig: modalConfig,
snapPointIndex: index,
withTargetRect: targetRect,
currentSize: currentSize,
layoutValueContext: context,
snapPointConfig: snapConfig,
prevInterpolationPoint: items.last
)
Expand All @@ -323,17 +319,14 @@ extension AdaptiveModalInterpolationPoint {

let overshootSnapPointConfig = AdaptiveModalSnapPointConfig(
fromSnapPointPreset: modalConfig.overshootSnapPoint,
fromBaseLayoutConfig: prevSnapPointConfig.snapPoint,
withTargetRect: targetRect,
currentSize: currentSize
fromBaseLayoutConfig: prevSnapPointConfig.snapPoint
);

return AdaptiveModalInterpolationPoint(
usingModalConfig: modalConfig,
snapPointIndex: modalConfig.snapPointLastIndex + 1,
percent: 1,
withTargetRect: targetRect,
currentSize: currentSize,
layoutValueContext: context,
snapPointConfig: overshootSnapPointConfig,
prevInterpolationPoint: items.last
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,18 @@ class AdaptiveModalManager: NSObject {
return targetView.frame[keyPath: self.modalConfig.maxInputRangeKeyForRect];
};

var layoutValueContext: RNILayoutValueContext? {
if let targetVC = self.targetViewController {
return .init(fromTargetViewController: targetVC);
};

if let targetView = self.targetView {
return .init(fromTargetView: targetView);
};

return nil;
};

// MARK: - Init
// ------------

Expand Down Expand Up @@ -1073,20 +1085,17 @@ class AdaptiveModalManager: NSObject {
self.setupViewConstraints();
};

func computeSnapPoints(forTargetView nextTargetView: UIView? = nil) {
if nextTargetView != nil {
self.targetView = nextTargetView;
};

guard let targetView = nextTargetView ?? self.targetView
func computeSnapPoints(
usingLayoutValueContext context: RNILayoutValueContext? = nil
) {
guard let context = context ?? self.layoutValueContext
else { return };

let currentSize = self.currentSizeProvider?() ?? .zero;

self.interpolationSteps = .Element.compute(
usingModalConfig: self.modalConfig,
withTargetRect: targetView.frame,
currentSize: currentSize
layoutValueContext: context
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,12 @@ struct AdaptiveModalSnapPointConfig {

init(
fromSnapPointPreset snapPointPreset: AdaptiveModalSnapPointPreset,
fromBaseLayoutConfig baseLayoutConfig: RNILayout,
withTargetRect targetRect: CGRect,
currentSize: CGSize
fromBaseLayoutConfig baseLayoutConfig: RNILayout
) {
let snapPointLayoutPreset = snapPointPreset.snapPointPreset;

let snapPointLayout = snapPointLayoutPreset.getLayoutConfig(
fromBaseLayoutConfig: baseLayoutConfig,
withTargetRect: targetRect,
currentSize: currentSize
fromBaseLayoutConfig: baseLayoutConfig
);

self.snapPoint = snapPointLayout;
Expand Down
Loading

0 comments on commit 546b292

Please sign in to comment.