mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
Ongoing work on the updated entity input
This commit is contained in:
@@ -7,21 +7,18 @@ import PagerComponent
|
||||
private func traceScrollView(view: UIView, point: CGPoint) -> (UIScrollView?, Bool) {
|
||||
for subview in view.subviews.reversed() {
|
||||
let subviewPoint = view.convert(point, to: subview)
|
||||
if subview.frame.contains(point) {
|
||||
if subview.frame.contains(point) || subview is PagerExternalTopPanelContainer {
|
||||
let (result, shouldContinue) = traceScrollView(view: subview, point: subviewPoint)
|
||||
if let result = result {
|
||||
return (result, false)
|
||||
} else if subview.backgroundColor != nil {
|
||||
return (nil, false)
|
||||
} else if !shouldContinue{
|
||||
} else if !shouldContinue {
|
||||
return (nil, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
if let scrollView = view as? UIScrollView {
|
||||
if scrollView is ListViewScroller || scrollView is GridNodeScrollerView {
|
||||
return (nil, false)
|
||||
}
|
||||
return (scrollView, false)
|
||||
}
|
||||
return (nil, true)
|
||||
@@ -31,6 +28,7 @@ private final class ExpansionPanRecognizer: UIGestureRecognizer, UIGestureRecogn
|
||||
enum LockDirection {
|
||||
case up
|
||||
case down
|
||||
case any
|
||||
}
|
||||
|
||||
var requiredLockDirection: LockDirection = .up
|
||||
@@ -83,14 +81,23 @@ private final class ExpansionPanRecognizer: UIGestureRecognizer, UIGestureRecogn
|
||||
|
||||
var found = false
|
||||
let point = touch.location(in: self.view)
|
||||
if let _ = view.hitTest(point, with: event) as? UIButton {
|
||||
} else if let scrollView = traceScrollView(view: view, point: point).0 {
|
||||
let contentOffset = scrollView.contentOffset
|
||||
let contentInset = scrollView.contentInset
|
||||
if contentOffset.y.isLessThanOrEqualTo(contentInset.top) {
|
||||
|
||||
let hitView = view.hitTest(point, with: event)
|
||||
|
||||
if let _ = hitView as? UIButton {
|
||||
} else if let hitView = hitView, hitView.asyncdisplaykit_node is ASButtonNode {
|
||||
} else {
|
||||
if let scrollView = traceScrollView(view: view, point: point).0 {
|
||||
if scrollView is ListViewScroller || scrollView is GridNodeScrollerView {
|
||||
found = false
|
||||
} else {
|
||||
found = true
|
||||
}
|
||||
} else {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
|
||||
if found {
|
||||
self.beginPosition = point
|
||||
} else {
|
||||
@@ -118,28 +125,46 @@ private final class ExpansionPanRecognizer: UIGestureRecognizer, UIGestureRecogn
|
||||
}
|
||||
var lockDirection: LockDirection?
|
||||
let point = touch.location(in: self.view)
|
||||
let tracedView = view.hitTest(point, with: event)
|
||||
if let scrollView = traceScrollView(view: view, point: point).0 {
|
||||
let contentOffset = scrollView.contentOffset
|
||||
let contentInset = scrollView.contentInset
|
||||
if contentOffset.y <= contentInset.top {
|
||||
lockDirection = self.requiredLockDirection
|
||||
if !(scrollView is PagerExpandableScrollView) {
|
||||
lockDirection = .any
|
||||
} else {
|
||||
let contentOffset = scrollView.contentOffset
|
||||
let contentInset = scrollView.contentInset
|
||||
if contentOffset.y <= contentInset.top {
|
||||
lockDirection = .down
|
||||
}
|
||||
}
|
||||
} else {
|
||||
lockDirection = .any
|
||||
}
|
||||
if let lockDirection = lockDirection {
|
||||
if abs(translation.y) > 2.0 {
|
||||
switch lockDirection {
|
||||
case .up:
|
||||
if translation.y < 0.0 {
|
||||
if let tracedView = tracedView {
|
||||
cancelParentGestures(view: tracedView, ignore: [self])
|
||||
}
|
||||
self.state = .began
|
||||
} else {
|
||||
self.state = .failed
|
||||
}
|
||||
case .down:
|
||||
if translation.y > 0.0 {
|
||||
if let tracedView = tracedView {
|
||||
cancelParentGestures(view: tracedView, ignore: [self])
|
||||
}
|
||||
self.state = .began
|
||||
} else {
|
||||
self.state = .failed
|
||||
}
|
||||
case .any:
|
||||
if let tracedView = tracedView {
|
||||
cancelParentGestures(view: tracedView, ignore: [self])
|
||||
}
|
||||
self.state = .began
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -179,6 +204,7 @@ public final class ChatInputPanelContainer: SparseNode, UIScrollViewDelegate {
|
||||
private var scrollableDistance: CGFloat?
|
||||
public private(set) var initialExpansionFraction: CGFloat = 0.0
|
||||
public private(set) var expansionFraction: CGFloat = 0.0
|
||||
public private(set) var stableIsExpanded: Bool = false
|
||||
|
||||
override public init() {
|
||||
super.init()
|
||||
@@ -231,6 +257,8 @@ public final class ChatInputPanelContainer: SparseNode, UIScrollViewDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
self.stableIsExpanded = self.expansionFraction == 1.0
|
||||
|
||||
if let expansionRecognizer = self.expansionRecognizer {
|
||||
expansionRecognizer.requiredLockDirection = self.expansionFraction == 0.0 ? .up : .down
|
||||
}
|
||||
@@ -250,10 +278,24 @@ public final class ChatInputPanelContainer: SparseNode, UIScrollViewDelegate {
|
||||
public func expand() {
|
||||
self.expansionFraction = 1.0
|
||||
self.expansionRecognizer?.requiredLockDirection = self.expansionFraction == 0.0 ? .up : .down
|
||||
self.stableIsExpanded = self.expansionFraction == 1.0
|
||||
}
|
||||
|
||||
public func collapse() {
|
||||
self.expansionFraction = 0.0
|
||||
self.expansionRecognizer?.requiredLockDirection = self.expansionFraction == 0.0 ? .up : .down
|
||||
self.stableIsExpanded = self.expansionFraction == 1.0
|
||||
}
|
||||
|
||||
public func toggleIfEnabled() {
|
||||
if let expansionRecognizer = self.expansionRecognizer, expansionRecognizer.isEnabled {
|
||||
if self.expansionFraction == 0.0 {
|
||||
self.expansionFraction = 1.0
|
||||
} else {
|
||||
self.expansionFraction = 0.0
|
||||
}
|
||||
self.stableIsExpanded = self.expansionFraction == 1.0
|
||||
self.expansionUpdated?(.animated(duration: 0.4, curve: .spring))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user