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 2, 2023
1 parent 7799c6e commit 767e925
Showing 1 changed file with 33 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class AdaptiveModalManager {
weak var modalView: UIView?;
weak var backgroundVisualEffectView: UIVisualEffectView?;

var displayLinkStartTimestamp: CFTimeInterval?;

var gestureOffset: CGPoint?;
var gestureVelocity: CGPoint?;
var gestureInitialPoint: CGPoint?;
Expand Down Expand Up @@ -67,7 +69,15 @@ class AdaptiveModalManager {
};

var isAnimating: Bool {
self.animator != nil || !(self.animator?.isRunning ?? false);
self.animator != nil || (self.animator?.isRunning ?? false);
};

var displayLinkEndTimestamp: CFTimeInterval? {
guard let animator = self.animator,
let displayLinkStartTimestamp = self.displayLinkStartTimestamp
else { return nil };

return displayLinkStartTimestamp + animator.duration;
};

var currentSnapPointConfig: AdaptiveModalSnapPointConfig {
Expand Down Expand Up @@ -156,23 +166,6 @@ class AdaptiveModalManager {
return targetView.frame[keyPath: self.modalConfig.maxInputRangeKeyForRect];
};

var currentPercent: CGFloat? {
guard let modalView = self.modalView,
let interpolationRangeMaxInput = self.interpolationRangeMaxInput
else {
return self.currentInterpolationStep?.percent;
};

let inputCoord =
modalView.frame.origin[keyPath: self.modalConfig.inputValueKeyForPoint];

let percent = inputCoord / interpolationRangeMaxInput;

return self.modalConfig.shouldInvertPercent
? Self.invertPercent(percent)
: percent;
};

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

Expand Down Expand Up @@ -367,6 +360,10 @@ class AdaptiveModalManager {
};
}();

print(
"applyInterpolationToBackgroundVisualEffect - inputPercentValue: \(inputPercentValue)"
);

self.backgroundVisualEffectAnimator = animator;
animator.setFractionComplete(forInputPercentValue: inputPercentValue);
};
Expand Down Expand Up @@ -630,25 +627,39 @@ class AdaptiveModalManager {
@objc func onDisplayLinkTick(displayLink: CADisplayLink) {
guard let modalView = self.modalView,
let modalViewPresentationLayer = modalView.layer.presentation(),
let currentPercent = self.currentPercent
let interpolationRangeMaxInput = self.interpolationRangeMaxInput
else { return };

if self.isSwiping {
self.endDisplayLink();
};

if self.displayLinkStartTimestamp == nil {
self.displayLinkStartTimestamp = displayLink.timestamp;
};

let prevModalFrame = self.prevModalFrame;
let nextModalFrame = modalViewPresentationLayer.frame;

guard prevModalFrame != nextModalFrame else { return };

let inputCoord =
nextModalFrame.origin[keyPath: self.modalConfig.inputValueKeyForPoint];

let percent = inputCoord / interpolationRangeMaxInput;

let percentAdj = self.modalConfig.shouldInvertPercent
? Self.invertPercent(percent)
: percent;


self.applyInterpolationToBackgroundVisualEffect(
forInputPercentValue: currentPercent
forInputPercentValue: percentAdj
);

print(
"onDisplayLinkTick"
+ " - currentPercent: \(currentPercent)"
+ " - percentAdj: \(percentAdj)"
);

self.prevModalFrame = nextModalFrame;
Expand Down Expand Up @@ -724,7 +735,7 @@ class AdaptiveModalManager {

func updateModal(){
guard let modalView = self.modalView,
self.isAnimating
!self.isAnimating
else { return };

if let gesturePoint = self.gesturePoint {
Expand Down

0 comments on commit 767e925

Please sign in to comment.