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 6, 2023
1 parent e1f6db4 commit 3a56f33
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ class RoundedView: UIView {
origin: .zero,
size: frame.size
);

self.layer.mask = self.makeShapeMask(bounds: bounds);
}

required init?(coder: NSCoder) {
Expand All @@ -25,8 +23,6 @@ class RoundedView: UIView {

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

self.layer.mask = self.makeShapeMask(bounds: self.bounds);
};

func makeShapeMask(bounds: CGRect) -> CAShapeLayer {
Expand Down Expand Up @@ -125,20 +121,74 @@ class RoundedViewTestViewController: UIViewController {
relativeDuration: 0
) {
roundedView.frame = prevFrame;
roundedView.setNeedsLayout();
roundedView.layoutIfNeeded();
//roundedView.layer.frame = prevFrame;
//roundedView.layer.mask = prevMask;
};

UIView.addKeyframe(
withRelativeStartTime: 1,
relativeDuration: 0
) {
roundedView.frame = nextFrame;
roundedView.setNeedsLayout();
roundedView.layoutIfNeeded();
//roundedView.layer.frame = nextFrame;
//roundedView.layer.mask = nextMask;
};
};


// define your new path to animate the mask layer to
//let path = UIBezierPath(roundedRect: CGRectInset(view.bounds, 100, 100), cornerRadius: 20.0)
//path.appendPath(UIBezierPath(rect: view.bounds))

// create new animation
let pathAnimator = CABasicAnimation(keyPath: "path");

let shapeMask = CAShapeLayer();

let prevPath = UIBezierPath(
shouldRoundRect: prevBounds,
topLeftRadius: 10,
topRightRadius: 10,
bottomLeftRadius: 10,
bottomRightRadius: 10
);

// from value is the current mask path
pathAnimator.fromValue = prevPath.cgPath;

let nextPath = UIBezierPath(
shouldRoundRect: nextBounds,
topLeftRadius: 25,
topRightRadius: 25,
bottomLeftRadius: 25,
bottomRightRadius: 25
);

// to value is the new path
pathAnimator.toValue = nextPath.cgPath;

// duration of your animation
pathAnimator.duration = viewAnimator.duration;

// custom timing function to make it look smooth
pathAnimator.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut);

pathAnimator.isRemovedOnCompletion = false;
pathAnimator.fillMode = .both;

// add animation
shapeMask.add(pathAnimator, forKey: nil);

// update the path property on the mask layer, using a CATransaction to prevent an implicit animation
CATransaction.begin();

roundedView.layer.mask = shapeMask;
CATransaction.commit();





viewAnimator.startAnimation();
};
};
Expand Down
2 changes: 1 addition & 1 deletion experiments/swift-programmatic-modal/Test/TestRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import UIKit

enum TestRoutes {
static let rootRouteKey: Self = .RNIDraggableTest;
static let rootRouteKey: Self = .RoundedViewTest;

case RNILayoutTest;
case RNIDraggableTest;
Expand Down

0 comments on commit 3a56f33

Please sign in to comment.