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 May 31, 2023
1 parent 1ad6487 commit b66705d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class AdaptiveModalManager {

var prevModalFrame: CGRect = .zero;

var modalViewMaskedCornersAnimator: AdaptiveModalPropertyAnimator?;
var backgroundVisualEffectAnimator: AdaptiveModalPropertyAnimator?;

// MARK: - Properties
Expand Down Expand Up @@ -316,35 +315,7 @@ class AdaptiveModalManager {
guard let modalCornerRadius = modalCornerRadius else { return nil };
return modalCornerRadius;
};

func applyInterpolationToModalMaskedCorners(
forInputValue inputValue: CGFloat
) {
guard let modalView = self.modalView,
let inputRange = self.getInterpolationStepRange(
forInputValue: inputValue
)
else { return };

let animator: AdaptiveModalPropertyAnimator = {
if let animator = self.backgroundVisualEffectAnimator {
return animator;
};

return AdaptiveModalPropertyAnimator(
interpolationRangeStart: inputRange.rangeStart,
interpolationRangeEnd: inputRange.rangeEnd,
forComponent: modalView,
withInputAxisKey: self.inputAxisKey
) {
$0.layer.maskedCorners = $1.modalMaskedCorners;
};
}();

self.modalViewMaskedCornersAnimator = animator;
animator.setFractionComplete(forInputValue: inputValue);
};


func applyInterpolationToBackgroundVisualEffect(
forInputValue inputValue: CGFloat
) {
Expand Down Expand Up @@ -395,7 +366,6 @@ class AdaptiveModalManager {
modalView.layer.cornerRadius = nextModalRadius;
};

self.applyInterpolationToModalMaskedCorners(forInputValue: inputValue);
self.applyInterpolationToBackgroundVisualEffect(forInputValue: inputValue);
};

Expand Down Expand Up @@ -436,8 +406,8 @@ class AdaptiveModalManager {
};

func clearAnimators(){
self.modalViewMaskedCornersAnimator?.clear();
self.modalViewMaskedCornersAnimator = nil;
self.backgroundVisualEffectAnimator?.clear();
self.backgroundVisualEffectAnimator = nil;
};

func animateModal(
Expand Down Expand Up @@ -482,6 +452,7 @@ class AdaptiveModalManager {

animator.addAnimations {
interpolationPoint.apply(toModalView: modalView);
modalView.layer.maskedCorners = interpolationPoint.modalMaskedCorners;
};

if let completion = completion {
Expand Down Expand Up @@ -641,8 +612,6 @@ class AdaptiveModalManager {
self.applyInterpolationToModal(forGesturePoint: gesturePoint);

case .cancelled, .ended:
// self.clearAnimators();

guard self.enableSnapping else {
self.clearGestureValues();
return;
Expand Down Expand Up @@ -674,24 +643,19 @@ class AdaptiveModalManager {
};

func updateModal(){
guard let modalView = self.modalView else { return };
guard let modalView = self.modalView,
self.animator == nil || !(self.animator?.isRunning ?? false)
else { return };


if let gesturePoint = self.gesturePoint {
self.applyInterpolationToModal(forGesturePoint: gesturePoint);

} else if modalView.frame == .zero,
let currentInterpolationStep = self.currentInterpolationStep {
} else if let currentInterpolationStep = self.currentInterpolationStep,
currentInterpolationStep.computedRect != modalView.frame {

currentInterpolationStep.apply(toModalView: modalView);

} else if let currentInterpolationStep = self.currentInterpolationStep {
currentInterpolationStep.apply(toModalView: modalView);

return;

currentInterpolationStep.apply(
toBackgroundEffectView: self.backgroundVisualEffectView
);
let inputRect = currentInterpolationStep.computedRect;
self.applyInterpolationToModal(forPoint: inputRect.origin);
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@ struct AdaptiveModalPropertyAnimator {
return didChange;
};

mutating func update(
interpolationRangeStart: AdaptiveModalInterpolationPoint,
interpolationRangeEnd: AdaptiveModalInterpolationPoint
){
let didChange =
interpolationRangeStart != self.interpolationRangeStart ||
interpolationRangeEnd != self.interpolationRangeEnd;

guard didChange else { return };

self.interpolationRangeStart = interpolationRangeStart;
self.interpolationRangeEnd = interpolationRangeEnd;
};

func setFractionComplete(forPercent percent: CGFloat) {
self.animator.fractionComplete = percent;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ enum AdaptiveModalConfigTestPresets: CaseIterable {
.layerMaxXMinYCorner,
.layerMaxXMaxYCorner
],
backgroundVisualEffect: UIBlurEffect(style: .prominent)
backgroundVisualEffect: UIBlurEffect(style: .regular)
)
),
],
Expand Down Expand Up @@ -153,7 +153,7 @@ class RNIDraggableTestViewController : UIViewController {

view.backgroundColor = UIColor(
hue: 0/360,
saturation: 50/100,
saturation: 0/100,
brightness: 100/100,
alpha: 1.0
);
Expand Down

0 comments on commit b66705d

Please sign in to comment.