prevent pulling down the notification tray from messing up story viewer dismissal

This commit is contained in:
harry-signal 2022-08-10 14:45:11 -07:00 committed by GitHub
parent 678f8cb332
commit 9a65f52ae8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -45,13 +45,17 @@ class StoryInteractiveTransitionCoordinator: UIPercentDrivenInteractiveTransitio
func handlePan(_ gestureRecognizer: UIPanGestureRecognizer) {
switch gestureRecognizer.state {
case .began:
interactiveEdge = interactiveEdgeForCurrentGesture()
gestureRecognizer.setTranslation(.zero, in: pageViewController.view)
pageViewController.currentContextViewController.pause(hideChrome: true)
switch interactiveEdge {
case .none:
owsFailDebug("began gesture from unexpected state")
pageViewController.currentContextViewController.play()
cancel()
return
case .leading, .top, .bottom:
pageViewController.dismiss(animated: true)
case .trailing:
@ -127,25 +131,8 @@ class StoryInteractiveTransitionCoordinator: UIPercentDrivenInteractiveTransitio
func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
guard gestureRecognizer == panGestureRecognizer else { return false }
let translation = panGestureRecognizer.translation(in: pageViewController.view)
let normalizedTranslationX = (CurrentAppContext().isRTL ? -1 : 1) * translation.x
if normalizedTranslationX > 0 {
interactiveEdge = .leading
return true
} else if normalizedTranslationX < 0, pageViewController.currentContextViewController.allowsReplies {
interactiveEdge = .trailing
return true
} else if pageViewController.previousStoryContext == nil, translation.y > 0 {
interactiveEdge = .top
return true
} else if pageViewController.nextStoryContext == nil, translation.y < 0 {
interactiveEdge = .bottom
return true
} else {
interactiveEdge = .none
return false
}
return interactiveEdgeForCurrentGesture() != .none
}
func gestureRecognizer(
@ -154,4 +141,21 @@ class StoryInteractiveTransitionCoordinator: UIPercentDrivenInteractiveTransitio
) -> Bool {
gestureRecognizer == panGestureRecognizer
}
private func interactiveEdgeForCurrentGesture() -> Edge {
let translation = panGestureRecognizer.translation(in: pageViewController.view)
let normalizedTranslationX = (CurrentAppContext().isRTL ? -1 : 1) * translation.x
if normalizedTranslationX > 0 {
return .leading
} else if normalizedTranslationX < 0, pageViewController.currentContextViewController.allowsReplies {
return .trailing
} else if pageViewController.previousStoryContext == nil, translation.y > 0 {
return .top
} else if pageViewController.nextStoryContext == nil, translation.y < 0 {
return .bottom
} else {
return .none
}
}
}