-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Update experiment/test - `swift-programmatic-modal/AdaptiveModal`.
- Loading branch information
1 parent
36f9647
commit 5ff377d
Showing
5 changed files
with
314 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
experiments/swift-programmatic-modal/AdaptiveModal/AdaptiveModalInterpolationPoint.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// | ||
// AdaptiveModalInterpolationPoint.swift | ||
// swift-programmatic-modal | ||
// | ||
// Created by Dominic Go on 5/29/23. | ||
// | ||
|
||
import UIKit | ||
|
||
struct AdaptiveModalInterpolationPoint { | ||
|
||
/// The computed frames of the modal based on the snap points | ||
let computedRect: CGRect; | ||
|
||
let modalRadiusTopLeft: CGFloat; | ||
let modalRadiusTopRight: CGFloat; | ||
let modalRadiusBottomLeft: CGFloat; | ||
let modalRadiusBottomRight: CGFloat; | ||
|
||
var modalRadiusMask: CAShapeLayer { | ||
let radiusPath = UIBezierPath( | ||
shouldRoundRect: CGRect( | ||
origin: .zero, | ||
size: self.computedRect.size | ||
), | ||
topLeftRadius: self.modalRadiusTopLeft, | ||
topRightRadius: self.modalRadiusTopRight, | ||
bottomLeftRadius: self.modalRadiusBottomLeft, | ||
bottomRightRadius: self.modalRadiusBottomRight | ||
); | ||
|
||
let shape = CAShapeLayer(); | ||
shape.path = radiusPath.cgPath; | ||
|
||
return shape; | ||
}; | ||
|
||
init( | ||
withTargetRect targetRect: CGRect, | ||
currentSize: CGSize, | ||
snapPointConfig: AdaptiveModalSnapPointConfig, | ||
modalRadiusTopLeft: CGFloat, | ||
modalRadiusTopRight: CGFloat, | ||
modalRadiusBottomLeft: CGFloat, | ||
modalRadiusBottomRight: CGFloat | ||
) { | ||
self.computedRect = snapPointConfig.snapPoint.computeRect( | ||
withTargetRect: targetRect, | ||
currentSize: currentSize | ||
); | ||
|
||
self.modalRadiusTopLeft = modalRadiusTopLeft; | ||
self.modalRadiusTopRight = modalRadiusTopRight; | ||
self.modalRadiusBottomLeft = modalRadiusBottomLeft; | ||
self.modalRadiusBottomRight = modalRadiusBottomRight; | ||
}; | ||
}; | ||
|
||
extension AdaptiveModalInterpolationPoint { | ||
|
||
static func compute( | ||
usingModalConfig modalConfig: AdaptiveModalConfig, | ||
withTargetRect targetRect: CGRect, | ||
currentSize: CGSize | ||
) -> [AdaptiveModalInterpolationPoint] { | ||
|
||
var items: [AdaptiveModalInterpolationPoint] = []; | ||
|
||
let defaultCornerRadius: CGFloat = 0; | ||
|
||
for snapConfig in modalConfig.snapPoints { | ||
let keyframe = snapConfig.animationKeyframe; | ||
let prevKeyframe = items.last; | ||
|
||
items.append( | ||
AdaptiveModalInterpolationPoint( | ||
withTargetRect : targetRect, | ||
currentSize : currentSize, | ||
snapPointConfig: snapConfig, | ||
|
||
modalRadiusTopLeft: keyframe?.modalRadiusTopLeft | ||
?? prevKeyframe?.modalRadiusTopLeft ?? defaultCornerRadius, | ||
|
||
modalRadiusTopRight: keyframe?.modalRadiusTopRight | ||
?? prevKeyframe?.modalRadiusTopRight ?? defaultCornerRadius, | ||
|
||
modalRadiusBottomLeft: keyframe?.modalRadiusBottomLeft | ||
?? prevKeyframe?.modalRadiusBottomLeft ?? defaultCornerRadius, | ||
|
||
modalRadiusBottomRight: keyframe?.modalRadiusBottomRight | ||
?? prevKeyframe?.modalRadiusBottomRight ?? defaultCornerRadius | ||
) | ||
); | ||
}; | ||
|
||
return items; | ||
}; | ||
|
||
}; |
Oops, something went wrong.