From 372a2d536042a8a86924c30c45fd41f735f042c0 Mon Sep 17 00:00:00 2001 From: Flavio Alescio Date: Fri, 12 May 2023 14:19:56 +0200 Subject: [PATCH] change accesibility identifiers, remove single selection button style, use Picker instead, --- .../Other/AccessibilityIdentifiers.swift | 4 +- .../Form Styles/FormButtonStyles.swift | 18 ------ .../Screens/CreateRoom/CreateRoomModels.swift | 2 - .../CreateRoom/CreateRoomViewModel.swift | 4 -- .../CreateRoom/View/CreateRoomScreen.swift | 57 ++++++++----------- .../SessionVerificationScreenViewModel.swift | 6 +- .../Sources/CreateRoomViewModelTests.swift | 7 --- 7 files changed, 27 insertions(+), 71 deletions(-) diff --git a/ElementX/Sources/Other/AccessibilityIdentifiers.swift b/ElementX/Sources/Other/AccessibilityIdentifiers.swift index 3331bbe49..a81c9fbdf 100644 --- a/ElementX/Sources/Other/AccessibilityIdentifiers.swift +++ b/ElementX/Sources/Other/AccessibilityIdentifiers.swift @@ -133,7 +133,7 @@ struct A11yIdentifiers { } struct CreateRoomScreen { - let roomName = "create-room-room-name" - let roomTopic = "create-room-room-topic" + let roomName = "create_room-room_name" + let roomTopic = "create_room-room_topic" } } diff --git a/ElementX/Sources/Other/SwiftUI/Form Styles/FormButtonStyles.swift b/ElementX/Sources/Other/SwiftUI/Form Styles/FormButtonStyles.swift index 934620c41..2a684e516 100644 --- a/ElementX/Sources/Other/SwiftUI/Form Styles/FormButtonStyles.swift +++ b/ElementX/Sources/Other/SwiftUI/Form Styles/FormButtonStyles.swift @@ -21,7 +21,6 @@ enum FormRowAccessory: View { case navigationLink case progressView case selection(isSelected: Bool) - case singleSelection(isSelected: Bool) var body: some View { switch self { @@ -35,10 +34,6 @@ enum FormRowAccessory: View { Image(systemName: isSelected ? "checkmark.circle.fill" : "circle") .font(.compound.bodyLG) .foregroundColor(isSelected ? .element.primaryContent : .element.tertiaryContent) - case .singleSelection(let isSelected): - Image(systemName: "checkmark") - .font(.compound.bodyLG) - .foregroundColor(isSelected ? .element.primaryContent : .clear) } } } @@ -140,19 +135,6 @@ struct FormButtonStyles_Previews: PreviewProvider { Text("Selection") } .buttonStyle(FormButtonStyle(accessory: .selection(isSelected: false))) - Button { } label: { - Label { - VStack(alignment: .leading, spacing: 8) { - Text("Hello world") - Text("subtitle\nsubtitle") - .font(.compound.bodyMD) - .foregroundColor(.element.secondaryContent) - } - } icon: { - Image(systemName: "globe") - } - } - .buttonStyle(FormButtonStyle(iconAlignment: .top, accessory: .singleSelection(isSelected: true))) } .formSectionStyle() diff --git a/ElementX/Sources/Screens/CreateRoom/CreateRoomModels.swift b/ElementX/Sources/Screens/CreateRoom/CreateRoomModels.swift index 563dcc665..e821a62f1 100644 --- a/ElementX/Sources/Screens/CreateRoom/CreateRoomModels.swift +++ b/ElementX/Sources/Screens/CreateRoom/CreateRoomModels.swift @@ -38,7 +38,5 @@ struct CreateRoomViewStateBindings { enum CreateRoomViewAction { case createRoom - case selectPrivateRoom - case selectPublicRoom case deselectUser(UserProfile) } diff --git a/ElementX/Sources/Screens/CreateRoom/CreateRoomViewModel.swift b/ElementX/Sources/Screens/CreateRoom/CreateRoomViewModel.swift index 7e462e760..5b8bd5221 100644 --- a/ElementX/Sources/Screens/CreateRoom/CreateRoomViewModel.swift +++ b/ElementX/Sources/Screens/CreateRoom/CreateRoomViewModel.swift @@ -43,10 +43,6 @@ class CreateRoomViewModel: CreateRoomViewModelType, CreateRoomViewModelProtocol case .deselectUser(let user): state.selectedUsers.removeAll(where: { $0.userID == user.userID }) actionsSubject.send(.deselectUser(user)) - case .selectPrivateRoom: - state.bindings.isRoomPrivate = true - case .selectPublicRoom: - state.bindings.isRoomPrivate = false } } diff --git a/ElementX/Sources/Screens/CreateRoom/View/CreateRoomScreen.swift b/ElementX/Sources/Screens/CreateRoom/View/CreateRoomScreen.swift index 9a25d0687..ccecec057 100644 --- a/ElementX/Sources/Screens/CreateRoom/View/CreateRoomScreen.swift +++ b/ElementX/Sources/Screens/CreateRoom/View/CreateRoomScreen.swift @@ -31,6 +31,7 @@ struct CreateRoomScreen: View { createButton } } + .background(ViewFrameReader(frame: $frame)) } /// The main content of the view to be shown in a scroll view. @@ -38,22 +39,19 @@ struct CreateRoomScreen: View { Form { roomSection topicSection - if !context.viewState.selectedUsers.isEmpty { - selectedUsersSection - } Spacer() .listRowBackground(Color.clear) securitySection } } - @ScaledMetric private var roomIconSide: CGFloat = 64 + @ScaledMetric private var roomIconSize: CGFloat = 64 private var roomSection: some View { Section { HStack(alignment: .center, spacing: 16) { Image(systemName: "camera") .foregroundColor(.element.secondaryContent) - .frame(width: roomIconSide, height: roomIconSide) + .frame(width: roomIconSize, height: roomIconSize) .background(Color.element.quinaryContent) .clipShape(Circle()) VStack(alignment: .leading, spacing: 8) { @@ -87,31 +85,34 @@ struct CreateRoomScreen: View { .lineLimit(3, reservesSpace: false) } header: { Text(L10n.screenCreateRoomTopicLabel) + } footer: { + if !context.viewState.selectedUsers.isEmpty { + selectedUsersSection + } } .formSectionStyle() } - @ScaledMetric private var cellWidth: CGFloat = 64 + @State private var frame: CGRect = .zero + @ScaledMetric private var invitedUserCellWidth: CGFloat = 64 private var selectedUsersSection: some View { - Section { - ScrollView(.horizontal, showsIndicators: false) { - LazyHStack(spacing: 28) { - ForEach(context.viewState.selectedUsers, id: \.userID) { user in - InviteUsersScreenSelectedItem(user: user, imageProvider: context.imageProvider) { - deselect(user) - } - .frame(width: cellWidth) + ScrollView(.horizontal, showsIndicators: false) { + LazyHStack(spacing: 28) { + ForEach(context.viewState.selectedUsers, id: \.userID) { user in + InviteUsersScreenSelectedItem(user: user, imageProvider: context.imageProvider) { + context.send(viewAction: .deselectUser(user)) } + .frame(width: invitedUserCellWidth) } } - .listRowInsets(.init()) - .listRowBackground(Color.clear) + .padding(.init(top: 16, leading: 32, bottom: 16, trailing: 32)) } + .frame(width: frame.width) } private var securitySection: some View { Section { - Button(action: selectPrivate) { + Picker(L10n.commonSecurity, selection: $context.isRoomPrivate) { Label { VStack(alignment: .leading, spacing: 8) { Text(L10n.screenCreateRoomPrivateOptionTitle) @@ -122,9 +123,8 @@ struct CreateRoomScreen: View { } icon: { Image(systemName: "lock.shield") } - } - .buttonStyle(FormButtonStyle(iconAlignment: .top, accessory: .singleSelection(isSelected: context.isRoomPrivate))) - Button(action: selectPublic) { + .tag(true) + .labelStyle(FormRowLabelStyle(alignment: .top)) Label { VStack(alignment: .leading, spacing: 8) { Text(L10n.screenCreateRoomPublicOptionTitle) @@ -135,8 +135,11 @@ struct CreateRoomScreen: View { } icon: { Image(systemName: "exclamationmark.shield") } + .tag(false) + .labelStyle(FormRowLabelStyle(alignment: .top)) } - .buttonStyle(FormButtonStyle(iconAlignment: .top, accessory: .singleSelection(isSelected: !context.isRoomPrivate))) + .labelsHidden() + .pickerStyle(.inline) } header: { Text(L10n.commonSecurity.uppercased()) } @@ -149,18 +152,6 @@ struct CreateRoomScreen: View { } .disabled(!context.viewState.canCreateRoom) } - - private func selectPrivate() { - context.send(viewAction: .selectPrivateRoom) - } - - private func selectPublic() { - context.send(viewAction: .selectPublicRoom) - } - - private func deselect(_ user: UserProfile) { - context.send(viewAction: .deselectUser(user)) - } } // MARK: - Previews diff --git a/ElementX/Sources/Screens/SessionVerificationScreen/SessionVerificationScreenViewModel.swift b/ElementX/Sources/Screens/SessionVerificationScreen/SessionVerificationScreenViewModel.swift index 6e12abd94..b54d2b730 100644 --- a/ElementX/Sources/Screens/SessionVerificationScreen/SessionVerificationScreenViewModel.swift +++ b/ElementX/Sources/Screens/SessionVerificationScreen/SessionVerificationScreenViewModel.swift @@ -109,11 +109,7 @@ class SessionVerificationScreenViewModel: SessionVerificationViewModelType, Sess case (_, _, .verified): // Dismiss the success screen automatically. Task { - do { - try await Task.sleep(for: .seconds(2)) - } catch { - MXLog.error(error.localizedDescription) - } + try? await Task.sleep(for: .seconds(2)) self.callback?(.finished) } default: diff --git a/UnitTests/Sources/CreateRoomViewModelTests.swift b/UnitTests/Sources/CreateRoomViewModelTests.swift index 2b09d8f84..47c9cc02b 100644 --- a/UnitTests/Sources/CreateRoomViewModelTests.swift +++ b/UnitTests/Sources/CreateRoomViewModelTests.swift @@ -49,13 +49,6 @@ class CreateRoomScreenViewModelTests: XCTestCase { XCTAssertTrue(context.viewState.bindings.isRoomPrivate) } - func testChangeSecurity() { - context.send(viewAction: .selectPublicRoom) - XCTAssertFalse(context.viewState.bindings.isRoomPrivate) - context.send(viewAction: .selectPrivateRoom) - XCTAssertTrue(context.viewState.bindings.isRoomPrivate) - } - func testCreateRoomRequirements() { XCTAssertFalse(context.viewState.canCreateRoom) context.roomName = "A"