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

View File

@ -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"
}
}

View File

@ -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()

View File

@ -38,7 +38,5 @@ struct CreateRoomViewStateBindings {
enum CreateRoomViewAction {
case createRoom
case selectPrivateRoom
case selectPublicRoom
case deselectUser(UserProfile)
}

View File

@ -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
}
}

View File

@ -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)
context.send(viewAction: .deselectUser(user))
}
.frame(width: cellWidth)
.frame(width: invitedUserCellWidth)
}
}
.padding(.init(top: 16, leading: 32, bottom: 16, trailing: 32))
}
.listRowInsets(.init())
.listRowBackground(Color.clear)
}
.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

View File

@ -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:

View File

@ -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"