mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Fix the room list flashing empty on launch
The room summary provider publishes its loading state and its rooms through two independent streams, so the state can report loaded before the first summaries have been applied. Flipping the room list mode to .rooms at that point renders an empty list until the summaries arrive. Combine the two publishers into a single subscription so that the mode and the rooms are always updated from the same pair of values, and keep the skeletons up until the rooms have published. Only the initial transition is held back, an empty list later on is a filter or a search result and must not send the mode back to the skeletons.
This commit is contained in:
@@ -313,33 +313,34 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
|
||||
return
|
||||
}
|
||||
|
||||
// Combined so that the mode and the rooms are always updated from the same pair of
|
||||
// values: the state can report loaded before the first summaries have published and
|
||||
// flipping to .rooms then would flash an empty list.
|
||||
roomSummaryProvider.statePublisher
|
||||
.combineLatest(roomSummaryProvider.roomListPublisher)
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { [weak self] state in
|
||||
.sink { [weak self] state, rooms in
|
||||
guard let self else { return }
|
||||
|
||||
updateRoomListMode(with: state)
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
roomSummaryProvider.roomListPublisher
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { [weak self] _ in
|
||||
self?.updateRooms()
|
||||
updateRooms()
|
||||
updateRoomListMode(with: state, hasRooms: !rooms.isEmpty)
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
private func updateRoomListMode(with roomSummaryProviderState: RoomSummaryProviderState) {
|
||||
private func updateRoomListMode(with roomSummaryProviderState: RoomSummaryProviderState, hasRooms: Bool) {
|
||||
let isLoadingData = !roomSummaryProviderState.isLoaded
|
||||
let hasNoRooms = roomSummaryProviderState.isLoaded && roomSummaryProviderState.totalNumberOfRooms == 0
|
||||
// Only the initial transition needs holding back until the rooms have published, an
|
||||
// empty list later on is a filter or a search result.
|
||||
let isInitialLoad = state.roomListMode == .skeletons
|
||||
|
||||
var roomListMode = state.roomListMode
|
||||
if isLoadingData {
|
||||
roomListMode = .skeletons
|
||||
} else if hasNoRooms {
|
||||
roomListMode = .empty
|
||||
} else {
|
||||
} else if hasRooms || !isInitialLoad {
|
||||
roomListMode = .rooms
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user