Add a SpaceExplorerFlowCoordinator. (#4383)

* Add a SpaceExplorerFlowCoordinator.

* Project tweaks

- iOS 17.5 so that we can use the simulator.
- Make a Spaces group for common Space related views.
- Fix the tab bar badge colour on iPhone landscape and iPadOS 17 (18 is still wrong 😒)
This commit is contained in:
Doug
2025-08-07 12:48:53 +01:00
committed by GitHub
parent e95e8ff5aa
commit c47ec8a7cc
10 changed files with 177 additions and 48 deletions
@@ -0,0 +1,54 @@
//
// Copyright 2025 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
// Please see LICENSE files in the repository root for full details.
//
// periphery:ignore:all - this is just a spaceList remove this comment once generating the final file
import Combine
import SwiftUI
struct SpaceListScreenCoordinatorParameters {
let userSession: UserSessionProtocol
}
enum SpaceListScreenCoordinatorAction {
case showSettings
}
final class SpaceListScreenCoordinator: CoordinatorProtocol {
private let parameters: SpaceListScreenCoordinatorParameters
private let viewModel: SpaceListScreenViewModelProtocol
private var cancellables = Set<AnyCancellable>()
private let actionsSubject: PassthroughSubject<SpaceListScreenCoordinatorAction, Never> = .init()
var actionsPublisher: AnyPublisher<SpaceListScreenCoordinatorAction, Never> {
actionsSubject.eraseToAnyPublisher()
}
init(parameters: SpaceListScreenCoordinatorParameters) {
self.parameters = parameters
viewModel = SpaceListScreenViewModel(userSession: parameters.userSession)
}
func start() {
viewModel.actionsPublisher.sink { [weak self] action in
MXLog.info("Coordinator: received view model action: \(action)")
guard let self else { return }
switch action {
case .showSettings:
actionsSubject.send(.showSettings)
}
}
.store(in: &cancellables)
}
func toPresentable() -> AnyView {
AnyView(SpaceListScreen(context: viewModel.context))
}
}
@@ -0,0 +1,33 @@
//
// Copyright 2025 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
// Please see LICENSE files in the repository root for full details.
//
import Foundation
enum SpaceListScreenViewModelAction {
case showSettings
}
struct SpaceListScreenViewState: BindableState {
let userID: String
var userDisplayName: String?
var userAvatarURL: URL?
var rooms: [HomeScreenRoom]
var joinedRoomsCount: Int
var bindings: SpaceListScreenViewStateBindings
var subtitle: String {
L10n.screenSpaceListDetails(L10n.commonSpaces(rooms.count), L10n.commonRooms(joinedRoomsCount))
}
}
struct SpaceListScreenViewStateBindings { }
enum SpaceListScreenViewAction {
case showSettings
}
@@ -0,0 +1,47 @@
//
// Copyright 2025 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
// Please see LICENSE files in the repository root for full details.
//
import Combine
import SwiftUI
typealias SpaceListScreenViewModelType = StateStoreViewModelV2<SpaceListScreenViewState, SpaceListScreenViewAction>
class SpaceListScreenViewModel: SpaceListScreenViewModelType, SpaceListScreenViewModelProtocol {
private let actionsSubject: PassthroughSubject<SpaceListScreenViewModelAction, Never> = .init()
var actionsPublisher: AnyPublisher<SpaceListScreenViewModelAction, Never> {
actionsSubject.eraseToAnyPublisher()
}
init(userSession: UserSessionProtocol) {
super.init(initialViewState: SpaceListScreenViewState(userID: userSession.clientProxy.userID,
rooms: [],
joinedRoomsCount: 0,
bindings: .init()),
mediaProvider: userSession.mediaProvider)
userSession.clientProxy.userAvatarURLPublisher
.receive(on: DispatchQueue.main)
.weakAssign(to: \.state.userAvatarURL, on: self)
.store(in: &cancellables)
userSession.clientProxy.userDisplayNamePublisher
.receive(on: DispatchQueue.main)
.weakAssign(to: \.state.userDisplayName, on: self)
.store(in: &cancellables)
}
// MARK: - Public
override func process(viewAction: SpaceListScreenViewAction) {
MXLog.info("View model: received view action: \(viewAction)")
switch viewAction {
case .showSettings:
actionsSubject.send(.showSettings)
}
}
}
@@ -0,0 +1,14 @@
//
// Copyright 2025 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
// Please see LICENSE files in the repository root for full details.
//
import Combine
@MainActor
protocol SpaceListScreenViewModelProtocol {
var actionsPublisher: AnyPublisher<SpaceListScreenViewModelAction, Never> { get }
var context: SpaceListScreenViewModelType.Context { get }
}
@@ -0,0 +1,101 @@
//
// Copyright 2025 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
// Please see LICENSE files in the repository root for full details.
//
import Compound
import SwiftUI
struct SpaceListScreen: View {
@Bindable var context: SpaceListScreenViewModel.Context
var body: some View {
ScrollView {
LazyVStack(spacing: 0) {
header
}
}
.navigationTitle(L10n.screenSpaceListTitle)
.navigationBarTitleDisplayMode(.inline)
.toolbar { toolbar }
.background(Color.compound.bgCanvasDefault.ignoresSafeArea())
.bloom()
}
var header: some View {
VStack(spacing: 16) {
BigIcon(icon: \.spaceSolid)
VStack(spacing: 8) {
Text(L10n.screenSpaceListTitle)
.font(.compound.headingLGBold)
.foregroundStyle(.compound.textPrimary)
.multilineTextAlignment(.center)
Text(context.viewState.subtitle)
.font(.compound.bodyLG)
.foregroundStyle(.compound.textSecondary)
.multilineTextAlignment(.center)
}
Text(L10n.screenSpaceListDescription)
.font(.compound.bodyMD)
.foregroundStyle(.compound.textPrimary)
.multilineTextAlignment(.center)
}
.frame(maxWidth: .infinity)
.padding(.horizontal, 16)
.padding(.top, 32)
.padding(.bottom, 24)
.overlay(alignment: .bottom) {
Rectangle()
.fill(Color.compound.borderDisabled)
.frame(height: 1 / UIScreen.main.scale)
}
}
@ToolbarContentBuilder
var toolbar: some ToolbarContent {
ToolbarItem(placement: .navigationBarLeading) {
Button {
context.send(viewAction: .showSettings)
} label: {
LoadableAvatarImage(url: context.viewState.userAvatarURL,
name: context.viewState.userDisplayName,
contentID: context.viewState.userID,
avatarSize: .user(on: .home),
mediaProvider: context.mediaProvider)
.accessibilityIdentifier(A11yIdentifiers.homeScreen.userAvatar)
.compositingGroup()
}
.accessibilityLabel(L10n.commonSettings)
}
ToolbarItem(placement: .principal) {
// Hides the navigationTitle (which is set for the navigation stack label).
Text("").accessibilityHidden(true)
}
}
}
// MARK: - Previews
struct SpaceListScreen_Previews: PreviewProvider, TestablePreview {
static let viewModel = makeViewModel()
static var previews: some View {
NavigationStack {
SpaceListScreen(context: viewModel.context)
}
}
static func makeViewModel(counterValue: Int = 0) -> SpaceListScreenViewModel {
let clientProxy = ClientProxyMock(.init())
let userSession = UserSessionMock(.init(clientProxy: clientProxy))
let viewModel = SpaceListScreenViewModel(userSession: userSession)
return viewModel
}
}