Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add highlighting of cell in chat list when returning to screen #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions TelegramUI/ChatListController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -682,9 +682,7 @@ public class ChatListController: TelegramController, KeyShortcutResponder, UIVie
if let layout = strongSelf.validLayout, case .regular = layout.metrics.widthClass {
scrollToEndIfExists = true
}
navigateToChatController(navigationController: navigationController, context: strongSelf.context, chatLocation: .peer(peerId), scrollToEndIfExists: scrollToEndIfExists, animated: animated, completion: { [weak self] in
self?.chatListDisplayNode.chatListNode.clearHighlightAnimated(true)
})
navigateToChatController(navigationController: navigationController, context: strongSelf.context, chatLocation: .peer(peerId), scrollToEndIfExists: scrollToEndIfExists, animated: animated)
}
}
}
Expand All @@ -694,7 +692,6 @@ public class ChatListController: TelegramController, KeyShortcutResponder, UIVie
if let navigationController = strongSelf.navigationController as? NavigationController {
let chatListController = ChatListController(context: strongSelf.context, groupId: groupId, controlsHistoryPreload: false)
navigationController.pushViewController(chatListController)
strongSelf.chatListDisplayNode.chatListNode.clearHighlightAnimated(true)
}
}
}
Expand Down Expand Up @@ -1070,8 +1067,17 @@ public class ChatListController: TelegramController, KeyShortcutResponder, UIVie
self.dismissSearchOnDisappear = false
self.deactivateSearch(animated: false)
}

self.chatListDisplayNode.chatListNode.clearHighlightAnimated(true)
}

override public func navigationAlongsideTransition(type: NavigationTransition) -> ((CGFloat) -> ())? {
switch type {
case .Pop:
return { [weak self] progress in
self?.chatListDisplayNode.chatListNode.updateHiglightPercent(1 - progress)
}
case .Push:
return nil
}
}

override public func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) {
Expand All @@ -1091,10 +1097,17 @@ public class ChatListController: TelegramController, KeyShortcutResponder, UIVie

override public func navigationStackConfigurationUpdated(next: [ViewController]) {
super.navigationStackConfigurationUpdated(next: next)

let chatLocation = (next.first as? ChatController)?.chatLocation

self.chatListDisplayNode.chatListNode.updateSelectedChatLocation(chatLocation, progress: 1.0, transition: .immediate)

if UIDevice.current.userInterfaceIdiom != .phone {
let chatLocation = (navigationController?.viewControllers.last as? ChatController)?.chatLocation
chatListDisplayNode.chatListNode.clearHighlightAnimated(false)
chatListDisplayNode.chatListNode.updateSelectedChatLocation(chatLocation, progress: 1.0, transition: .immediate)
} else {
if let chatLocation = (navigationController?.viewControllers.last as? ChatController)?.chatLocation {
chatListDisplayNode.chatListNode.clearHighlightAnimated(false)
chatListDisplayNode.chatListNode.updateSelectedChatLocation(chatLocation, progress: 1.0, transition: .immediate)
}
}
}

@objc func editPressed() {
Expand Down
13 changes: 13 additions & 0 deletions TelegramUI/ChatListItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,17 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
self.updateIsHighlighted(transition: (animated && !highlighted) ? .animated(duration: 0.3, curve: .easeInOut) : .immediate)
}

override func setHighlightedPercent(_ percent: CGFloat) -> Bool {
guard isHighlighted else { return false }

if percent == 0 {
setHighlighted(false, at: .zero, animated: true)
} else {
self.highlightedBackgroundNode.alpha = 2 * (1 - 1 / (1 + percent))
}
return isHighlighted
}

func updateIsHighlighted(transition: ContainedViewLayoutTransition) {
var reallyHighlighted = self.isHighlighted
if let item = self.item {
Expand All @@ -513,6 +524,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
}

if reallyHighlighted {
self.isHighlighted = true
if self.highlightedBackgroundNode.supernode == nil {
self.insertSubnode(self.highlightedBackgroundNode, aboveSubnode: self.separatorNode)
self.highlightedBackgroundNode.alpha = 0.0
Expand All @@ -524,6 +536,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
self.onlineNode.setImage(PresentationResourcesChatList.recentStatusOnlineIcon(item.presentationData.theme, state: .highlighted))
}
} else {
self.isHighlighted = false
if self.highlightedBackgroundNode.supernode != nil {
transition.updateAlpha(layer: self.highlightedBackgroundNode.layer, alpha: 0.0, completion: { [weak self] completed in
if let strongSelf = self {
Expand Down
21 changes: 21 additions & 0 deletions TelegramUI/ChatListNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1419,11 +1419,32 @@ final class ChatListNode: ListView {

self.forEachItemNode { itemNode in
if let itemNode = itemNode as? ChatListItemNode {
_ = itemNode.setHighlightedPercent(0)
itemNode.updateIsHighlighted(transition: transition)
}
}
}

private var nodeCurrentlyBeingAnimated: ChatListItemNode?
override public func updateHiglightPercent(_ percent: CGFloat) {
if percent == 0, let interaction = self.interaction {
interaction.highlightedChatLocation = nil
}
if percent == 0 || percent == 1 {
nodeCurrentlyBeingAnimated = nil
}

if let currentlyAnimatedNode = nodeCurrentlyBeingAnimated {
_ = currentlyAnimatedNode.setHighlightedPercent(percent)
} else {
self.forEachItemNode { itemNode in
if let itemNode = itemNode as? ChatListItemNode, itemNode.setHighlightedPercent(percent) {
nodeCurrentlyBeingAnimated = itemNode
}
}
}
}

private func currentlyVisibleLatestChatListIndex() -> ChatListIndex? {
guard let chatListView = (self.opaqueTransactionState as? ChatListOpaqueTransactionState)?.chatListView else {
return nil
Expand Down