Adjust gestures

This commit is contained in:
Ali 2023-07-17 00:29:03 +04:00
parent 2747901065
commit d5c3e43d7a
4 changed files with 86 additions and 45 deletions

View File

@ -948,7 +948,7 @@ public final class ChatListContainerNode: ASDisplayNode, UIGestureRecognizerDele
let offset = itemNode.listNode.visibleContentOffset()
self.contentOffset = offset
self.contentOffsetChanged?(offset)
self.contentOffsetChanged?(offset, self.currentItemNode)
self.isSettingUpContentOffset = false
return
@ -966,7 +966,7 @@ public final class ChatListContainerNode: ASDisplayNode, UIGestureRecognizerDele
}
self.contentOffset = offset
self.contentOffsetChanged?(offset)
self.contentOffsetChanged?(offset, self.currentItemNode)
if !self.isInlineMode, self.currentItemNode.startedScrollingAtUpperBound && self.tempTopInset != 0.0 {
if case let .known(value) = offset {
@ -1108,7 +1108,7 @@ public final class ChatListContainerNode: ASDisplayNode, UIGestureRecognizerDele
var groupSelected: ((EngineChatList.Group) -> Void)?
var updatePeerGrouping: ((EnginePeer.Id, Bool) -> Void)?
var contentOffset: ListViewVisibleContentOffset?
public var contentOffsetChanged: ((ListViewVisibleContentOffset) -> Void)?
public var contentOffsetChanged: ((ListViewVisibleContentOffset, ListView) -> Void)?
public var contentScrollingEnded: ((ListView) -> Bool)?
var didBeginInteractiveDragging: (() -> Void)?
var endedInteractiveDragging: ((ListView) -> Void)?
@ -1756,6 +1756,8 @@ final class ChatListControllerNode: ASDisplayNode, UIGestureRecognizerDelegate {
private var tempNavigationScrollingTransition: ContainedViewLayoutTransition?
private var allowOverscrollStoryExpansion: Bool = false
private var allowOverscrollItemExpansion: Bool = false
private var currentOverscrollItemExpansionTimestamp: Double?
private var containerLayout: (layout: ContainerViewLayout, navigationBarHeight: CGFloat, visualNavigationHeight: CGFloat, cleanNavigationBarHeight: CGFloat, storiesInset: CGFloat)?
@ -1807,8 +1809,8 @@ final class ChatListControllerNode: ASDisplayNode, UIGestureRecognizerDelegate {
self.addSubnode(self.mainContainerNode)
self.mainContainerNode.contentOffsetChanged = { [weak self] offset in
self?.contentOffsetChanged(offset: offset, isPrimary: true)
self.mainContainerNode.contentOffsetChanged = { [weak self] offset, listView in
self?.contentOffsetChanged(offset: offset, listView: listView, isPrimary: true)
}
self.mainContainerNode.contentScrollingEnded = { [weak self] listView in
return self?.contentScrollingEnded(listView: listView, isPrimary: true) ?? false
@ -2141,15 +2143,6 @@ final class ChatListControllerNode: ASDisplayNode, UIGestureRecognizerDelegate {
mainDelta = 0.0
}
transition.updateSublayerTransformOffset(layer: self.mainContainerNode.layer, offset: CGPoint(x: 0.0, y: -mainDelta))
if self.inlineStackContainerNode == nil && self.allowOverscrollStoryExpansion {
if let controller = self.controller, let componentView = controller.chatListHeaderView(), let storyPeerListView = componentView.storyPeerListView(), let peerId = storyPeerListView.overscrollSelectedId {
self.allowOverscrollStoryExpansion = false
HapticFeedback().tap()
controller.openStories(peerId: peerId)
}
}
}
func requestNavigationBarLayout(transition: Transition) {
@ -2408,11 +2401,44 @@ final class ChatListControllerNode: ASDisplayNode, UIGestureRecognizerDelegate {
}
}
private func contentOffsetChanged(offset: ListViewVisibleContentOffset, isPrimary: Bool) {
private func contentOffsetChanged(offset: ListViewVisibleContentOffset, listView: ListView, isPrimary: Bool) {
guard let containerLayout = self.containerLayout else {
return
}
self.updateNavigationScrolling(navigationHeight: containerLayout.navigationBarHeight, transition: self.tempNavigationScrollingTransition ?? .immediate)
if listView.isDragging {
if let controller = self.controller, let componentView = controller.chatListHeaderView(), let storyPeerListView = componentView.storyPeerListView() {
if let peerId = storyPeerListView.overscrollSelectedId {
if self.allowOverscrollStoryExpansion && self.inlineStackContainerNode == nil && isPrimary {
self.allowOverscrollStoryExpansion = false
self.allowOverscrollItemExpansion = false
self.currentOverscrollItemExpansionTimestamp = nil
HapticFeedback().tap()
controller.openStories(peerId: peerId)
}
} else if storyPeerListView.overscrollHiddenChatItemsAllowed {
if self.allowOverscrollItemExpansion {
let timestamp = CACurrentMediaTime()
if let _ = self.currentOverscrollItemExpansionTimestamp {
} else {
self.currentOverscrollItemExpansionTimestamp = timestamp
}
if let currentOverscrollItemExpansionTimestamp = self.currentOverscrollItemExpansionTimestamp, currentOverscrollItemExpansionTimestamp <= timestamp - 0.1 {
self.allowOverscrollItemExpansion = false
if isPrimary {
self.mainContainerNode.currentItemNode.revealScrollHiddenItem()
} else {
self.inlineStackContainerNode?.currentItemNode.revealScrollHiddenItem()
}
}
}
}
}
}
}
private func shouldStopScrolling(listView: ListView, velocity: CGFloat, isPrimary: Bool) -> Bool {
@ -2444,12 +2470,15 @@ final class ChatListControllerNode: ASDisplayNode, UIGestureRecognizerDelegate {
private func didBeginInteractiveDragging(isPrimary: Bool) {
if isPrimary {
self.allowOverscrollStoryExpansion = true
self.allowOverscrollItemExpansion = true
}
}
private func endedInteractiveDragging(listView: ListView, isPrimary: Bool) {
if isPrimary {
self.allowOverscrollStoryExpansion = false
self.allowOverscrollItemExpansion = false
self.currentOverscrollItemExpansionTimestamp = nil
}
}
@ -2518,8 +2547,8 @@ final class ChatListControllerNode: ASDisplayNode, UIGestureRecognizerDelegate {
inlineStackContainerNode.groupSelected = self.mainContainerNode.groupSelected
inlineStackContainerNode.updatePeerGrouping = self.mainContainerNode.updatePeerGrouping
inlineStackContainerNode.contentOffsetChanged = { [weak self] offset in
self?.contentOffsetChanged(offset: offset, isPrimary: false)
inlineStackContainerNode.contentOffsetChanged = { [weak self] offset, listView in
self?.contentOffsetChanged(offset: offset, listView: listView, isPrimary: false)
}
inlineStackContainerNode.endedInteractiveDragging = { [weak self] listView in
self?.didBeginInteractiveDragging(isPrimary: false)

View File

@ -2858,32 +2858,7 @@ public final class ChatListNode: ListView {
strongSelf.scrolledAtTopValue = atTop
strongSelf.contentOffsetChanged?(offset)
if revealHiddenItems && !strongSelf.currentState.hiddenItemShouldBeTemporaryRevealed {
var isHiddenItemVisible = false
strongSelf.forEachItemNode({ itemNode in
if let itemNode = itemNode as? ChatListItemNode, let item = itemNode.item {
if case let .peer(peerData) = item.content, let threadInfo = peerData.threadInfo {
if threadInfo.isHidden {
isHiddenItemVisible = true
}
}
if case let .groupReference(groupReference) = item.content {
if groupReference.hiddenByDefault {
isHiddenItemVisible = true
}
}
}
})
if isHiddenItemVisible {
if strongSelf.hapticFeedback == nil {
strongSelf.hapticFeedback = HapticFeedback()
}
strongSelf.hapticFeedback?.impact(.medium)
strongSelf.updateState { state in
var state = state
state.hiddenItemShouldBeTemporaryRevealed = true
return state
}
}
//strongSelf.revealScrollHiddenItem()
}
}
@ -2915,6 +2890,35 @@ public final class ChatListNode: ListView {
}
}
func revealScrollHiddenItem() {
var isHiddenItemVisible = false
self.forEachItemNode({ itemNode in
if let itemNode = itemNode as? ChatListItemNode, let item = itemNode.item {
if case let .peer(peerData) = item.content, let threadInfo = peerData.threadInfo {
if threadInfo.isHidden {
isHiddenItemVisible = true
}
}
if case let .groupReference(groupReference) = item.content {
if groupReference.hiddenByDefault {
isHiddenItemVisible = true
}
}
}
})
if isHiddenItemVisible {
if self.hapticFeedback == nil {
self.hapticFeedback = HapticFeedback()
}
self.hapticFeedback?.impact(.medium)
self.updateState { state in
var state = state
state.hiddenItemShouldBeTemporaryRevealed = true
return state
}
}
}
private func pollFilterUpdates() {
self.chatFolderUpdates.set(.single(nil))

View File

@ -354,6 +354,7 @@ public final class StoryPeerListComponent: Component {
private var currentActivityFraction: CGFloat = 0.0
public private(set) var overscrollSelectedId: EnginePeer.Id?
public private(set) var overscrollHiddenChatItemsAllowed: Bool = false
private var sharedBlurEffect: NSObject?
@ -712,7 +713,7 @@ public final class StoryPeerListComponent: Component {
var rawProgress = CGFloat((timestamp - animationState.startTime) / animationState.duration)
rawProgress = max(0.0, min(1.0, rawProgress))
if !animationState.fromIsUnlocked && animationState.bounce && itemLayout.itemCount > 3 {
if !animationState.fromIsUnlocked && animationState.bounce {
let bounceStartFraction: CGFloat = 0.0
let bounceGlobalFraction: CGFloat = animationState.interpolatedFraction(at: timestamp, effectiveFromFraction: 0.0, toFraction: 1.0, linear: true)
let bounceFraction: CGFloat = 1.0 - max(0.0, min(1.0, bounceGlobalFraction - bounceStartFraction)) / (1.0 - bounceStartFraction)
@ -801,6 +802,13 @@ public final class StoryPeerListComponent: Component {
break
}
}
if overscrollStage1 >= 0.6 {
self.overscrollHiddenChatItemsAllowed = true
} else {
self.overscrollHiddenChatItemsAllowed = false
}
if let overscrollFocusIndex, overscrollStage2 >= 0.6 {
self.overscrollSelectedId = self.sortedItems[overscrollFocusIndex].peer.id
} else {

View File

@ -262,7 +262,7 @@ final class PeerSelectionControllerNode: ASDisplayNode {
}
}
self.mainContainerNode?.contentOffsetChanged = { [weak self] offset in
self.mainContainerNode?.contentOffsetChanged = { [weak self] offset, _ in
guard let strongSelf = self else {
return
}