Skip to content

Commit

Permalink
💫 Update: Exp - swift-programmatic-modal
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicstop committed May 25, 2023
1 parent 12a1cda commit f160743
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ class AdaptiveModalManager {

var currentSnapPointIndex = 1;

/// Defines which axis of the gesture point to use to drive the interpolation
/// of the modal snap points
///
var inputAxisKey: KeyPath<CGPoint, CGFloat> = \.y;

// MARK: - Computed Properties
// ---------------------------

Expand Down Expand Up @@ -205,29 +210,32 @@ class AdaptiveModalManager {
};

func interpolateModalRect(
forGesturePointInTargetRect gesturePointInTargetRect: CGPoint,
gesturePointRelativeToModal: CGPoint
forGesturePoint gesturePoint: CGPoint
) -> CGRect {

guard let modalView = self.modalView else { return .zero };

let targetRect = self.targetRectProvider();
let modalRect = modalView.frame;

let gestureCoord = gesturePoint[keyPath: self.inputAxisKey];
let snapRects = self.computedSnapRects.reversed();

let gestureOffset = self.gestureOffset ??
gesturePointInTargetRect.y - modalRect.origin.y;
let gestureOffset = self.gestureOffset ?? {
let modalCoord = modalRect.origin[keyPath: self.inputAxisKey];
return gestureCoord - modalCoord;
}();


if self.gestureOffset == nil {
self.gestureOffset = gestureOffset;
};

let gestureInput = gesturePointInTargetRect.y - gestureOffset;
let gestureInput = gestureCoord - gestureOffset;
let rangeInputGesture = snapRects.map { $0.minY };

print(
"gesturePoint: \(gesturePointInTargetRect)"
+ "\n" + " - gesturePointRelativeToModal: \(gesturePointRelativeToModal)"
"gesturePoint: \(gesturePoint)"
+ "\n" + " - targetRect: \(targetRect)"
+ "\n" + " - gestureInput: \(gestureInput)"
+ "\n" + " - offset: \(gestureOffset)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ class RNIDraggableTestViewController : UIViewController {

case .changed:
let computedRect = self.modalManager.interpolateModalRect(
forGesturePointInTargetRect: gesturePoint,
gesturePointRelativeToModal: relativeGesturePoint
forGesturePoint: gesturePoint
);

floatingView.frame = computedRect;
Expand Down

0 comments on commit f160743

Please sign in to comment.