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 d56cd14 commit 3a97f74
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ struct AdaptiveModalInterpolationPoint {
let modalRadiusBottomRight: CGFloat;

var modalRadiusMask: CAShapeLayer {
let bounds = CGRect(
origin: .zero,
size: self.computedRect.size
);

let radiusPath = UIBezierPath(
shouldRoundRect: CGRect(
origin: .zero,
size: self.computedRect.size
),
shouldRoundRect: bounds,
topLeftRadius: self.modalRadiusTopLeft,
topRightRadius: self.modalRadiusTopRight,
bottomLeftRadius: self.modalRadiusBottomLeft,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,32 @@

import UIKit

class MaskedView: UIView {
var maskShape: CAShapeLayer?;

var maskingView: UIView?;

override init(frame: CGRect) {
self.maskingView = UIView(frame: frame);
self.maskingView!.backgroundColor = .blue;

super.init(frame: frame);

self.mask = self.maskingView;
};

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func layoutSubviews() {
super.layoutSubviews();

self.maskingView!.frame = self.frame;
print("MaskedView.layoutSubviews - frame: \(self.frame)")
};
};


class AdaptiveModalManager {

Expand All @@ -24,7 +50,7 @@ class AdaptiveModalManager {
var currentSizeProvider: () -> CGSize;

weak var targetView: UIView?;
weak var modalView: UIView?;
weak var modalView: MaskedView?;

var gestureOffset: CGFloat?;
var gestureVelocity: CGPoint?;
Expand Down Expand Up @@ -150,7 +176,7 @@ class AdaptiveModalManager {

init(
modalConfig: AdaptiveModalConfig,
modalView: UIView,
modalView: MaskedView,
targetView: UIView,
currentSizeProvider: @escaping () -> CGSize
) {
Expand Down Expand Up @@ -327,7 +353,7 @@ class AdaptiveModalManager {
forInputValue: gestureInput,
modalBounds: modalView.bounds
) {
modalView.layer.mask = modalBorderRadiusMask;
modalView.maskShape = modalBorderRadiusMask;
};
};

Expand Down Expand Up @@ -383,6 +409,8 @@ class AdaptiveModalManager {

animator.addAnimations {
modalView.frame = interpolationPoint.computedRect;
modalView.maskShape = interpolationPoint.modalRadiusMask;
modalView.layoutSubviews();
};

if let completion = completion {
Expand All @@ -392,7 +420,7 @@ class AdaptiveModalManager {
animator.addCompletion { _ in
self.animator = nil;
};

animator.startAnimation();
};

Expand Down Expand Up @@ -493,6 +521,7 @@ class AdaptiveModalManager {
};

@objc func onDisplayLinkTick(displayLink: CADisplayLink){
return;
/// `Note:2023-05-30-16-13-29`
///
/// The interpolation can be driven by either via **Method-A** or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ extension UIBezierPath {
} else {
path.addLine(to: topLeft);
};



path.closeSubpath();
cgPath = path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ class RNIDraggableTestViewController : UIViewController {
return label;
}();

lazy var floatingView: UIView = {
let view = UIView();
lazy var floatingView: MaskedView = {
let view = MaskedView();

view.backgroundColor = UIColor(
hue: 0/360,
Expand Down

0 comments on commit 3a97f74

Please sign in to comment.