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

Use Compound List in more screens. #2099

Merged
merged 6 commits into from
Nov 17, 2023
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
2 changes: 1 addition & 1 deletion ElementX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -6664,7 +6664,7 @@
repositoryURL = "https://github.com/vector-im/compound-ios";
requirement = {
kind = revision;
revision = 7ae8b7ef4033861d0439427d5404538243afeffd;
revision = 59166acc95a775ba3b7e7d39e5605611cf0e657f;
};
};
9A472EE0218FE7DCF5283429 /* XCRemoteSwiftPackageReference "SwiftUI-Introspect" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/vector-im/compound-ios",
"state" : {
"revision" : "7ae8b7ef4033861d0439427d5404538243afeffd"
"revision" : "59166acc95a775ba3b7e7d39e5605611cf0e657f"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion ElementX/Sources/Mocks/RoomProxyMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct RoomProxyMockConfiguration {
var isDirect = Bool.random()
var isSpace = Bool.random()
var isPublic = Bool.random()
var isEncrypted = Bool.random()
var isEncrypted = true
var isTombstoned = Bool.random()
var hasOngoingCall = false
var canonicalAlias: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ struct BugReportScreen: View {
PhotosPicker(selection: $selectedScreenshot,
matching: .screenshots,
photoLibrary: .shared()) {
ListLabel.plain(title: photosPickerTitle)
ListRowLabel.plain(title: photosPickerTitle)
}
})
.accessibilityIdentifier(A11yIdentifiers.bugReportScreen.attachScreenshot)
Expand Down
172 changes: 71 additions & 101 deletions ElementX/Sources/Screens/CreateRoom/View/CreateRoomScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// limitations under the License.
//

import Compound
import SwiftUI

struct CreateRoomScreen: View {
Expand All @@ -31,103 +32,95 @@ struct CreateRoomScreen: View {
topicSection
securitySection
}
.compoundForm()
.compoundList()
.track(screen: .createRoom)
.scrollDismissesKeyboard(.immediately)
.navigationTitle(L10n.screenCreateRoomTitle)
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .confirmationAction) {
createButton
}
}
.toolbar { toolbar }
.readFrame($frame)
.alert(item: $context.alertInfo)
}

private var roomSection: some View {
Section {
HStack(alignment: .center, spacing: 16) {
Button {
focus = nil
context.showAttachmentConfirmationDialog = true
} label: {
if let url = context.viewState.avatarURL {
AsyncImage(url: url) { image in
image
.resizable()
.aspectRatio(contentMode: .fill)
} placeholder: {
ProgressView()
}
.scaledFrame(size: 70)
.clipShape(Circle())
} else {
cameraImage
}
}
.buttonStyle(.plain)
.confirmationDialog("", isPresented: $context.showAttachmentConfirmationDialog) {
Button(L10n.actionTakePhoto) {
context.send(viewAction: .displayCameraPicker)
}
Button(L10n.actionChoosePhoto) {
context.send(viewAction: .displayMediaPicker)
}
if context.viewState.avatarURL != nil {
Button(L10n.actionRemove, role: .destructive) {
context.send(viewAction: .removeImage)
}
}
}
roomAvatarButton

VStack(alignment: .leading, spacing: 8) {
Text(L10n.screenCreateRoomRoomNameLabel.uppercased())
.padding(.leading, FormRow.insets.leading)
.compoundFormSectionHeader()
.padding(.leading, ListRowPadding.horizontal)
.compoundListSectionHeader()

TextField(L10n.screenCreateRoomRoomNameLabel,
text: $context.roomName,
prompt: Text(L10n.commonRoomNamePlaceholder).foregroundColor(.compound.textPlaceholder),
axis: .horizontal)
.focused($focus, equals: .name)
.accessibilityIdentifier(A11yIdentifiers.createRoomScreen.roomName)
.padding(EdgeInsets(top: 10, leading: 16, bottom: 10, trailing: 16))
.background(Color.compound.bgCanvasDefaultLevel1)
.clipShape(RoundedRectangle(cornerRadius: 8))
.padding(.horizontal, ListRowPadding.horizontal)
.padding(.vertical, ListRowPadding.vertical)
.background(.compound.bgCanvasDefaultLevel1, in: RoundedRectangle(cornerRadius: 12))
}
}
.listRowInsets(.init())
.listRowBackground(Color.clear)
}
.compoundFormSection()
}

private var cameraImage: some View {
Image(systemName: "camera")
.font(.system(size: 28, weight: .semibold))
.foregroundColor(.compound.iconSecondary)
.scaledFrame(size: 70)
.background(Color.compound.bgSubtlePrimary)
.clipShape(Circle())
private var roomAvatarButton: some View {
Button {
focus = nil
context.showAttachmentConfirmationDialog = true
} label: {
if let url = context.viewState.avatarURL {
AsyncImage(url: url) { image in
image
.resizable()
.aspectRatio(contentMode: .fill)
} placeholder: {
ProgressView()
}
.scaledFrame(size: 70)
.clipShape(Circle())
} else {
CompoundIcon(asset: Asset.Images.takePhoto, size: .custom(36), relativeTo: .title)
.foregroundColor(.compound.iconSecondary)
.scaledFrame(size: 70, relativeTo: .title)
.background(.compound.bgSubtlePrimary, in: Circle())
}
}
.buttonStyle(.plain)
.confirmationDialog("", isPresented: $context.showAttachmentConfirmationDialog) {
Button(L10n.actionTakePhoto) {
context.send(viewAction: .displayCameraPicker)
}
Button(L10n.actionChoosePhoto) {
context.send(viewAction: .displayMediaPicker)
}
if context.viewState.avatarURL != nil {
Button(L10n.actionRemove, role: .destructive) {
context.send(viewAction: .removeImage)
}
}
}
}

private var topicSection: some View {
Section {
TextField(L10n.screenCreateRoomTopicLabel,
text: $context.roomTopic,
prompt: Text(L10n.commonTopicPlaceholder).foregroundColor(.compound.textPlaceholder),
axis: .vertical)
ListRow(label: .plain(title: L10n.commonTopicPlaceholder),
kind: .textField(text: $context.roomTopic, axis: .vertical))
.lineLimit(3, reservesSpace: false)
.focused($focus, equals: .topic)
.accessibilityIdentifier(A11yIdentifiers.createRoomScreen.roomTopic)
.lineLimit(3, reservesSpace: false)
} header: {
Text(L10n.screenCreateRoomTopicLabel)
.compoundFormSectionHeader()
.compoundListSectionHeader()
} footer: {
if !context.viewState.selectedUsers.isEmpty {
selectedUsersSection
}
}
.compoundFormSection()
}

@State private var frame: CGRect = .zero
Expand All @@ -143,61 +136,38 @@ struct CreateRoomScreen: View {
.frame(width: invitedUserCellWidth)
}
}
.padding(.init(top: 22, leading: 20, bottom: 0, trailing: 32))
.padding(.horizontal, ListRowPadding.horizontal)
.padding(.vertical, 22)
}
.frame(width: frame.width)
}

private var securitySection: some View {
Section {
Picker(L10n.commonSecurity, selection: $context.isRoomPrivate) {
Label {
VStack(alignment: .leading, spacing: 2) {
Text(L10n.screenCreateRoomPrivateOptionTitle)
.font(.compound.bodyLG)
Text(L10n.screenCreateRoomPrivateOptionDescription)
.font(.compound.bodyXS)
.foregroundColor(.compound.textSecondary)
}
} icon: {
Image(systemName: "lock.shield")
}
.tag(true)
.labelStyle(FormRowLabelStyle(alignment: .top))

Label {
VStack(alignment: .leading, spacing: 2) {
Text(L10n.screenCreateRoomPublicOptionTitle)
.font(.compound.bodyLG)
Text(L10n.screenCreateRoomPublicOptionDescription)
.font(.compound.bodyXS)
.foregroundColor(.compound.textSecondary)
}
} icon: {
Image(systemName: "exclamationmark.shield")
}
.tag(false)
.labelStyle(FormRowLabelStyle(alignment: .top))
}
.labelsHidden()
.pickerStyle(.inline)
ListRow(label: .default(title: L10n.screenCreateRoomPrivateOptionTitle,
description: L10n.screenCreateRoomPrivateOptionDescription,
icon: CompoundIcon(asset: Asset.Images.lock),
iconAlignment: .top),
kind: .selection(isSelected: context.isRoomPrivate) { context.isRoomPrivate = true })
ListRow(label: .default(title: L10n.screenCreateRoomPublicOptionTitle,
description: L10n.screenCreateRoomPublicOptionDescription,
icon: \.public,
iconAlignment: .top),
kind: .selection(isSelected: !context.isRoomPrivate) { context.isRoomPrivate = false })
} header: {
Text(L10n.commonSecurity.uppercased())
.compoundFormSectionHeader()
.padding(.top, 40)
.compoundListSectionHeader()
}
.listRowSeparatorTint(.compound.borderDisabled)
.listRowBackground(Color.compound.bgCanvasDefaultLevel1)
}

private var createButton: some View {
Button {
focus = nil
context.send(viewAction: .createRoom)
} label: {
Text(L10n.actionCreate)
private var toolbar: some ToolbarContent {
ToolbarItem(placement: .confirmationAction) {
Button(L10n.actionCreate) {
focus = nil
context.send(viewAction: .createRoom)
}
.disabled(!context.viewState.canCreateRoom)
}
.disabled(!context.viewState.canCreateRoom)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ struct RoomDetailsEditScreen: View {
.focused($focus, equals: .name)
} else {
ListRow(kind: .custom {
ListLabel.plain(title: context.viewState.nameRowTitle)
ListRowLabel.plain(title: context.viewState.nameRowTitle)
.listRowBackground(Color.clear)
})
}
Expand All @@ -111,7 +111,7 @@ struct RoomDetailsEditScreen: View {
.lineLimit(3...)
} else {
ListRow(kind: .custom {
ListLabel.plain(title: context.viewState.topicRowTitle)
ListRowLabel.plain(title: context.viewState.topicRowTitle)
.listRowBackground(Color.clear)
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// limitations under the License.
//

import Compound
import SwiftUI

struct RoomMemberDetailsScreen: View {
Expand All @@ -27,7 +28,7 @@ struct RoomMemberDetailsScreen: View {
blockUserSection
}
}
.compoundForm()
.compoundList()
.alert(item: $context.ignoreUserAlert, actions: blockUserAlertActions, message: blockUserAlertMessage)
.alert(item: $context.alertInfo)
.track(screen: .user)
Expand All @@ -49,7 +50,7 @@ struct RoomMemberDetailsScreen: View {
if let permalink = context.viewState.details.permalink {
HStack(spacing: 32) {
ShareLink(item: permalink) {
Image(systemName: "square.and.arrow.up")
CompoundIcon(asset: Asset.Images.shareIos)
}
.buttonStyle(FormActionButtonStyle(title: L10n.actionShare))
}
Expand All @@ -60,16 +61,16 @@ struct RoomMemberDetailsScreen: View {

private var blockUserSection: some View {
Section {
Button(role: context.viewState.details.isIgnored ? nil : .destructive) {
context.send(viewAction: blockUserButtonAction)
} label: {
Label(blockUserButtonTitle, systemImage: "slash.circle")
}
.accessibilityIdentifier(blockUserButtonAccessibilityIdentifier)
.buttonStyle(FormButtonStyle(accessory: context.viewState.isProcessingIgnoreRequest ? .progressView : nil))
.disabled(context.viewState.isProcessingIgnoreRequest)
ListRow(label: .default(title: blockUserButtonTitle,
icon: CompoundIcon(asset: Asset.Images.block),
role: context.viewState.details.isIgnored ? nil : .destructive),
details: .isWaiting(context.viewState.isProcessingIgnoreRequest),
kind: .button {
context.send(viewAction: blockUserButtonAction)
})
.accessibilityIdentifier(blockUserButtonAccessibilityIdentifier)
.disabled(context.viewState.isProcessingIgnoreRequest)
}
.compoundFormSection()
}

private var blockUserButtonAction: RoomMemberDetailsScreenViewAction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ struct RoomNotificationSettingsCustomSectionView_Previews: PreviewProvider, Test
Form {
RoomNotificationSettingsCustomSectionView(context: viewModel.context)
}
.compoundForm()
.compoundList()
.previewDisplayName("Encrypted")

Form {
RoomNotificationSettingsCustomSectionView(context: viewModelUnencrypted.context)
}
.compoundForm()
.compoundList()
.previewDisplayName("Unencrypted")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct RoomNotificationSettingsUserDefinedScreen: View {

private var deleteButton: some View {
ListRow(label: .action(title: L10n.screenRoomNotificationSettingsEditRemoveSetting,
systemIcon: .trash,
icon: \.delete,
role: .destructive),
details: context.viewState.deletingCustomSetting ? .isWaiting(true) : nil,
kind: .button {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ struct SecureBackupScreen: View {
}
} footer: {
recoveryKeySectionFooter
.compoundFormSectionFooter()
.compoundListSectionFooter()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ struct NotificationSettingsEditScreen: View {
Text(L10n.screenNotificationSettingsEditCustomSettingsSectionTitle)
.compoundListSectionHeader()
}
.compoundFormSection()
}
}

Expand Down
Loading