Hook up the RoomThreadList to the RoomFlowCoordinator state machine and presenting threads.

This commit is contained in:
Stefan Ceriu
2026-04-01 09:27:39 +03:00
committed by Stefan Ceriu
parent 212cd42161
commit a358cacf31
9 changed files with 67 additions and 17 deletions
@@ -13,7 +13,9 @@ struct RoomThreadListScreenCoordinatorParameters {
let mediaProvider: MediaProviderProtocol
}
enum RoomThreadListScreenCoordinatorAction { }
enum RoomThreadListScreenCoordinatorAction {
case presentThread(threadRootEventID: String)
}
final class RoomThreadListScreenCoordinator: CoordinatorProtocol {
private let parameters: RoomThreadListScreenCoordinatorParameters
@@ -35,7 +37,13 @@ final class RoomThreadListScreenCoordinator: CoordinatorProtocol {
func start() {
viewModel.actionsPublisher.sink { [weak self] action in
guard let self else { return }
MXLog.info("Coordinator: received view model action: \(action)")
switch action {
case .presentThread(let threadRootEventID):
actionsSubject.send(.presentThread(threadRootEventID: threadRootEventID))
}
}
.store(in: &cancellables)
}
@@ -7,7 +7,9 @@
import Foundation
enum RoomThreadListScreenViewModelAction { }
enum RoomThreadListScreenViewModelAction {
case presentThread(threadRootEventID: String)
}
struct RoomThreadListScreenViewState: BindableState {
var items = [RoomThreadListItem]()
@@ -22,4 +24,5 @@ struct RoomThreadListScreenViewStateBindings { }
enum RoomThreadListScreenViewAction {
case oldestItemDidAppear
case oldestItemDidDisappear
case tappedThread(threadRootEventID: String)
}
@@ -58,6 +58,8 @@ class RoomThreadListScreenViewModel: RoomThreadListScreenViewModelType, RoomThre
}
case .oldestItemDidDisappear:
isOldestItemVisible = false
case .tappedThread(let threadRootEventID):
actionsSubject.send(.presentThread(threadRootEventID: threadRootEventID))
}
}
@@ -15,9 +15,14 @@ struct RoomThreadListScreen: View {
ScrollView {
LazyVStack(spacing: 0) {
ForEach(context.viewState.items) { item in
RoomThreadListCell(item: item, mediaProvider: context.mediaProvider)
.padding(.horizontal, 16)
.padding(.vertical, 8)
Button {
context.send(viewAction: .tappedThread(threadRootEventID: item.id))
} label: {
RoomThreadListCell(item: item, mediaProvider: context.mediaProvider)
.padding(.horizontal, 16)
.padding(.vertical, 8)
}
.buttonStyle(ThreadCellButtonStyle())
}
footer
@@ -137,6 +142,14 @@ private struct RoomThreadListCell: View {
}
}
private struct ThreadCellButtonStyle: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
.background(configuration.isPressed ? Color.compound.bgSubtleSecondary : Color.compound.bgCanvasDefault)
.contentShape(Rectangle())
}
}
// MARK: - Previews
struct RoomThreadListScreen_Previews: PreviewProvider, TestablePreview {