Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App Layout: Cancel and Back on Spaces Bottom Sheet #6582

Merged
merged 2 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ final class SpaceSelectorBottomSheetCoordinator: Coordinator, Presentable {
let parameters = SpaceSelectorCoordinatorParameters(session: parameters.session,
parentSpaceId: parentSpaceId,
selectedSpaceId: parameters.selectedSpaceId,
showHomeSpace: parameters.showHomeSpace)
showHomeSpace: parameters.showHomeSpace,
showCancel: navigationRouter.modules.isEmpty)
let coordinator = SpaceSelectorCoordinator(parameters: parameters)
coordinator.completion = { [weak self] result in
guard let self = self else { return }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@ struct SpaceSelectorCoordinatorParameters {
let parentSpaceId: String?
let selectedSpaceId: String?
let showHomeSpace: Bool
let showCancel: Bool

init(session: MXSession,
parentSpaceId: String? = nil,
selectedSpaceId: String? = nil,
showHomeSpace: Bool = false) {
showHomeSpace: Bool = false,
showCancel: Bool) {
self.session = session
self.parentSpaceId = parentSpaceId
self.selectedSpaceId = selectedSpaceId
self.showHomeSpace = showHomeSpace
self.showCancel = showCancel
}
}

Expand Down Expand Up @@ -58,7 +61,7 @@ final class SpaceSelectorCoordinator: Coordinator, Presentable {
init(parameters: SpaceSelectorCoordinatorParameters) {
self.parameters = parameters
let service = SpaceSelectorService(session: parameters.session, parentSpaceId: parameters.parentSpaceId, showHomeSpace: parameters.showHomeSpace, selectedSpaceId: parameters.selectedSpaceId)
let viewModel = SpaceSelectorViewModel.makeViewModel(service: service)
let viewModel = SpaceSelectorViewModel.makeViewModel(service: service, showCancel: parameters.showCancel)
let view = SpaceSelector(viewModel: viewModel.context)
.addDependency(AvatarService.instantiate(mediaManager: parameters.session.mediaManager))
self.viewModel = viewModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ enum MockSpaceSelectorScreenState: MockScreenState, CaseIterable {
case .selection:
service = MockSpaceSelectorService(selectedSpaceId: MockSpaceSelectorService.defaultSpaceList[2].id)
}
let viewModel = SpaceSelectorViewModel.makeViewModel(service: service)
let viewModel = SpaceSelectorViewModel.makeViewModel(service: service, showCancel: true)

// can simulate service and viewModel actions here if needs be.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ struct SpaceSelectorViewState: BindableState {
var selectedSpaceId: String?
/// String to be displayed as title for the navigation bar
var navigationTitle: String
/// `true` if the view should display the cancel button in the navigation bar
let showCancel: Bool
}

enum SpaceSelectorViewAction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,21 @@ class SpaceSelectorViewModel: SpaceSelectorViewModelType, SpaceSelectorViewModel

// MARK: - Setup

static func makeViewModel(service: SpaceSelectorServiceProtocol) -> SpaceSelectorViewModelProtocol {
return SpaceSelectorViewModel(service: service)
static func makeViewModel(service: SpaceSelectorServiceProtocol, showCancel: Bool) -> SpaceSelectorViewModelProtocol {
return SpaceSelectorViewModel(service: service, showCancel: showCancel)
}

private init(service: SpaceSelectorServiceProtocol) {
private init(service: SpaceSelectorServiceProtocol, showCancel: Bool) {
self.service = service
super.init(initialViewState: Self.defaultState(service: service))
super.init(initialViewState: Self.defaultState(service: service, showCancel: showCancel))
}

private static func defaultState(service: SpaceSelectorServiceProtocol) -> SpaceSelectorViewState {
private static func defaultState(service: SpaceSelectorServiceProtocol, showCancel: Bool) -> SpaceSelectorViewState {
let parentName = service.parentSpaceNameSubject.value
return SpaceSelectorViewState(items: service.spaceListSubject.value,
selectedSpaceId: service.selectedSpaceId,
navigationTitle: parentName ?? VectorL10n.spaceSelectorTitle)
navigationTitle: parentName ?? VectorL10n.spaceSelectorTitle,
showCancel: showCancel)
}

// MARK: - Public
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ import Foundation
protocol SpaceSelectorViewModelProtocol {

var completion: ((SpaceSelectorViewModelResult) -> Void)? { get set }
static func makeViewModel(service: SpaceSelectorServiceProtocol) -> SpaceSelectorViewModelProtocol
static func makeViewModel(service: SpaceSelectorServiceProtocol, showCancel: Bool) -> SpaceSelectorViewModelProtocol
var context: SpaceSelectorViewModelType.Context { get }
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SpaceSelectorViewModelTests: XCTestCase {

override func setUpWithError() throws {
service = MockSpaceSelectorService()
viewModel = SpaceSelectorViewModel.makeViewModel(service: service)
viewModel = SpaceSelectorViewModel.makeViewModel(service: service, showCancel: true)
context = viewModel.context
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ struct SpaceSelector: View {
}
}
ToolbarItem(placement: .cancellationAction) {
Button(VectorL10n.cancel) {
viewModel.send(viewAction: .cancel)
if viewModel.viewState.showCancel {
Button(VectorL10n.cancel) {
viewModel.send(viewAction: .cancel)
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions changelog.d/6572.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
App Layout: fixed Cancel and Back on Spaces Bottom Sheet