Skip to content

Commit

Permalink
⭐️ Impl: `ModalSheetViewControllerEventsNotifiable.notifyOnSheetBeing…
Browse files Browse the repository at this point in the history
…DraggedByPanGesture`
  • Loading branch information
dominicstop committed Sep 29, 2024
1 parent 8db6026 commit 1161634
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ios/Temp/ModalSheetViewControllerEventsNotifiable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public protocol ModalSheetViewControllerEventsNotifiable: AnyObject {
panGesture: UIPanGestureRecognizer,
scrollView: UIScrollView
);

func notifyOnSheetBeingDraggedByPanGesture(
sender: UIViewController,
panGesture: UIPanGestureRecognizer
);
};

// MARK: - SheetViewControllerEventsNotifiable
Expand Down Expand Up @@ -79,4 +84,11 @@ public extension ModalSheetViewControllerEventsNotifiable {
) {
// no-op
};

func notifyOnSheetBeingDraggedByPanGesture(
sender: UIViewController,
panGesture: UIPanGestureRecognizer
) {
// no-op
};
};
43 changes: 43 additions & 0 deletions ios/Temp/ModalSheetViewControllerLifecycleNotifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,22 @@ open class ModalSheetViewControllerLifecycleNotifier: ViewControllerLifecycleNot
gesturePoint: gesturePoint
);
};

let shouldInvokeCombinedGestureHandler: Bool = {
if let scrollViewPanGesture = self.modalRootScrollViewGestureRecognizer {
let isScrollGestureActive = scrollViewPanGesture.state.isActive;
let didSystemPanGestureFail = panGesture.state == .failed;

return !isScrollGestureActive || !didSystemPanGestureFail;
};

return true;
}();

if shouldInvokeCombinedGestureHandler {
self._handleCombinedSheetGesture(panGesture);
};
};

@objc
private func _handleSheetScrollViewGesture(
Expand Down Expand Up @@ -211,7 +227,34 @@ open class ModalSheetViewControllerLifecycleNotifier: ViewControllerLifecycleNot
scrollView: scrollView
);
};

let shouldInvokeCombinedGestureHandler = {
if let sheetGesture = self.sheetGesture {
return sheetGesture.state == .failed;
};

let currentOffsetY = scrollView.contentOffset.y;
let initialOffsetY = self.sheetRootScrollViewInitialContentOffset.y;

return currentOffsetY <= initialOffsetY;
}();

if shouldInvokeCombinedGestureHandler {
self._handleCombinedSheetGesture(panGesture);
};
};

@objc
private func _handleCombinedSheetGesture(
_ panGesture: UIPanGestureRecognizer
) {

self.sheetLifecycleEventDelegates.invoke {
$0.notifyOnSheetBeingDraggedByPanGesture(
sender: self,
panGesture: panGesture
);
};
};

// MARK: - Debug-Related
Expand Down

0 comments on commit 1161634

Please sign in to comment.