chat selecting fixes

This commit is contained in:
overtake 2019-06-26 15:58:13 +02:00
parent a0f2dc92b9
commit c27c6977a4
10 changed files with 50 additions and 26 deletions

View File

@ -490,9 +490,9 @@ open class NavigationController: UINavigationController, ContainableController,
controller.navigationBar?.previousItem = .item(viewControllers[i - 1].navigationItem) controller.navigationBar?.previousItem = .item(viewControllers[i - 1].navigationItem)
} }
if i < self._viewControllers.count - 1 { if i < self._viewControllers.count - 1 {
controller.navigationCustomData = (viewControllers[i + 1] as? ViewController)?.customData controller.updateNavigationCustomData((viewControllers[i + 1] as? ViewController)?.customData, progress: 1.0, transition: transition)
} else { } else {
controller.navigationCustomData = nil controller.updateNavigationCustomData(nil, progress: 1.0, transition: transition)
} }
} }
viewControllers[i].navigation_setNavigationController(self) viewControllers[i].navigation_setNavigationController(self)
@ -840,13 +840,27 @@ open class NavigationController: UINavigationController, ContainableController,
bottomController.displayNode.recursivelyEnsureDisplaySynchronously(true) bottomController.displayNode.recursivelyEnsureDisplaySynchronously(true)
} }
let navigationTransitionCoordinator = NavigationTransitionCoordinator(transition: .Pop, container: self.controllerView.containerView, topView: topView, topNavigationBar: (topController as? ViewController)?.navigationBar, bottomView: bottomView, bottomNavigationBar: (bottomController as? ViewController)?.navigationBar) let navigationTransitionCoordinator = NavigationTransitionCoordinator(transition: .Pop, container: self.controllerView.containerView, topView: topView, topNavigationBar: (topController as? ViewController)?.navigationBar, bottomView: bottomView, bottomNavigationBar: (bottomController as? ViewController)?.navigationBar, didUpdateProgress: { [weak self] progress in
if let strongSelf = self {
for i in 0 ..< strongSelf._viewControllers.count {
if let controller = strongSelf._viewControllers[i].controller as? ViewController {
if i < strongSelf._viewControllers.count - 1 {
controller.updateNavigationCustomData((strongSelf.viewControllers[i + 1] as? ViewController)?.customData, progress: 1.0 - progress, transition: .immediate)
} else {
controller.updateNavigationCustomData(nil, progress: 1.0 - progress, transition: .immediate)
}
}
}
}
})
self.navigationTransitionCoordinator = navigationTransitionCoordinator self.navigationTransitionCoordinator = navigationTransitionCoordinator
} }
case UIGestureRecognizerState.changed: case UIGestureRecognizerState.changed:
if let navigationTransitionCoordinator = self.navigationTransitionCoordinator, !navigationTransitionCoordinator.animatingCompletion { if let navigationTransitionCoordinator = self.navigationTransitionCoordinator, !navigationTransitionCoordinator.animatingCompletion {
let translation = recognizer.translation(in: self.view).x let translation = recognizer.translation(in: self.view).x
navigationTransitionCoordinator.progress = max(0.0, min(1.0, translation / self.view.frame.width)) let progress = max(0.0, min(1.0, translation / self.view.frame.width))
navigationTransitionCoordinator.progress = progress
} }
case UIGestureRecognizerState.ended: case UIGestureRecognizerState.ended:
if let navigationTransitionCoordinator = self.navigationTransitionCoordinator, !navigationTransitionCoordinator.animatingCompletion { if let navigationTransitionCoordinator = self.navigationTransitionCoordinator, !navigationTransitionCoordinator.animatingCompletion {

View File

@ -39,10 +39,11 @@ class NavigationTransitionCoordinator {
private(set) var animatingCompletion = false private(set) var animatingCompletion = false
private var currentCompletion: (() -> Void)? private var currentCompletion: (() -> Void)?
private var didUpdateProgress:((CGFloat)->Void)?
init(transition: NavigationTransition, container: UIView, topView: UIView, topNavigationBar: NavigationBar?, bottomView: UIView, bottomNavigationBar: NavigationBar?) { init(transition: NavigationTransition, container: UIView, topView: UIView, topNavigationBar: NavigationBar?, bottomView: UIView, bottomNavigationBar: NavigationBar?, didUpdateProgress: ((CGFloat) -> Void)? = nil) {
self.transition = transition self.transition = transition
self.container = container self.container = container
self.didUpdateProgress = didUpdateProgress
self.topView = topView self.topView = topView
switch transition { switch transition {
case .Push: case .Push:
@ -109,6 +110,8 @@ class NavigationTransitionCoordinator {
self.bottomView.frame = CGRect(origin: CGPoint(x: ((position - 1.0) * containerSize.width * 0.3), y: 0.0), size: containerSize) self.bottomView.frame = CGRect(origin: CGPoint(x: ((position - 1.0) * containerSize.width * 0.3), y: 0.0), size: containerSize)
self.updateNavigationBarTransition() self.updateNavigationBarTransition()
self.didUpdateProgress?(self.progress)
} }
func updateNavigationBarTransition() { func updateNavigationBarTransition() {

View File

@ -73,14 +73,13 @@ open class TabBarController: ViewController {
} }
} }
open override var navigationCustomData: Any? { open override func updateNavigationCustomData(_ data: Any?, progress: CGFloat, transition: ContainedViewLayoutTransition) {
didSet { for controller in controllers {
for controller in controllers { controller.updateNavigationCustomData(data, progress: progress, transition: transition)
controller.navigationCustomData = navigationCustomData
}
} }
} }
public private(set) var controllers: [ViewController] = [] public private(set) var controllers: [ViewController] = []
private let _ready = Promise<Bool>() private let _ready = Promise<Bool>()

View File

@ -206,7 +206,10 @@ open class ViewControllerPresentationArguments {
public var scrollToTopWithTabBar: (() -> Void)? public var scrollToTopWithTabBar: (() -> Void)?
public var longTapWithTabBar: (() -> Void)? public var longTapWithTabBar: (() -> Void)?
open var navigationCustomData: Any? open func updateNavigationCustomData(_ data: Any?, progress: CGFloat, transition: ContainedViewLayoutTransition) {
}
open var customData: Any? { open var customData: Any? {
get { get {
return nil return nil

View File

@ -96,12 +96,11 @@ public class ChatListController: TelegramController, UIViewControllerPreviewingD
private var searchContentNode: NavigationBarSearchContentNode? private var searchContentNode: NavigationBarSearchContentNode?
public override var navigationCustomData: Any? { public override func updateNavigationCustomData(_ data: Any?, progress: CGFloat, transition: ContainedViewLayoutTransition) {
didSet { self.chatListDisplayNode.chatListNode.updateSelectedChatLocation(data as? ChatLocation, progress: progress, transition: transition)
self.chatListDisplayNode.chatListNode.updateSelectedChatLocation(self.navigationCustomData as? ChatLocation, progress: 1, transition: .immediate)
}
} }
public init(context: AccountContext, groupId: PeerGroupId, controlsHistoryPreload: Bool, hideNetworkActivityStatus: Bool = false) { public init(context: AccountContext, groupId: PeerGroupId, controlsHistoryPreload: Bool, hideNetworkActivityStatus: Bool = false) {
self.context = context self.context = context
self.controlsHistoryPreload = controlsHistoryPreload self.controlsHistoryPreload = controlsHistoryPreload
@ -1121,11 +1120,13 @@ public class ChatListController: TelegramController, UIViewControllerPreviewingD
editItem.accessibilityLabel = self.presentationData.strings.Common_Done editItem.accessibilityLabel = self.presentationData.strings.Common_Done
if case .root = self.groupId { if case .root = self.groupId {
self.navigationItem.leftBarButtonItem = editItem self.navigationItem.leftBarButtonItem = editItem
(self.navigationController as? NavigationController)?.updateMasterDetailsBlackout(.details, transition: .animated(duration: 0.5, curve: .spring))
} else { } else {
self.navigationItem.rightBarButtonItem = editItem self.navigationItem.rightBarButtonItem = editItem
(self.navigationController as? NavigationController)?.updateMasterDetailsBlackout(.master, transition: .animated(duration: 0.5, curve: .spring))
} }
self.searchContentNode?.setIsEnabled(false, animated: true) self.searchContentNode?.setIsEnabled(false, animated: true)
(self.navigationController as? NavigationController)?.updateMasterDetailsBlackout(.details, transition: .animated(duration: 0.5, curve: .spring))
self.chatListDisplayNode.chatListNode.updateState { state in self.chatListDisplayNode.chatListNode.updateState { state in
var state = state var state = state
state.editing = true state.editing = true

View File

@ -519,6 +519,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
func updateIsHighlighted(transition: ContainedViewLayoutTransition) { func updateIsHighlighted(transition: ContainedViewLayoutTransition) {
let highlightProgress: CGFloat = self.item?.interaction.highlightedChatLocation?.progress ?? 1.0
if reallyHighlighted { if reallyHighlighted {
if self.highlightedBackgroundNode.supernode == nil { if self.highlightedBackgroundNode.supernode == nil {
@ -526,14 +527,14 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
self.highlightedBackgroundNode.alpha = 0.0 self.highlightedBackgroundNode.alpha = 0.0
} }
self.highlightedBackgroundNode.layer.removeAllAnimations() self.highlightedBackgroundNode.layer.removeAllAnimations()
transition.updateAlpha(layer: self.highlightedBackgroundNode.layer, alpha: 1.0) transition.updateAlpha(layer: self.highlightedBackgroundNode.layer, alpha: highlightProgress)
if let item = self.item { if let item = self.item {
self.onlineNode.setImage(PresentationResourcesChatList.recentStatusOnlineIcon(item.presentationData.theme, state: .highlighted)) self.onlineNode.setImage(PresentationResourcesChatList.recentStatusOnlineIcon(item.presentationData.theme, state: .highlighted))
} }
} else { } else {
if self.highlightedBackgroundNode.supernode != nil { if self.highlightedBackgroundNode.supernode != nil {
transition.updateAlpha(layer: self.highlightedBackgroundNode.layer, alpha: 0.0, completion: { [weak self] completed in transition.updateAlpha(layer: self.highlightedBackgroundNode.layer, alpha: highlightProgress, completion: { [weak self] completed in
if let strongSelf = self { if let strongSelf = self {
if completed { if completed {
strongSelf.highlightedBackgroundNode.removeFromSupernode() strongSelf.highlightedBackgroundNode.removeFromSupernode()

View File

@ -1427,7 +1427,7 @@ final class ChatListNode: ListView {
} }
if let chatLocation = chatLocation { if let chatLocation = chatLocation {
interaction.highlightedChatLocation = ChatListHighlightedLocation(location: chatLocation, progress: 1.0) interaction.highlightedChatLocation = ChatListHighlightedLocation(location: chatLocation, progress: progress)
} else { } else {
interaction.highlightedChatLocation = nil interaction.highlightedChatLocation = nil
} }

View File

@ -99,6 +99,7 @@ private enum ContactListNodeEntryId: Hashable {
final class ContactItemHighlighting { final class ContactItemHighlighting {
var chatLocation: ChatLocation? var chatLocation: ChatLocation?
var progress: CGFloat = 1.0
init(chatLocation: ChatLocation? = nil) { init(chatLocation: ChatLocation? = nil) {
self.chatLocation = chatLocation self.chatLocation = chatLocation
} }
@ -1343,6 +1344,7 @@ final class ContactListNode: ASDisplayNode {
func updateSelectedChatLocation(_ chatLocation: ChatLocation?, progress: CGFloat, transition: ContainedViewLayoutTransition) { func updateSelectedChatLocation(_ chatLocation: ChatLocation?, progress: CGFloat, transition: ContainedViewLayoutTransition) {
self.interaction?.itemHighlighting.chatLocation = chatLocation self.interaction?.itemHighlighting.chatLocation = chatLocation
self.interaction?.itemHighlighting.progress = progress
self.listNode.forEachItemNode { itemNode in self.listNode.forEachItemNode { itemNode in
if let itemNode = itemNode as? ContactsPeerItemNode { if let itemNode = itemNode as? ContactsPeerItemNode {

View File

@ -77,12 +77,12 @@ public class ContactsController: ViewController {
var switchToChatsController: (() -> Void)? var switchToChatsController: (() -> Void)?
public override var navigationCustomData: Any? {
didSet { public override func updateNavigationCustomData(_ data: Any?, progress: CGFloat, transition: ContainedViewLayoutTransition) {
self.contactsNode.contactListNode.updateSelectedChatLocation(self.navigationCustomData as? ChatLocation, progress: 1, transition: .immediate) self.contactsNode.contactListNode.updateSelectedChatLocation(data as? ChatLocation, progress: progress, transition: transition)
}
} }
public init(context: AccountContext) { public init(context: AccountContext) {
self.context = context self.context = context

View File

@ -401,6 +401,7 @@ class ContactsPeerItemNode: ItemListRevealOptionsItemNode {
func updateIsHighlighted(transition: ContainedViewLayoutTransition) { func updateIsHighlighted(transition: ContainedViewLayoutTransition) {
var reallyHighlighted = self.isHighlighted var reallyHighlighted = self.isHighlighted
var highlightProgress: CGFloat = self.item?.itemHighlighting?.progress ?? 1.0
if let item = self.item { if let item = self.item {
switch item.peer { switch item.peer {
case let .peer(_, chatPeer): case let .peer(_, chatPeer):
@ -420,10 +421,10 @@ class ContactsPeerItemNode: ItemListRevealOptionsItemNode {
self.highlightedBackgroundNode.alpha = 0.0 self.highlightedBackgroundNode.alpha = 0.0
} }
self.highlightedBackgroundNode.layer.removeAllAnimations() self.highlightedBackgroundNode.layer.removeAllAnimations()
transition.updateAlpha(layer: self.highlightedBackgroundNode.layer, alpha: 1.0) transition.updateAlpha(layer: self.highlightedBackgroundNode.layer, alpha: highlightProgress)
} else { } else {
if self.highlightedBackgroundNode.supernode != nil { if self.highlightedBackgroundNode.supernode != nil {
transition.updateAlpha(layer: self.highlightedBackgroundNode.layer, alpha: 0.0, completion: { [weak self] completed in transition.updateAlpha(layer: self.highlightedBackgroundNode.layer, alpha: highlightProgress, completion: { [weak self] completed in
if let strongSelf = self { if let strongSelf = self {
if completed { if completed {
strongSelf.highlightedBackgroundNode.removeFromSupernode() strongSelf.highlightedBackgroundNode.removeFromSupernode()