change accesibility identifiers, remove single selection button style, use Picker instead,

This commit is contained in:
Flavio Alescio
2023-05-12 14:19:56 +02:00
committed by Flescio
parent 41094cb293
commit 372a2d5360
7 changed files with 27 additions and 71 deletions
@@ -133,7 +133,7 @@ struct A11yIdentifiers {
} }
struct CreateRoomScreen { struct CreateRoomScreen {
let roomName = "create-room-room-name" let roomName = "create_room-room_name"
let roomTopic = "create-room-room-topic" let roomTopic = "create_room-room_topic"
} }
} }
@@ -21,7 +21,6 @@ enum FormRowAccessory: View {
case navigationLink case navigationLink
case progressView case progressView
case selection(isSelected: Bool) case selection(isSelected: Bool)
case singleSelection(isSelected: Bool)
var body: some View { var body: some View {
switch self { switch self {
@@ -35,10 +34,6 @@ enum FormRowAccessory: View {
Image(systemName: isSelected ? "checkmark.circle.fill" : "circle") Image(systemName: isSelected ? "checkmark.circle.fill" : "circle")
.font(.compound.bodyLG) .font(.compound.bodyLG)
.foregroundColor(isSelected ? .element.primaryContent : .element.tertiaryContent) .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") Text("Selection")
} }
.buttonStyle(FormButtonStyle(accessory: .selection(isSelected: false))) .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() .formSectionStyle()
@@ -38,7 +38,5 @@ struct CreateRoomViewStateBindings {
enum CreateRoomViewAction { enum CreateRoomViewAction {
case createRoom case createRoom
case selectPrivateRoom
case selectPublicRoom
case deselectUser(UserProfile) case deselectUser(UserProfile)
} }
@@ -43,10 +43,6 @@ class CreateRoomViewModel: CreateRoomViewModelType, CreateRoomViewModelProtocol
case .deselectUser(let user): case .deselectUser(let user):
state.selectedUsers.removeAll(where: { $0.userID == user.userID }) state.selectedUsers.removeAll(where: { $0.userID == user.userID })
actionsSubject.send(.deselectUser(user)) actionsSubject.send(.deselectUser(user))
case .selectPrivateRoom:
state.bindings.isRoomPrivate = true
case .selectPublicRoom:
state.bindings.isRoomPrivate = false
} }
} }
@@ -31,6 +31,7 @@ struct CreateRoomScreen: View {
createButton createButton
} }
} }
.background(ViewFrameReader(frame: $frame))
} }
/// The main content of the view to be shown in a scroll view. /// The main content of the view to be shown in a scroll view.
@@ -38,22 +39,19 @@ struct CreateRoomScreen: View {
Form { Form {
roomSection roomSection
topicSection topicSection
if !context.viewState.selectedUsers.isEmpty {
selectedUsersSection
}
Spacer() Spacer()
.listRowBackground(Color.clear) .listRowBackground(Color.clear)
securitySection securitySection
} }
} }
@ScaledMetric private var roomIconSide: CGFloat = 64 @ScaledMetric private var roomIconSize: CGFloat = 64
private var roomSection: some View { private var roomSection: some View {
Section { Section {
HStack(alignment: .center, spacing: 16) { HStack(alignment: .center, spacing: 16) {
Image(systemName: "camera") Image(systemName: "camera")
.foregroundColor(.element.secondaryContent) .foregroundColor(.element.secondaryContent)
.frame(width: roomIconSide, height: roomIconSide) .frame(width: roomIconSize, height: roomIconSize)
.background(Color.element.quinaryContent) .background(Color.element.quinaryContent)
.clipShape(Circle()) .clipShape(Circle())
VStack(alignment: .leading, spacing: 8) { VStack(alignment: .leading, spacing: 8) {
@@ -87,31 +85,34 @@ struct CreateRoomScreen: View {
.lineLimit(3, reservesSpace: false) .lineLimit(3, reservesSpace: false)
} header: { } header: {
Text(L10n.screenCreateRoomTopicLabel) Text(L10n.screenCreateRoomTopicLabel)
} footer: {
if !context.viewState.selectedUsers.isEmpty {
selectedUsersSection
}
} }
.formSectionStyle() .formSectionStyle()
} }
@ScaledMetric private var cellWidth: CGFloat = 64 @State private var frame: CGRect = .zero
@ScaledMetric private var invitedUserCellWidth: CGFloat = 64
private var selectedUsersSection: some View { private var selectedUsersSection: some View {
Section { ScrollView(.horizontal, showsIndicators: false) {
ScrollView(.horizontal, showsIndicators: false) { LazyHStack(spacing: 28) {
LazyHStack(spacing: 28) { ForEach(context.viewState.selectedUsers, id: \.userID) { user in
ForEach(context.viewState.selectedUsers, id: \.userID) { user in InviteUsersScreenSelectedItem(user: user, imageProvider: context.imageProvider) {
InviteUsersScreenSelectedItem(user: user, imageProvider: context.imageProvider) { context.send(viewAction: .deselectUser(user))
deselect(user)
}
.frame(width: cellWidth)
} }
.frame(width: invitedUserCellWidth)
} }
} }
.listRowInsets(.init()) .padding(.init(top: 16, leading: 32, bottom: 16, trailing: 32))
.listRowBackground(Color.clear)
} }
.frame(width: frame.width)
} }
private var securitySection: some View { private var securitySection: some View {
Section { Section {
Button(action: selectPrivate) { Picker(L10n.commonSecurity, selection: $context.isRoomPrivate) {
Label { Label {
VStack(alignment: .leading, spacing: 8) { VStack(alignment: .leading, spacing: 8) {
Text(L10n.screenCreateRoomPrivateOptionTitle) Text(L10n.screenCreateRoomPrivateOptionTitle)
@@ -122,9 +123,8 @@ struct CreateRoomScreen: View {
} icon: { } icon: {
Image(systemName: "lock.shield") Image(systemName: "lock.shield")
} }
} .tag(true)
.buttonStyle(FormButtonStyle(iconAlignment: .top, accessory: .singleSelection(isSelected: context.isRoomPrivate))) .labelStyle(FormRowLabelStyle(alignment: .top))
Button(action: selectPublic) {
Label { Label {
VStack(alignment: .leading, spacing: 8) { VStack(alignment: .leading, spacing: 8) {
Text(L10n.screenCreateRoomPublicOptionTitle) Text(L10n.screenCreateRoomPublicOptionTitle)
@@ -135,8 +135,11 @@ struct CreateRoomScreen: View {
} icon: { } icon: {
Image(systemName: "exclamationmark.shield") Image(systemName: "exclamationmark.shield")
} }
.tag(false)
.labelStyle(FormRowLabelStyle(alignment: .top))
} }
.buttonStyle(FormButtonStyle(iconAlignment: .top, accessory: .singleSelection(isSelected: !context.isRoomPrivate))) .labelsHidden()
.pickerStyle(.inline)
} header: { } header: {
Text(L10n.commonSecurity.uppercased()) Text(L10n.commonSecurity.uppercased())
} }
@@ -149,18 +152,6 @@ struct CreateRoomScreen: View {
} }
.disabled(!context.viewState.canCreateRoom) .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 // MARK: - Previews
@@ -109,11 +109,7 @@ class SessionVerificationScreenViewModel: SessionVerificationViewModelType, Sess
case (_, _, .verified): case (_, _, .verified):
// Dismiss the success screen automatically. // Dismiss the success screen automatically.
Task { Task {
do { try? await Task.sleep(for: .seconds(2))
try await Task.sleep(for: .seconds(2))
} catch {
MXLog.error(error.localizedDescription)
}
self.callback?(.finished) self.callback?(.finished)
} }
default: default:
@@ -49,13 +49,6 @@ class CreateRoomScreenViewModelTests: XCTestCase {
XCTAssertTrue(context.viewState.bindings.isRoomPrivate) 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() { func testCreateRoomRequirements() {
XCTAssertFalse(context.viewState.canCreateRoom) XCTAssertFalse(context.viewState.canCreateRoom)
context.roomName = "A" context.roomName = "A"