Fix call list presentation data updates

This commit is contained in:
Ali 2019-12-01 01:35:20 +04:00
parent c1728f9719
commit 8eccc02e55
4 changed files with 32 additions and 31 deletions

View File

@ -134,7 +134,7 @@ public final class CallListController: ViewController {
self.navigationBar?.updatePresentationData(NavigationBarPresentationData(presentationData: self.presentationData)) self.navigationBar?.updatePresentationData(NavigationBarPresentationData(presentationData: self.presentationData))
if self.isNodeLoaded { if self.isNodeLoaded {
self.controllerNode.updateThemeAndStrings(theme: self.presentationData.theme, strings: self.presentationData.strings, dateTimeFormat: self.presentationData.dateTimeFormat, disableAnimations: self.presentationData.disableAnimations) self.controllerNode.updateThemeAndStrings(presentationData: self.presentationData)
} }
} }

View File

@ -74,30 +74,26 @@ final class CallListNodeInteraction {
} }
struct CallListNodeState: Equatable { struct CallListNodeState: Equatable {
let theme: PresentationTheme let presentationData: ItemListPresentationData
let strings: PresentationStrings
let dateTimeFormat: PresentationDateTimeFormat let dateTimeFormat: PresentationDateTimeFormat
let disableAnimations: Bool let disableAnimations: Bool
let editing: Bool let editing: Bool
let messageIdWithRevealedOptions: MessageId? let messageIdWithRevealedOptions: MessageId?
func withUpdatedPresentationData(theme: PresentationTheme, strings: PresentationStrings, dateTimeFormat: PresentationDateTimeFormat, disableAnimations: Bool) -> CallListNodeState { func withUpdatedPresentationData(presentationData: ItemListPresentationData, dateTimeFormat: PresentationDateTimeFormat, disableAnimations: Bool) -> CallListNodeState {
return CallListNodeState(theme: theme, strings: strings, dateTimeFormat: dateTimeFormat, disableAnimations: disableAnimations, editing: self.editing, messageIdWithRevealedOptions: self.messageIdWithRevealedOptions) return CallListNodeState(presentationData: presentationData, dateTimeFormat: dateTimeFormat, disableAnimations: disableAnimations, editing: self.editing, messageIdWithRevealedOptions: self.messageIdWithRevealedOptions)
} }
func withUpdatedEditing(_ editing: Bool) -> CallListNodeState { func withUpdatedEditing(_ editing: Bool) -> CallListNodeState {
return CallListNodeState(theme: self.theme, strings: self.strings, dateTimeFormat: self.dateTimeFormat, disableAnimations: self.disableAnimations, editing: editing, messageIdWithRevealedOptions: self.messageIdWithRevealedOptions) return CallListNodeState(presentationData: self.presentationData, dateTimeFormat: self.dateTimeFormat, disableAnimations: self.disableAnimations, editing: editing, messageIdWithRevealedOptions: self.messageIdWithRevealedOptions)
} }
func withUpdatedMessageIdWithRevealedOptions(_ messageIdWithRevealedOptions: MessageId?) -> CallListNodeState { func withUpdatedMessageIdWithRevealedOptions(_ messageIdWithRevealedOptions: MessageId?) -> CallListNodeState {
return CallListNodeState(theme: self.theme, strings: self.strings, dateTimeFormat: self.dateTimeFormat, disableAnimations: self.disableAnimations, editing: self.editing, messageIdWithRevealedOptions: messageIdWithRevealedOptions) return CallListNodeState(presentationData: self.presentationData, dateTimeFormat: self.dateTimeFormat, disableAnimations: self.disableAnimations, editing: self.editing, messageIdWithRevealedOptions: messageIdWithRevealedOptions)
} }
static func ==(lhs: CallListNodeState, rhs: CallListNodeState) -> Bool { static func ==(lhs: CallListNodeState, rhs: CallListNodeState) -> Bool {
if lhs.theme !== rhs.theme { if lhs.presentationData != rhs.presentationData {
return false
}
if lhs.strings !== rhs.strings {
return false return false
} }
if lhs.dateTimeFormat != rhs.dateTimeFormat { if lhs.dateTimeFormat != rhs.dateTimeFormat {
@ -209,7 +205,7 @@ final class CallListControllerNode: ASDisplayNode {
self.openInfo = openInfo self.openInfo = openInfo
self.emptyStateUpdated = emptyStateUpdated self.emptyStateUpdated = emptyStateUpdated
self.currentState = CallListNodeState(theme: presentationData.theme, strings: presentationData.strings, dateTimeFormat: presentationData.dateTimeFormat, disableAnimations: presentationData.disableAnimations, editing: false, messageIdWithRevealedOptions: nil) self.currentState = CallListNodeState(presentationData: ItemListPresentationData(presentationData), dateTimeFormat: presentationData.dateTimeFormat, disableAnimations: presentationData.disableAnimations, editing: false, messageIdWithRevealedOptions: nil)
self.statePromise = ValuePromise(self.currentState, ignoreRepeated: true) self.statePromise = ValuePromise(self.currentState, ignoreRepeated: true)
self.listNode = ListView() self.listNode = ListView()
@ -299,8 +295,9 @@ final class CallListControllerNode: ASDisplayNode {
return value return value
} }
let callListNodeViewTransition = combineLatest(callListViewUpdate, self.statePromise.get(), showCallsTab) |> mapToQueue { (update, state, showCallsTab) -> Signal<CallListNodeListViewTransition, NoError> in let callListNodeViewTransition = combineLatest(callListViewUpdate, self.statePromise.get(), showCallsTab)
let processedView = CallListNodeView(originalView: update.view, filteredEntries: callListNodeEntriesForView(update.view, state: state, showSettings: showSettings, showCallsTab: showCallsTab)) |> mapToQueue { (update, state, showCallsTab) -> Signal<CallListNodeListViewTransition, NoError> in
let processedView = CallListNodeView(originalView: update.view, filteredEntries: callListNodeEntriesForView(update.view, state: state, showSettings: showSettings, showCallsTab: showCallsTab), presentationData: state.presentationData)
let previous = previousView.swap(processedView) let previous = previousView.swap(processedView)
let reason: CallListNodeViewTransitionReason let reason: CallListNodeViewTransitionReason
@ -343,7 +340,7 @@ final class CallListControllerNode: ASDisplayNode {
} }
return preparedCallListNodeViewTransition(from: previous, to: processedView, reason: reason, disableAnimations: false, account: context.account, scrollPosition: update.scrollPosition) return preparedCallListNodeViewTransition(from: previous, to: processedView, reason: reason, disableAnimations: false, account: context.account, scrollPosition: update.scrollPosition)
|> map({ mappedCallListNodeViewListTransition(account: context.account, presentationData: ItemListPresentationData(presentationData), showSettings: showSettings, nodeInteraction: nodeInteraction, transition: $0) }) |> map({ mappedCallListNodeViewListTransition(account: context.account, presentationData: state.presentationData, showSettings: showSettings, nodeInteraction: nodeInteraction, transition: $0) })
|> runOn(prepareOnMainQueue ? Queue.mainQueue() : viewProcessingQueue) |> runOn(prepareOnMainQueue ? Queue.mainQueue() : viewProcessingQueue)
} }
@ -381,7 +378,7 @@ final class CallListControllerNode: ASDisplayNode {
self.emptyStateDisposable.set((combineLatest(emptySignal, typeSignal, self.statePromise.get()) |> deliverOnMainQueue).start(next: { [weak self] isEmpty, type, state in self.emptyStateDisposable.set((combineLatest(emptySignal, typeSignal, self.statePromise.get()) |> deliverOnMainQueue).start(next: { [weak self] isEmpty, type, state in
if let strongSelf = self { if let strongSelf = self {
strongSelf.updateEmptyPlaceholder(theme: state.theme, strings: state.strings, type: type, hidden: !isEmpty) strongSelf.updateEmptyPlaceholder(theme: state.presentationData.theme, strings: state.presentationData.strings, type: type, hidden: !isEmpty)
} }
})) }))
} }
@ -391,23 +388,25 @@ final class CallListControllerNode: ASDisplayNode {
self.emptyStateDisposable.dispose() self.emptyStateDisposable.dispose()
} }
func updateThemeAndStrings(theme: PresentationTheme, strings: PresentationStrings, dateTimeFormat: PresentationDateTimeFormat, disableAnimations: Bool) { func updateThemeAndStrings(presentationData: PresentationData) {
if theme !== self.currentState.theme || strings !== self.currentState.strings || disableAnimations != self.currentState.disableAnimations { if presentationData.theme !== self.currentState.presentationData.theme || presentationData.strings !== self.currentState.presentationData.strings || presentationData.disableAnimations != self.currentState.disableAnimations {
self.leftOverlayNode.backgroundColor = theme.list.blocksBackgroundColor self.presentationData = presentationData
self.rightOverlayNode.backgroundColor = theme.list.blocksBackgroundColor
self.leftOverlayNode.backgroundColor = presentationData.theme.list.blocksBackgroundColor
self.rightOverlayNode.backgroundColor = presentationData.theme.list.blocksBackgroundColor
switch self.mode { switch self.mode {
case .tab: case .tab:
self.backgroundColor = theme.chatList.backgroundColor self.backgroundColor = presentationData.theme.chatList.backgroundColor
self.listNode.backgroundColor = theme.chatList.backgroundColor self.listNode.backgroundColor = presentationData.theme.chatList.backgroundColor
case .navigation: case .navigation:
self.backgroundColor = theme.list.blocksBackgroundColor self.backgroundColor = presentationData.theme.list.blocksBackgroundColor
self.listNode.backgroundColor = theme.list.blocksBackgroundColor self.listNode.backgroundColor = presentationData.theme.list.blocksBackgroundColor
} }
self.updateEmptyPlaceholder(theme: theme, strings: strings, type: self.currentLocationAndType.type, hidden: self.emptyTextNode.isHidden) self.updateEmptyPlaceholder(theme: presentationData.theme, strings: presentationData.strings, type: self.currentLocationAndType.type, hidden: self.emptyTextNode.isHidden)
self.updateState { self.updateState {
return $0.withUpdatedPresentationData(theme: theme, strings: strings, dateTimeFormat: dateTimeFormat, disableAnimations: disableAnimations) return $0.withUpdatedPresentationData(presentationData: ItemListPresentationData(presentationData), dateTimeFormat: presentationData.dateTimeFormat, disableAnimations: presentationData.disableAnimations)
} }
} }
} }

View File

@ -183,14 +183,14 @@ func callListNodeEntriesForView(_ view: CallListView, state: CallListNodeState,
for entry in view.entries { for entry in view.entries {
switch entry { switch entry {
case let .message(topMessage, messages): case let .message(topMessage, messages):
result.append(.messageEntry(topMessage: topMessage, messages: messages, theme: state.theme, strings: state.strings, dateTimeFormat: state.dateTimeFormat, editing: state.editing, hasActiveRevealControls: state.messageIdWithRevealedOptions == topMessage.id)) result.append(.messageEntry(topMessage: topMessage, messages: messages, theme: state.presentationData.theme, strings: state.presentationData.strings, dateTimeFormat: state.dateTimeFormat, editing: state.editing, hasActiveRevealControls: state.messageIdWithRevealedOptions == topMessage.id))
case let .hole(index): case let .hole(index):
result.append(.holeEntry(index: index, theme: state.theme)) result.append(.holeEntry(index: index, theme: state.presentationData.theme))
} }
} }
if showSettings { if showSettings {
result.append(.displayTabInfo(state.theme, state.strings.CallSettings_TabIconDescription)) result.append(.displayTabInfo(state.presentationData.theme, state.presentationData.strings.CallSettings_TabIconDescription))
result.append(.displayTab(state.theme, state.strings.CallSettings_TabIcon, showCallsTab)) result.append(.displayTab(state.presentationData.theme, state.presentationData.strings.CallSettings_TabIcon, showCallsTab))
} }
return result return result
} }

View File

@ -6,10 +6,12 @@ import SyncCore
import SwiftSignalKit import SwiftSignalKit
import Display import Display
import MergeLists import MergeLists
import ItemListUI
struct CallListNodeView { struct CallListNodeView {
let originalView: CallListView let originalView: CallListView
let filteredEntries: [CallListNodeEntry] let filteredEntries: [CallListNodeEntry]
let presentationData: ItemListPresentationData
} }
enum CallListNodeViewTransitionReason { enum CallListNodeViewTransitionReason {
@ -49,7 +51,7 @@ enum CallListNodeViewScrollPosition {
func preparedCallListNodeViewTransition(from fromView: CallListNodeView?, to toView: CallListNodeView, reason: CallListNodeViewTransitionReason, disableAnimations: Bool, account: Account, scrollPosition: CallListNodeViewScrollPosition?) -> Signal<CallListNodeViewTransition, NoError> { func preparedCallListNodeViewTransition(from fromView: CallListNodeView?, to toView: CallListNodeView, reason: CallListNodeViewTransitionReason, disableAnimations: Bool, account: Account, scrollPosition: CallListNodeViewScrollPosition?) -> Signal<CallListNodeViewTransition, NoError> {
return Signal { subscriber in return Signal { subscriber in
let (deleteIndices, indicesAndItems, updateIndices) = mergeListsStableWithUpdates(leftList: fromView?.filteredEntries ?? [], rightList: toView.filteredEntries) let (deleteIndices, indicesAndItems, updateIndices) = mergeListsStableWithUpdates(leftList: fromView?.filteredEntries ?? [], rightList: toView.filteredEntries, allUpdated: fromView?.presentationData != toView.presentationData)
var adjustedDeleteIndices: [ListViewDeleteItem] = [] var adjustedDeleteIndices: [ListViewDeleteItem] = []
let previousCount: Int let previousCount: Int