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:
Stefan Ceriu
2026-10-02 10:06:00 +03:00
parent 4b6953e80f
commit a50c80c179
5 changed files with 42 additions and 10 deletions
@@ -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)
}