Fix chat title update

This commit is contained in:
Isaac 2026-02-10 10:52:53 +04:00
parent 73d7587a06
commit 692fbd9742
5 changed files with 48 additions and 11 deletions

View file

@ -1 +1 @@
2620 2720

View file

@ -16,7 +16,7 @@ import EmojiStatusComponent
import GlassBackgroundComponent import GlassBackgroundComponent
public final class ChatNavigationBarTitleView: UIView, NavigationBarTitleView { public final class ChatNavigationBarTitleView: UIView, NavigationBarTitleView {
private final class ContentData { private final class ContentData: Equatable {
let context: AccountContext let context: AccountContext
let theme: PresentationTheme let theme: PresentationTheme
let preferClearGlass: Bool let preferClearGlass: Bool
@ -36,6 +36,34 @@ public final class ChatNavigationBarTitleView: UIView, NavigationBarTitleView {
self.nameDisplayOrder = nameDisplayOrder self.nameDisplayOrder = nameDisplayOrder
self.content = content self.content = content
} }
static func ==(lhs: ContentData, rhs: ContentData) -> Bool {
if lhs.context !== rhs.context {
return false
}
if lhs.theme !== rhs.theme {
return false
}
if lhs.preferClearGlass != rhs.preferClearGlass {
return false
}
if lhs.wallpaper != rhs.wallpaper {
return false
}
if lhs.strings !== rhs.strings {
return false
}
if lhs.dateTimeFormat != rhs.dateTimeFormat {
return false
}
if lhs.nameDisplayOrder != rhs.nameDisplayOrder {
return false
}
if lhs.content != rhs.content {
return false
}
return true
}
} }
private let parentTitleState = ComponentState() private let parentTitleState = ComponentState()
@ -86,9 +114,9 @@ public final class ChatNavigationBarTitleView: UIView, NavigationBarTitleView {
content: ChatTitleContent, content: ChatTitleContent,
transition: ComponentTransition, transition: ComponentTransition,
ignoreParentTransitionRequests: Bool = false ignoreParentTransitionRequests: Bool = false
) { ) -> Bool {
self.ignoreParentTransitionRequests = ignoreParentTransitionRequests self.ignoreParentTransitionRequests = ignoreParentTransitionRequests
self.contentData = ContentData( let contentData = ContentData(
context: context, context: context,
theme: theme, theme: theme,
preferClearGlass: preferClearGlass, preferClearGlass: preferClearGlass,
@ -98,8 +126,12 @@ public final class ChatNavigationBarTitleView: UIView, NavigationBarTitleView {
nameDisplayOrder: nameDisplayOrder, nameDisplayOrder: nameDisplayOrder,
content: content content: content
) )
let isUpdated = self.contentData != contentData
self.contentData = contentData
self.update(transition: transition) self.update(transition: transition)
self.ignoreParentTransitionRequests = false self.ignoreParentTransitionRequests = false
return isUpdated
} }
public func updateActivities(activities: ChatTitleComponent.Activities?, transition: ComponentTransition) { public func updateActivities(activities: ChatTitleComponent.Activities?, transition: ComponentTransition) {

View file

@ -456,12 +456,14 @@ func updateChatPresentationInterfaceStateImpl(
selfController.tempHideAccessoryPanels = selfController.presentationInterfaceState.search != nil selfController.tempHideAccessoryPanels = selfController.presentationInterfaceState.search != nil
if let chatTitleContent = selfController.contentData?.state.chatTitleContent { var forceLayout = false
if let chatTitleContent = selfController.contentData?.state.chatTitleContent, let chatTitleView = selfController.chatTitleView {
var titleTransition = ComponentTransition(transition) var titleTransition = ComponentTransition(transition)
if case .messageOptions = selfController.subject { if case .messageOptions = selfController.subject {
titleTransition = titleTransition.withAnimation(.none) titleTransition = titleTransition.withAnimation(.none)
} }
selfController.chatTitleView?.update( let isChatTitleViewUpdated = chatTitleView.update(
context: selfController.context, context: selfController.context,
theme: selfController.presentationData.theme, theme: selfController.presentationData.theme,
preferClearGlass: selfController.presentationInterfaceState.preferredGlassType == .clear, preferClearGlass: selfController.presentationInterfaceState.preferredGlassType == .clear,
@ -473,10 +475,13 @@ func updateChatPresentationInterfaceStateImpl(
transition: titleTransition, transition: titleTransition,
ignoreParentTransitionRequests: true ignoreParentTransitionRequests: true
) )
if isChatTitleViewUpdated {
forceLayout = true
}
} }
if selfController.isNodeLoaded { if selfController.isNodeLoaded {
selfController.chatDisplayNode.updateChatPresentationInterfaceState(updatedChatPresentationInterfaceState, transition: transition, interactive: interactive, completion: completion) selfController.chatDisplayNode.updateChatPresentationInterfaceState(updatedChatPresentationInterfaceState, transition: transition, interactive: interactive, forceLayout: forceLayout, completion: completion)
} else { } else {
completion(.immediate) completion(.immediate)
} }

View file

@ -49,7 +49,7 @@ extension ChatControllerImpl {
contentNode.setErrorText(errorText: self.presentationData.strings.QuickReply_ShortcutExistsInlineError) contentNode.setErrorText(errorText: self.presentationData.strings.QuickReply_ShortcutExistsInlineError)
} }
} else { } else {
self.chatTitleView?.update( let _ = self.chatTitleView?.update(
context: self.context, context: self.context,
theme: self.presentationData.theme, theme: self.presentationData.theme,
preferClearGlass: self.presentationInterfaceState.preferredGlassType == .clear, preferClearGlass: self.presentationInterfaceState.preferredGlassType == .clear,
@ -102,7 +102,7 @@ extension ChatControllerImpl {
} else { } else {
linkUrl = link.url linkUrl = link.url
} }
self.chatTitleView?.update( let _ = self.chatTitleView?.update(
context: self.context, context: self.context,
theme: self.presentationData.theme, theme: self.presentationData.theme,
preferClearGlass: self.presentationInterfaceState.preferredGlassType == .clear, preferClearGlass: self.presentationInterfaceState.preferredGlassType == .clear,

View file

@ -3435,7 +3435,7 @@ class ChatControllerNode: ASDisplayNode, ASScrollViewDelegate {
} }
} }
func updateChatPresentationInterfaceState(_ chatPresentationInterfaceState: ChatPresentationInterfaceState, transition: ContainedViewLayoutTransition, interactive: Bool, completion: @escaping (ContainedViewLayoutTransition) -> Void) { func updateChatPresentationInterfaceState(_ chatPresentationInterfaceState: ChatPresentationInterfaceState, transition: ContainedViewLayoutTransition, interactive: Bool, forceLayout: Bool, completion: @escaping (ContainedViewLayoutTransition) -> Void) {
self.selectedMessages = chatPresentationInterfaceState.interfaceState.selectionState?.selectedIds self.selectedMessages = chatPresentationInterfaceState.interfaceState.selectionState?.selectedIds
var textStateUpdated = false var textStateUpdated = false
@ -3451,7 +3451,7 @@ class ChatControllerNode: ASDisplayNode, ASScrollViewDelegate {
let presentationReadyUpdated = self.chatPresentationInterfaceState.presentationReady != chatPresentationInterfaceState.presentationReady let presentationReadyUpdated = self.chatPresentationInterfaceState.presentationReady != chatPresentationInterfaceState.presentationReady
if (self.chatPresentationInterfaceState != chatPresentationInterfaceState && chatPresentationInterfaceState.presentationReady) || textStateUpdated { if (self.chatPresentationInterfaceState != chatPresentationInterfaceState && chatPresentationInterfaceState.presentationReady) || textStateUpdated || forceLayout {
self.onLayoutCompletions.append(completion) self.onLayoutCompletions.append(completion)
let themeUpdated = presentationReadyUpdated || (self.chatPresentationInterfaceState.theme !== chatPresentationInterfaceState.theme) let themeUpdated = presentationReadyUpdated || (self.chatPresentationInterfaceState.theme !== chatPresentationInterfaceState.theme)