mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Improve tab switching
This commit is contained in:
parent
97401abba6
commit
974c2d8e17
@ -267,13 +267,13 @@ final class ChatListContainerNode: ASDisplayNode, UIGestureRecognizerDelegate {
|
|||||||
guard let strongSelf = self, let index = strongSelf.availableFilters.index(where: { $0.id == strongSelf.selectedId }) else {
|
guard let strongSelf = self, let index = strongSelf.availableFilters.index(where: { $0.id == strongSelf.selectedId }) else {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
var directions: InteractiveTransitionGestureRecognizerDirections = [.left, .right]
|
var directions: InteractiveTransitionGestureRecognizerDirections = [.leftCenter, .rightCenter]
|
||||||
if strongSelf.availableFilters.count > 1 {
|
if strongSelf.availableFilters.count > 1 {
|
||||||
if index == 0 {
|
if index == 0 {
|
||||||
directions.remove(.right)
|
directions.remove(.rightCenter)
|
||||||
}
|
}
|
||||||
if index == strongSelf.availableFilters.count - 1 {
|
if index == strongSelf.availableFilters.count - 1 {
|
||||||
directions.remove(.left)
|
directions.remove(.leftCenter)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
directions = []
|
directions = []
|
||||||
@ -358,7 +358,7 @@ final class ChatListContainerNode: ASDisplayNode, UIGestureRecognizerDelegate {
|
|||||||
self.disableItemNodeOperationsWhileAnimating = true
|
self.disableItemNodeOperationsWhileAnimating = true
|
||||||
self.update(layout: layout, navigationBarHeight: navigationBarHeight, visualNavigationHeight: visualNavigationHeight, cleanNavigationBarHeight: cleanNavigationBarHeight, transition: transition)
|
self.update(layout: layout, navigationBarHeight: navigationBarHeight, visualNavigationHeight: visualNavigationHeight, cleanNavigationBarHeight: cleanNavigationBarHeight, transition: transition)
|
||||||
self.currentItemFilterUpdated?(self.currentItemFilter, self.transitionFraction, 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 {
|
guard let strongSelf = self else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -366,7 +366,13 @@ final class ChatListContainerNode: ASDisplayNode, UIGestureRecognizerDelegate {
|
|||||||
if let (layout, navigationBarHeight, visualNavigationHeight, cleanNavigationBarHeight) = strongSelf.validLayout {
|
if let (layout, navigationBarHeight, visualNavigationHeight, cleanNavigationBarHeight) = strongSelf.validLayout {
|
||||||
strongSelf.update(layout: layout, navigationBarHeight: navigationBarHeight, visualNavigationHeight: visualNavigationHeight, cleanNavigationBarHeight: cleanNavigationBarHeight, transition: .immediate)
|
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:
|
default:
|
||||||
break
|
break
|
||||||
|
@ -1,16 +1,23 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
private func hasHorizontalGestures(_ view: UIView, point: CGPoint?) -> Bool {
|
private enum HorizontalGestures {
|
||||||
if view.disablesInteractiveTransitionGestureRecognizer {
|
case none
|
||||||
return true
|
case some
|
||||||
|
case strict
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func hasHorizontalGestures(_ view: UIView, point: CGPoint?) -> HorizontalGestures {
|
||||||
if let disablesInteractiveTransitionGestureRecognizerNow = view.disablesInteractiveTransitionGestureRecognizerNow, disablesInteractiveTransitionGestureRecognizerNow() {
|
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) {
|
if let point = point, let test = view.interactiveTransitionGestureRecognizerTest, test(point) {
|
||||||
return true
|
return .some
|
||||||
}
|
}
|
||||||
|
|
||||||
if let view = view as? ListViewBackingView {
|
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 term2: Double = abs(angle + Double.pi / 2.0)
|
||||||
let term3: Double = abs(angle - Double.pi * 3.0 / 2.0)
|
let term3: Double = abs(angle - Double.pi * 3.0 / 2.0)
|
||||||
if term1 < 0.001 || term2 < 0.001 || term3 < 0.001 {
|
if term1 < 0.001 || term2 < 0.001 || term3 < 0.001 {
|
||||||
return true
|
return .some
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let superview = view.superview {
|
if let superview = view.superview {
|
||||||
return hasHorizontalGestures(superview, point: point != nil ? view.convert(point!, to: superview) : nil)
|
return hasHorizontalGestures(superview, point: point != nil ? view.convert(point!, to: superview) : nil)
|
||||||
} else {
|
} else {
|
||||||
return false
|
return .none
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,10 +91,18 @@ public class InteractiveTransitionGestureRecognizer: UIPanGestureRecognizer {
|
|||||||
self.firstLocation = point
|
self.firstLocation = point
|
||||||
|
|
||||||
if let target = self.view?.hitTest(self.firstLocation, with: event) {
|
if let target = self.view?.hitTest(self.firstLocation, with: event) {
|
||||||
if hasHorizontalGestures(target, point: self.view?.convert(self.firstLocation, to: target)) {
|
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(.leftCenter)
|
||||||
allowedDirections.remove(.rightCenter)
|
allowedDirections.remove(.rightCenter)
|
||||||
}
|
}
|
||||||
|
case .none:
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if allowedDirections.isEmpty {
|
if allowedDirections.isEmpty {
|
||||||
@ -105,11 +120,21 @@ public class InteractiveTransitionGestureRecognizer: UIPanGestureRecognizer {
|
|||||||
let absTranslationY: CGFloat = abs(translation.y)
|
let absTranslationY: CGFloat = abs(translation.y)
|
||||||
|
|
||||||
let size = self.view?.bounds.size ?? CGSize()
|
let size = self.view?.bounds.size ?? CGSize()
|
||||||
|
let edgeWidth: CGFloat = 20.0
|
||||||
|
|
||||||
if !self.validatedGesture {
|
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
|
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
|
self.validatedGesture = true
|
||||||
} else if !self.currentAllowedDirections.contains(.leftCenter) && translation.x < 0.0 {
|
} else if !self.currentAllowedDirections.contains(.leftCenter) && translation.x < 0.0 {
|
||||||
self.state = .failed
|
self.state = .failed
|
||||||
|
@ -101,6 +101,16 @@ open class ItemListRevealOptionsItemNode: ListViewItemNode, UIGestureRecognizerD
|
|||||||
self.view.addGestureRecognizer(tapRecognizer)
|
self.view.addGestureRecognizer(tapRecognizer)
|
||||||
|
|
||||||
self.view.disablesInteractiveTransitionGestureRecognizer = self.allowAnyDirection
|
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])) {
|
open func setRevealOptions(_ options: (left: [ItemListRevealOption], right: [ItemListRevealOption])) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user