Fix inline chat list theme update

This commit is contained in:
Ali 2022-11-18 19:35:20 +04:00
parent 7338393c59
commit 8687b65acd
7 changed files with 85 additions and 87 deletions

View File

@ -852,8 +852,6 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
)))
}*/
self.primaryContext?.updatePresentationData(presentationData: self.presentationData)
self.statusBar.statusBarStyle = self.presentationData.theme.rootController.statusBarStyle.style
self.navigationBar?.updatePresentationData(NavigationBarPresentationData(presentationData: self.presentationData))
@ -4170,7 +4168,6 @@ private final class ChatListLocationContext {
let context: AccountContext
let location: ChatListControllerLocation
weak var parentController: ChatListControllerImpl?
var presentationData: PresentationData
private var proxyUnavailableTooltipController: TooltipController?
private var didShowProxyUnavailableTooltipController = false
@ -4212,7 +4209,6 @@ private final class ChatListLocationContext {
self.context = context
self.location = location
self.parentController = parentController
self.presentationData = context.sharedContext.currentPresentationData.with { $0 }
let hasProxy = context.sharedContext.accountManager.sharedData(keys: [SharedDataKeys.proxySettings])
|> map { sharedData -> (Bool, Bool) in
@ -4262,8 +4258,9 @@ private final class ChatListLocationContext {
passcode,
chatListDisplayNode.containerNode.currentItemState,
isReorderingTabs,
peerStatus
).start(next: { [weak self] networkState, proxy, passcode, stateAndFilterId, isReorderingTabs, peerStatus in
peerStatus,
parentController.updatedPresentationData.1
).start(next: { [weak self] networkState, proxy, passcode, stateAndFilterId, isReorderingTabs, peerStatus, presentationData in
guard let self else {
return
}
@ -4273,37 +4270,15 @@ private final class ChatListLocationContext {
passcode: passcode,
stateAndFilterId: stateAndFilterId,
isReorderingTabs: isReorderingTabs,
peerStatus: peerStatus
peerStatus: peerStatus,
presentationData: presentationData
)
})
} else {
self.didSetReady = true
self.ready.set(.single(true))
}
case let .forum(peerId):
//self.navigationItem.titleView = chatTitleView
/*chatTitleView.pressed = { [weak self] in
guard let self = self else {
return
}
let _ = (self.context.engine.data.get(
TelegramEngine.EngineData.Item.Peer.Peer(id: peerId)
)
|> deliverOnMainQueue).start(next: { [weak self] peer in
guard let self = self, let peer = peer, let controller = context.sharedContext.makePeerInfoController(context: self.context, updatedPresentationData: nil, peer: peer._asPeer(), mode: .generic, avatarInitiallyExpanded: false, fromChat: false, requestsContext: nil) else {
return
}
(self.navigationController as? NavigationController)?.pushViewController(controller)
})
}
self.chatTitleView?.longPressed = { [weak self] in
guard let self else {
return
}
self.activateSearch()
}*/
case let .forum(peerId):
let peerView = Promise<PeerView>()
peerView.set(context.account.viewTracker.peerView(peerId))
@ -4342,9 +4317,10 @@ private final class ChatListLocationContext {
self.titleDisposable = (combineLatest(queue: Queue.mainQueue(),
peerView.get(),
onlineMemberCount,
chatListDisplayNode.containerNode.currentItemState
chatListDisplayNode.containerNode.currentItemState,
parentController.updatedPresentationData.1
)
|> deliverOnMainQueue).start(next: { [weak self] peerView, onlineMemberCount, stateAndFilterId in
|> deliverOnMainQueue).start(next: { [weak self] peerView, onlineMemberCount, stateAndFilterId, presentationData in
guard let self else {
return
}
@ -4352,7 +4328,8 @@ private final class ChatListLocationContext {
peerId: peerId,
peerView: peerView,
onlineMemberCount: onlineMemberCount,
stateAndFilterId: stateAndFilterId
stateAndFilterId: stateAndFilterId,
presentationData: presentationData
)
})
}
@ -4364,15 +4341,16 @@ private final class ChatListLocationContext {
passcode: (Bool, Bool),
stateAndFilterId: (state: ChatListNodeState, filterId: Int32?),
isReorderingTabs: Bool,
peerStatus: NetworkStatusTitle.Status?
peerStatus: NetworkStatusTitle.Status?,
presentationData: PresentationData
) {
let defaultTitle: String
switch location {
case let .chatList(groupId):
if groupId == .root {
defaultTitle = self.presentationData.strings.DialogList_Title
defaultTitle = presentationData.strings.DialogList_Title
} else {
defaultTitle = self.presentationData.strings.ChatList_ArchivedChatsTitle
defaultTitle = presentationData.strings.ChatList_ArchivedChatsTitle
}
case .forum:
defaultTitle = ""
@ -4385,7 +4363,7 @@ private final class ChatListLocationContext {
if case .chatList(.root) = self.location {
self.rightButton = nil
}
let title = !stateAndFilterId.state.selectedPeerIds.isEmpty ? self.presentationData.strings.ChatList_SelectedChats(Int32(stateAndFilterId.state.selectedPeerIds.count)) : defaultTitle
let title = !stateAndFilterId.state.selectedPeerIds.isEmpty ? presentationData.strings.ChatList_SelectedChats(Int32(stateAndFilterId.state.selectedPeerIds.count)) : defaultTitle
var animated = false
if let (previousEditing, previousNetworkState) = previousEditingAndNetworkState {
@ -4400,7 +4378,7 @@ private final class ChatListLocationContext {
self.rightButton = nil
}
self.leftButton = AnyComponentWithIdentity(id: "done", component: AnyComponent(NavigationButtonComponent(
content: .text(title: self.presentationData.strings.Common_Done, isBold: true),
content: .text(title: presentationData.strings.Common_Done, isBold: true),
pressed: { [weak self] _ in
self?.parentController?.reorderingDonePressed()
}
@ -4410,16 +4388,16 @@ private final class ChatListLocationContext {
switch networkState {
case .waitingForNetwork:
titleContent = NetworkStatusTitle(text: self.presentationData.strings.State_WaitingForNetwork, activity: true, hasProxy: false, connectsViaProxy: connectsViaProxy, isPasscodeSet: false, isManuallyLocked: false, peerStatus: peerStatus)
titleContent = NetworkStatusTitle(text: presentationData.strings.State_WaitingForNetwork, activity: true, hasProxy: false, connectsViaProxy: connectsViaProxy, isPasscodeSet: false, isManuallyLocked: false, peerStatus: peerStatus)
case let .connecting(proxy):
let text = self.presentationData.strings.State_Connecting
let text = presentationData.strings.State_Connecting
let _ = proxy
/*if let layout = strongSelf.validLayout, proxy != nil && layout.metrics.widthClass != .regular && layout.size.width > 320.0 {
text = self.presentationData.strings.State_ConnectingToProxy
}*/
titleContent = NetworkStatusTitle(text: text, activity: true, hasProxy: false, connectsViaProxy: connectsViaProxy, isPasscodeSet: false, isManuallyLocked: false, peerStatus: peerStatus)
case .updating:
titleContent = NetworkStatusTitle(text: self.presentationData.strings.State_Updating, activity: true, hasProxy: false, connectsViaProxy: connectsViaProxy, isPasscodeSet: false, isManuallyLocked: false, peerStatus: peerStatus)
titleContent = NetworkStatusTitle(text: presentationData.strings.State_Updating, activity: true, hasProxy: false, connectsViaProxy: connectsViaProxy, isPasscodeSet: false, isManuallyLocked: false, peerStatus: peerStatus)
case .online:
titleContent = NetworkStatusTitle(text: defaultTitle, activity: false, hasProxy: false, connectsViaProxy: connectsViaProxy, isPasscodeSet: false, isManuallyLocked: false, peerStatus: peerStatus)
}
@ -4430,7 +4408,7 @@ private final class ChatListLocationContext {
if isReorderingTabs {
self.rightButton = AnyComponentWithIdentity(id: "done", component: AnyComponent(NavigationButtonComponent(
content: .text(title: self.presentationData.strings.Common_Done, isBold: true),
content: .text(title: presentationData.strings.Common_Done, isBold: true),
pressed: { [weak self] _ in
self?.parentController?.editPressed()
}
@ -4446,7 +4424,7 @@ private final class ChatListLocationContext {
if isReorderingTabs {
self.leftButton = AnyComponentWithIdentity(id: "done", component: AnyComponent(NavigationButtonComponent(
content: .text(title: self.presentationData.strings.Common_Done, isBold: true),
content: .text(title: presentationData.strings.Common_Done, isBold: true),
pressed: { [weak self] _ in
self?.parentController?.reorderingDonePressed()
}
@ -4454,14 +4432,14 @@ private final class ChatListLocationContext {
} else {
if stateAndFilterId.state.editing {
self.leftButton = AnyComponentWithIdentity(id: "done", component: AnyComponent(NavigationButtonComponent(
content: .text(title: self.presentationData.strings.Common_Done, isBold: true),
content: .text(title: presentationData.strings.Common_Done, isBold: true),
pressed: { [weak self] _ in
self?.parentController?.donePressed()
}
)))
} else {
self.leftButton = AnyComponentWithIdentity(id: "edit", component: AnyComponent(NavigationButtonComponent(
content: .text(title: self.presentationData.strings.Common_Edit, isBold: false),
content: .text(title: presentationData.strings.Common_Edit, isBold: false),
pressed: { [weak self] _ in
self?.parentController?.editPressed()
}
@ -4470,7 +4448,7 @@ private final class ChatListLocationContext {
}
} else {
self.rightButton = AnyComponentWithIdentity(id: "edit", component: AnyComponent(NavigationButtonComponent(
content: .text(title: self.presentationData.strings.Common_Edit, isBold: false),
content: .text(title: presentationData.strings.Common_Edit, isBold: false),
pressed: { [weak self] _ in
self?.parentController?.editPressed()
}
@ -4482,9 +4460,9 @@ private final class ChatListLocationContext {
var checkProxy = false
switch networkState {
case .waitingForNetwork:
titleContent = NetworkStatusTitle(text: self.presentationData.strings.State_WaitingForNetwork, activity: true, hasProxy: false, connectsViaProxy: connectsViaProxy, isPasscodeSet: isRoot && isPasscodeSet, isManuallyLocked: isRoot && isManuallyLocked, peerStatus: peerStatus)
titleContent = NetworkStatusTitle(text: presentationData.strings.State_WaitingForNetwork, activity: true, hasProxy: false, connectsViaProxy: connectsViaProxy, isPasscodeSet: isRoot && isPasscodeSet, isManuallyLocked: isRoot && isManuallyLocked, peerStatus: peerStatus)
case let .connecting(proxy):
let text = self.presentationData.strings.State_Connecting
let text = presentationData.strings.State_Connecting
/*if let layout = strongSelf.validLayout, proxy != nil && layout.metrics.widthClass != .regular && layout.size.width > 320.0 {*/
//text = self.presentationData.strings.State_ConnectingToProxy
//}
@ -4493,7 +4471,7 @@ private final class ChatListLocationContext {
}
titleContent = NetworkStatusTitle(text: text, activity: true, hasProxy: isRoot && hasProxy, connectsViaProxy: connectsViaProxy, isPasscodeSet: isRoot && isPasscodeSet, isManuallyLocked: isRoot && isManuallyLocked, peerStatus: peerStatus)
case .updating:
titleContent = NetworkStatusTitle(text: self.presentationData.strings.State_Updating, activity: true, hasProxy: isRoot && hasProxy, connectsViaProxy: connectsViaProxy, isPasscodeSet: isRoot && isPasscodeSet, isManuallyLocked: isRoot && isManuallyLocked, peerStatus: peerStatus)
titleContent = NetworkStatusTitle(text: presentationData.strings.State_Updating, activity: true, hasProxy: isRoot && hasProxy, connectsViaProxy: connectsViaProxy, isPasscodeSet: isRoot && isPasscodeSet, isManuallyLocked: isRoot && isManuallyLocked, peerStatus: peerStatus)
case .online:
titleContent = NetworkStatusTitle(text: defaultTitle, activity: false, hasProxy: isRoot && hasProxy, connectsViaProxy: connectsViaProxy, isPasscodeSet: isRoot && isPasscodeSet, isManuallyLocked: isRoot && isManuallyLocked, peerStatus: peerStatus)
}
@ -4527,7 +4505,7 @@ private final class ChatListLocationContext {
if case .chatList(.root) = self.location, checkProxy {
if self.proxyUnavailableTooltipController == nil, !self.didShowProxyUnavailableTooltipController, let parentController = self.parentController, parentController.isNodeLoaded, parentController.displayNode.view.window != nil, parentController.navigationController?.topViewController == nil {
self.didShowProxyUnavailableTooltipController = true
let tooltipController = TooltipController(content: .text(self.presentationData.strings.Proxy_TooltipUnavailable), baseFontSize: self.presentationData.listsFontSize.baseDisplaySize, timeout: 60.0, dismissByTapOutside: true)
let tooltipController = TooltipController(content: .text(presentationData.strings.Proxy_TooltipUnavailable), baseFontSize: presentationData.listsFontSize.baseDisplaySize, timeout: 60.0, dismissByTapOutside: true)
self.proxyUnavailableTooltipController = tooltipController
tooltipController.dismissed = { [weak self, weak tooltipController] _ in
if let strongSelf = self, let tooltipController = tooltipController, strongSelf.proxyUnavailableTooltipController === tooltipController {
@ -4562,23 +4540,24 @@ private final class ChatListLocationContext {
peerId: EnginePeer.Id,
peerView: PeerView,
onlineMemberCount: Int32?,
stateAndFilterId: (state: ChatListNodeState, filterId: Int32?)
stateAndFilterId: (state: ChatListNodeState, filterId: Int32?),
presentationData: PresentationData
) {
if stateAndFilterId.state.editing && stateAndFilterId.state.selectedThreadIds.count > 0 {
self.chatTitleComponent = ChatTitleComponent(
context: self.context,
theme: self.presentationData.theme,
strings: self.presentationData.strings,
dateTimeFormat: self.presentationData.dateTimeFormat,
nameDisplayOrder: self.presentationData.nameDisplayOrder,
content: .custom(self.presentationData.strings.ChatList_SelectedTopics(Int32(stateAndFilterId.state.selectedThreadIds.count)), nil, false),
theme: presentationData.theme,
strings: presentationData.strings,
dateTimeFormat: presentationData.dateTimeFormat,
nameDisplayOrder: presentationData.nameDisplayOrder,
content: .custom(presentationData.strings.ChatList_SelectedTopics(Int32(stateAndFilterId.state.selectedThreadIds.count)), nil, false),
tapped: {
},
longTapped: {
}
)
self.rightButton = AnyComponentWithIdentity(id: "done", component: AnyComponent(NavigationButtonComponent(
content: .text(title: self.presentationData.strings.Common_Done, isBold: true),
content: .text(title: presentationData.strings.Common_Done, isBold: true),
pressed: { [weak self] _ in
self?.parentController?.donePressed()
}
@ -4586,10 +4565,10 @@ private final class ChatListLocationContext {
} else {
self.chatTitleComponent = ChatTitleComponent(
context: self.context,
theme: self.presentationData.theme,
strings: self.presentationData.strings,
dateTimeFormat: self.presentationData.dateTimeFormat,
nameDisplayOrder: self.presentationData.nameDisplayOrder,
theme: presentationData.theme,
strings: presentationData.strings,
dateTimeFormat: presentationData.dateTimeFormat,
nameDisplayOrder: presentationData.nameDisplayOrder,
content: .peer(peerView: peerView, customTitle: nil, onlineMemberCount: onlineMemberCount, isScheduledMessages: false, isMuted: nil, customMessageCount: nil),
tapped: { [weak self] in
guard let self else {
@ -4645,9 +4624,6 @@ private final class ChatListLocationContext {
}
}
func updatePresentationData(presentationData: PresentationData) {
}
deinit {
self.titleDisposable?.dispose()
}

View File

@ -1363,6 +1363,7 @@ final class ChatListControllerNode: ASDisplayNode, UIGestureRecognizerDelegate {
self.backgroundColor = self.presentationData.theme.chatList.backgroundColor
self.containerNode.updatePresentationData(presentationData)
self.inlineStackContainerNode?.updatePresentationData(presentationData)
self.searchDisplayController?.updatePresentationData(presentationData)
if let toolbarNode = self.toolbarNode {

View File

@ -3021,7 +3021,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
strongSelf.textNode.textNode.recursivelyEnsureDisplaySynchronously(true)
}
var nextTitleIconOrigin: CGFloat = contentRect.origin.x + titleLayout.size.width + 3.0 + titleOffset
var nextTitleIconOrigin: CGFloat = contentRect.origin.x + titleLayout.trailingLineWidth + 3.0 + titleOffset
if let currentCredibilityIconContent = currentCredibilityIconContent {
let credibilityIconView: ComponentHostView<Empty>

View File

@ -360,7 +360,7 @@ public final class TextNodeLayout: NSObject {
public var trailingLineWidth: CGFloat {
if let lastLine = self.lines.last {
return lastLine.frame.width
return lastLine.frame.maxX
} else {
return 0.0
}

View File

@ -548,6 +548,8 @@ public final class ChatListHeaderComponent: Component {
let chatListTitleContentSize = size
chatListTitleView.setTitle(chatListTitle, animated: false)
chatListTitleView.updateLayout(size: chatListTitleContentSize, clearBounds: CGRect(origin: CGPoint(), size: chatListTitleContentSize), transition: transition.containedViewLayoutTransition)
chatListTitleView.theme = theme
chatListTitleView.strings = strings
chatListTitleView.openStatusSetup = { [weak self] sourceView in
guard let self else {
@ -761,6 +763,7 @@ public final class NavigationButtonComponent: Component {
private var moreButton: MoreHeaderButton?
private var component: NavigationButtonComponent?
private var theme: PresentationTheme?
override init(frame: CGRect) {
super.init(frame: frame)
@ -800,6 +803,11 @@ public final class NavigationButtonComponent: Component {
self.component = component
let theme = environment[NavigationButtonComponentEnvironment.self].value.theme
var themeUpdated = false
if self.theme !== theme {
self.theme = theme
themeUpdated = true
}
let iconOffset: CGFloat = 4.0
@ -852,7 +860,7 @@ public final class NavigationButtonComponent: Component {
self.iconView = iconView
self.addSubview(iconView)
}
if self.iconImageName != imageName {
if self.iconImageName != imageName || themeUpdated {
self.iconImageName = imageName
iconView.image = generateTintedImage(image: UIImage(bundleImageName: imageName), color: theme.rootController.navigationBar.accentTextColor)
}
@ -893,9 +901,14 @@ public final class NavigationButtonComponent: Component {
if isMore {
let moreButton: MoreHeaderButton
if let current = self.moreButton {
if let current = self.moreButton, !themeUpdated {
moreButton = current
} else {
if let moreButton = self.moreButton {
moreButton.removeFromSupernode()
self.moreButton = nil
}
moreButton = MoreHeaderButton(color: theme.rootController.navigationBar.buttonColor)
moreButton.isUserInteractionEnabled = true
moreButton.setContent(.more(MoreHeaderButton.optionsCircleImage(color: theme.rootController.navigationBar.buttonColor)))
@ -911,6 +924,7 @@ public final class NavigationButtonComponent: Component {
}
component.contextAction?(self, gesture)
}
self.moreButton = moreButton
self.addSubnode(moreButton)
}

View File

@ -204,18 +204,22 @@ public final class ChatListTitleView: UIView, NavigationBarTitleView, Navigation
public var theme: PresentationTheme {
didSet {
self.titleNode.attributedText = NSAttributedString(string: self.title.text, font: titleFont, textColor: self.theme.rootController.navigationBar.primaryTextColor)
self.lockView.updateTheme(self.theme)
self.activityIndicator.type = .custom(self.theme.rootController.navigationBar.primaryTextColor, 22.0, 1.5, false)
self.proxyNode.theme = self.theme
if self.theme !== oldValue {
self.titleNode.attributedText = NSAttributedString(string: self.title.text, font: titleFont, textColor: self.theme.rootController.navigationBar.primaryTextColor)
self.lockView.updateTheme(self.theme)
self.activityIndicator.type = .custom(self.theme.rootController.navigationBar.primaryTextColor, 22.0, 1.5, false)
self.proxyNode.theme = self.theme
}
}
}
public var strings: PresentationStrings {
didSet {
self.proxyButton.accessibilityLabel = self.strings.VoiceOver_Navigation_ProxySettings
if self.strings !== oldValue {
self.proxyButton.accessibilityLabel = self.strings.VoiceOver_Navigation_ProxySettings
}
}
}

View File

@ -694,17 +694,19 @@ public final class ChatTitleView: UIView, NavigationBarTitleView {
}
public func updateThemeAndStrings(theme: PresentationTheme, strings: PresentationStrings, hasEmbeddedTitleContent: Bool) {
self.theme = theme
self.hasEmbeddedTitleContent = hasEmbeddedTitleContent
self.strings = strings
let titleContent = self.titleContent
self.titleCredibilityIcon = .none
self.titleContent = titleContent
let _ = self.updateStatus()
if !self.manualLayout, let (size, clearBounds) = self.validLayout {
self.updateLayout(size: size, clearBounds: clearBounds, transition: .immediate)
if self.theme !== theme || self.strings !== strings || self.hasEmbeddedTitleContent != hasEmbeddedTitleContent {
self.theme = theme
self.hasEmbeddedTitleContent = hasEmbeddedTitleContent
self.strings = strings
let titleContent = self.titleContent
self.titleCredibilityIcon = .none
self.titleContent = titleContent
let _ = self.updateStatus()
if !self.manualLayout, let (size, clearBounds) = self.validLayout {
self.updateLayout(size: size, clearBounds: clearBounds, transition: .immediate)
}
}
}
@ -1009,6 +1011,7 @@ public final class ChatTitleComponent: Component {
if contentView.titleContent != component.content {
contentView.titleContent = component.content
}
contentView.updateThemeAndStrings(theme: component.theme, strings: component.strings, hasEmbeddedTitleContent: false)
contentView.updateLayout(size: availableSize, clearBounds: CGRect(origin: CGPoint(), size: availableSize), transition: transition.containedViewLayoutTransition)
transition.setFrame(view: contentView, frame: CGRect(origin: CGPoint(), size: availableSize))