mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Add the initial implementation for managing spaces. (#4963)
This isn't hooked up into the flows yet.
This commit is contained in:
+61
@@ -0,0 +1,61 @@
|
||||
//
|
||||
// Copyright 2025 Element Creations Ltd.
|
||||
// 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 SpaceRemoveChildrenConfirmationView: View {
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
|
||||
let spaceName: String
|
||||
let action: () -> Void
|
||||
|
||||
@State private var scrollViewHeight: CGFloat = .zero
|
||||
@State private var buttonsHeight: CGFloat = .zero
|
||||
private let topPadding = 19.0
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
TitleAndIcon(title: L10n.screenSpaceRemoveRoomsConfirmationTitleIos(spaceName),
|
||||
subtitle: L10n.screenSpaceRemoveRoomsConfirmationContent,
|
||||
icon: \.errorSolid,
|
||||
iconStyle: .alertSolid)
|
||||
.padding(24)
|
||||
.readHeight($scrollViewHeight)
|
||||
}
|
||||
.backportSafeAreaBar(edge: .bottom, spacing: 0) {
|
||||
buttons
|
||||
.readHeight($buttonsHeight)
|
||||
}
|
||||
.scrollBounceBehavior(.basedOnSize)
|
||||
.padding(.top, topPadding) // For the drag indicator
|
||||
.presentationDetents([.height(scrollViewHeight + buttonsHeight + topPadding)])
|
||||
.presentationDragIndicator(.visible)
|
||||
.presentationBackground(.compound.bgCanvasDefault)
|
||||
}
|
||||
|
||||
var buttons: some View {
|
||||
VStack(spacing: 16) {
|
||||
Button(L10n.actionRemove, role: .destructive, action: action)
|
||||
.buttonStyle(.compound(.primary))
|
||||
|
||||
Button(L10n.actionCancel, action: dismiss.callAsFunction)
|
||||
.buttonStyle(.compound(.tertiary))
|
||||
}
|
||||
.padding(.horizontal, 16)
|
||||
.padding(.top, 16)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
struct SpaceRemoveChildrenConfirmationView_Previews: PreviewProvider, TestablePreview {
|
||||
static var previews: some View {
|
||||
SpaceRemoveChildrenConfirmationView(spaceName: "Company") { }
|
||||
}
|
||||
}
|
||||
@@ -12,19 +12,37 @@ import SwiftUI
|
||||
struct SpaceScreen: View {
|
||||
@Bindable var context: SpaceScreenViewModel.Context
|
||||
|
||||
private var isEditModeActive: Bool { context.viewState.editMode != .inactive }
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
LazyVStack(spacing: 0) {
|
||||
SpaceHeaderView(spaceServiceRoom: context.viewState.space,
|
||||
mediaProvider: context.mediaProvider)
|
||||
if !isEditModeActive {
|
||||
SpaceHeaderView(spaceServiceRoom: context.viewState.space,
|
||||
mediaProvider: context.mediaProvider)
|
||||
}
|
||||
|
||||
rooms
|
||||
}
|
||||
}
|
||||
.environment(\.editMode, .constant(context.viewState.editMode))
|
||||
.background(Color.compound.bgCanvasDefault.ignoresSafeArea())
|
||||
.toolbarRole(RoomHeaderView.toolbarRole)
|
||||
.toolbarRole(isEditModeActive ? .automatic : RoomHeaderView.toolbarRole)
|
||||
.navigationTitle(context.viewState.space.name)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar { toolbar }
|
||||
.navigationBarBackButtonHidden(isEditModeActive)
|
||||
.toolbar {
|
||||
if isEditModeActive {
|
||||
editModeToolbar
|
||||
} else {
|
||||
toolbar
|
||||
}
|
||||
}
|
||||
.sheet(isPresented: $context.isPresentingRemoveChildrenConfirmation) {
|
||||
SpaceRemoveChildrenConfirmationView(spaceName: context.viewState.space.name) {
|
||||
context.send(viewAction: .confirmRemoveSelectedChildren)
|
||||
}
|
||||
}
|
||||
.sheet(item: $context.leaveSpaceViewModel) { leaveSpaceViewModel in
|
||||
LeaveSpaceView(context: leaveSpaceViewModel.context)
|
||||
}
|
||||
@@ -32,9 +50,9 @@ struct SpaceScreen: View {
|
||||
|
||||
@ViewBuilder
|
||||
var rooms: some View {
|
||||
ForEach(context.viewState.rooms, id: \.id) { spaceServiceRoom in
|
||||
ForEach(context.viewState.visibleRooms, id: \.id) { spaceServiceRoom in
|
||||
SpaceRoomCell(spaceServiceRoom: spaceServiceRoom,
|
||||
isSelected: spaceServiceRoom.id == context.viewState.selectedSpaceRoomID,
|
||||
isSelected: context.viewState.isSpaceIDSelected(spaceServiceRoom.id),
|
||||
isJoining: context.viewState.joiningRoomIDs.contains(spaceServiceRoom.id),
|
||||
mediaProvider: context.mediaProvider) { action in
|
||||
context.send(viewAction: .spaceAction(action))
|
||||
@@ -100,20 +118,46 @@ struct SpaceScreen: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ToolbarContentBuilder
|
||||
var editModeToolbar: some ToolbarContent {
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
Button(L10n.actionCancel, role: .cancel) {
|
||||
context.send(viewAction: .finishManagingChildren)
|
||||
}
|
||||
}
|
||||
|
||||
ToolbarItem(placement: .principal) {
|
||||
Text(L10n.commonSelectedCount(context.viewState.editModeSelectedIDs.count))
|
||||
}
|
||||
|
||||
ToolbarItem(placement: .primaryAction) {
|
||||
ToolbarButton(role: .destructive(title: L10n.actionRemove)) {
|
||||
context.send(viewAction: .removeSelectedChildren)
|
||||
}
|
||||
.disabled(context.viewState.editModeSelectedIDs.isEmpty)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
struct SpaceScreen_Previews: PreviewProvider, TestablePreview {
|
||||
static let viewModel = makeViewModel()
|
||||
static let managingViewModel = makeViewModel(isManagingRooms: true)
|
||||
|
||||
static var previews: some View {
|
||||
NavigationStack {
|
||||
SpaceScreen(context: viewModel.context)
|
||||
}
|
||||
|
||||
NavigationStack {
|
||||
SpaceScreen(context: managingViewModel.context)
|
||||
}
|
||||
.previewDisplayName("Managing")
|
||||
}
|
||||
|
||||
static func makeViewModel() -> SpaceScreenViewModel {
|
||||
static func makeViewModel(isManagingRooms: Bool = false) -> SpaceScreenViewModel {
|
||||
let spaceServiceRoom = SpaceServiceRoomMock(.init(id: "!eng-space:matrix.org",
|
||||
name: "Engineering Team",
|
||||
isSpace: true,
|
||||
@@ -138,6 +182,12 @@ struct SpaceScreen_Previews: PreviewProvider, TestablePreview {
|
||||
userSession: userSession,
|
||||
appSettings: AppSettings(),
|
||||
userIndicatorController: UserIndicatorControllerMock())
|
||||
|
||||
if isManagingRooms {
|
||||
viewModel.state.editMode = .transient
|
||||
viewModel.state.editModeSelectedIDs = [viewModel.state.visibleRooms[0].id]
|
||||
}
|
||||
|
||||
return viewModel
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user