mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Avoid flashing the room list skeletons on launch
On a cold launch the home screen appeared just before the cached rooms published, briefly showing skeletons that were immediately replaced. The home screen now starts in a new awaitingCachedRooms mode, keeping the list blank while a cached room list is about to publish and falling back to the skeletons after 500ms. Without a cache the skeletons show straight away as before.
This commit is contained in:
@@ -181,6 +181,13 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
|
||||
updateRoomListMode(with: roomSummaryProvider.statePublisher.value,
|
||||
hasRooms: !roomSummaryProvider.roomListPublisher.value.isEmpty)
|
||||
}
|
||||
|
||||
// Fall back to the skeletons if the cached rooms take too long to publish.
|
||||
Task { [weak self] in
|
||||
try? await Task.sleep(for: .milliseconds(500))
|
||||
guard let self, state.roomListMode == .awaitingCachedRooms else { return }
|
||||
state.roomListMode = .skeletons
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
@@ -342,8 +349,8 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
|
||||
.empty // Loaded, there are no rooms at all.
|
||||
} else if hasRooms || isFiltering {
|
||||
.rooms // Loaded and the summaries have published (or filtered down to nothing).
|
||||
} else if state.roomListMode == .skeletons {
|
||||
.skeletons // Loaded but nothing published yet, flipping to .rooms would flash an empty list.
|
||||
} else if state.roomListMode == .skeletons || state.roomListMode == .awaitingCachedRooms {
|
||||
state.roomListMode // Loaded but nothing published yet, flipping to .rooms would flash an empty list.
|
||||
} else {
|
||||
.rooms
|
||||
}
|
||||
@@ -352,7 +359,7 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
|
||||
return
|
||||
}
|
||||
|
||||
if roomListMode == .rooms, state.roomListMode == .skeletons {
|
||||
if roomListMode == .rooms, state.roomListMode == .skeletons || state.roomListMode == .awaitingCachedRooms {
|
||||
analyticsService.signpost.finishTransaction(.cachedRoomList)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user