Improve tab switching

This commit is contained in:
Ali 2020-03-01 01:44:25 +04:00
parent 97401abba6
commit 974c2d8e17
3 changed files with 59 additions and 18 deletions

View File

@ -267,13 +267,13 @@ final class ChatListContainerNode: ASDisplayNode, UIGestureRecognizerDelegate {
guard let strongSelf = self, let index = strongSelf.availableFilters.index(where: { $0.id == strongSelf.selectedId }) else {
return []
}
var directions: InteractiveTransitionGestureRecognizerDirections = [.left, .right]
var directions: InteractiveTransitionGestureRecognizerDirections = [.leftCenter, .rightCenter]
if strongSelf.availableFilters.count > 1 {
if index == 0 {
directions.remove(.right)
directions.remove(.rightCenter)
}
if index == strongSelf.availableFilters.count - 1 {
directions.remove(.left)
directions.remove(.leftCenter)
}
} else {
directions = []
@ -358,7 +358,7 @@ final class ChatListContainerNode: ASDisplayNode, UIGestureRecognizerDelegate {
self.disableItemNodeOperationsWhileAnimating = true
self.update(layout: layout, navigationBarHeight: navigationBarHeight, visualNavigationHeight: visualNavigationHeight, cleanNavigationBarHeight: cleanNavigationBarHeight, transition: transition)
self.currentItemFilterUpdated?(self.currentItemFilter, self.transitionFraction, transition)
transition.updateBounds(node: self, bounds: self.bounds, force: true, completion: { [weak self] _ in
/*transition.updateBounds(node: self, bounds: self.bounds, force: true, completion: { [weak self] _ in
guard let strongSelf = self else {
return
}
@ -366,7 +366,13 @@ final class ChatListContainerNode: ASDisplayNode, UIGestureRecognizerDelegate {
if let (layout, navigationBarHeight, visualNavigationHeight, cleanNavigationBarHeight) = strongSelf.validLayout {
strongSelf.update(layout: layout, navigationBarHeight: navigationBarHeight, visualNavigationHeight: visualNavigationHeight, cleanNavigationBarHeight: cleanNavigationBarHeight, transition: .immediate)
}
})
})*/
DispatchQueue.main.async {
self.disableItemNodeOperationsWhileAnimating = false
if let (layout, navigationBarHeight, visualNavigationHeight, cleanNavigationBarHeight) = self.validLayout {
self.update(layout: layout, navigationBarHeight: navigationBarHeight, visualNavigationHeight: visualNavigationHeight, cleanNavigationBarHeight: cleanNavigationBarHeight, transition: .immediate)
}
}
}
default:
break

View File

@ -1,16 +1,23 @@
import Foundation
import UIKit
private func hasHorizontalGestures(_ view: UIView, point: CGPoint?) -> Bool {
if view.disablesInteractiveTransitionGestureRecognizer {
return true
}
private enum HorizontalGestures {
case none
case some
case strict
}
private func hasHorizontalGestures(_ view: UIView, point: CGPoint?) -> HorizontalGestures {
if let disablesInteractiveTransitionGestureRecognizerNow = view.disablesInteractiveTransitionGestureRecognizerNow, disablesInteractiveTransitionGestureRecognizerNow() {
return true
return .strict
}
if view.disablesInteractiveTransitionGestureRecognizer {
return .some
}
if let point = point, let test = view.interactiveTransitionGestureRecognizerTest, test(point) {
return true
return .some
}
if let view = view as? ListViewBackingView {
@ -20,14 +27,14 @@ private func hasHorizontalGestures(_ view: UIView, point: CGPoint?) -> Bool {
let term2: Double = abs(angle + Double.pi / 2.0)
let term3: Double = abs(angle - Double.pi * 3.0 / 2.0)
if term1 < 0.001 || term2 < 0.001 || term3 < 0.001 {
return true
return .some
}
}
if let superview = view.superview {
return hasHorizontalGestures(superview, point: point != nil ? view.convert(point!, to: superview) : nil)
} else {
return false
return .none
}
}
@ -84,9 +91,17 @@ public class InteractiveTransitionGestureRecognizer: UIPanGestureRecognizer {
self.firstLocation = point
if let target = self.view?.hitTest(self.firstLocation, with: event) {
if hasHorizontalGestures(target, point: self.view?.convert(self.firstLocation, to: target)) {
allowedDirections.remove(.leftCenter)
allowedDirections.remove(.rightCenter)
let horizontalGestures = hasHorizontalGestures(target, point: self.view?.convert(self.firstLocation, to: target))
switch horizontalGestures {
case .some, .strict:
if case .strict = horizontalGestures {
allowedDirections = []
} else if allowedDirections.contains(.leftEdge) || allowedDirections.contains(.rightEdge) {
allowedDirections.remove(.leftCenter)
allowedDirections.remove(.rightCenter)
}
case .none:
break
}
}
@ -105,11 +120,21 @@ public class InteractiveTransitionGestureRecognizer: UIPanGestureRecognizer {
let absTranslationY: CGFloat = abs(translation.y)
let size = self.view?.bounds.size ?? CGSize()
let edgeWidth: CGFloat = 20.0
if !self.validatedGesture {
if self.currentAllowedDirections.contains(.rightEdge) && self.firstLocation.x < 16.0 {
if self.firstLocation.x < edgeWidth && !self.currentAllowedDirections.contains(.rightEdge) {
self.state = .failed
return
}
if self.firstLocation.x > size.width - edgeWidth && !self.currentAllowedDirections.contains(.leftEdge) {
self.state = .failed
return
}
if self.currentAllowedDirections.contains(.rightEdge) && self.firstLocation.x < edgeWidth {
self.validatedGesture = true
} else if self.currentAllowedDirections.contains(.leftEdge) && self.firstLocation.x > size.width - 16.0 {
} else if self.currentAllowedDirections.contains(.leftEdge) && self.firstLocation.x > size.width - edgeWidth {
self.validatedGesture = true
} else if !self.currentAllowedDirections.contains(.leftCenter) && translation.x < 0.0 {
self.state = .failed

View File

@ -101,6 +101,16 @@ open class ItemListRevealOptionsItemNode: ListViewItemNode, UIGestureRecognizerD
self.view.addGestureRecognizer(tapRecognizer)
self.view.disablesInteractiveTransitionGestureRecognizer = self.allowAnyDirection
self.view.disablesInteractiveTransitionGestureRecognizerNow = { [weak self] in
guard let strongSelf = self else {
return false
}
if !strongSelf.revealOffset.isZero {
return true
}
return false
}
}
open func setRevealOptions(_ options: (left: [ItemListRevealOption], right: [ItemListRevealOption])) {