From 44062adb0fc2ad6494913a9360073c4d274ab196 Mon Sep 17 00:00:00 2001 From: Doug <6060466+pixlwave@users.noreply.github.com> Date: Fri, 2 Jun 2023 11:39:03 +0100 Subject: [PATCH] Backport base Form style from Compound. (#1009) Apply to all screens using the formBackground colour. --- .../SwiftUI/Form Styles/FormSection.swift | 37 +++++++------------ .../CreateRoom/View/CreateRoomScreen.swift | 3 +- .../View/DeveloperOptionsScreen.swift | 3 +- .../View/InviteUsersScreen.swift | 3 +- .../View/RoomDetailsEditScreen.swift | 3 +- .../View/RoomDetailsScreen.swift | 3 +- .../View/RoomMemberDetailsScreen.swift | 3 +- .../View/StartChatScreen.swift | 3 +- 8 files changed, 21 insertions(+), 37 deletions(-) diff --git a/ElementX/Sources/Other/SwiftUI/Form Styles/FormSection.swift b/ElementX/Sources/Other/SwiftUI/Form Styles/FormSection.swift index 6ade45401..643d4c465 100644 --- a/ElementX/Sources/Other/SwiftUI/Form Styles/FormSection.swift +++ b/ElementX/Sources/Other/SwiftUI/Form Styles/FormSection.swift @@ -16,32 +16,23 @@ import SwiftUI -/// Style for form section headers -struct FormSectionHeaderStyle: ViewModifier { - func body(content: Content) -> some View { - content - .foregroundColor(.element.secondaryContent) +extension View { + /// Applies a standard style to forms. + func elementFormStyle() -> some View { + scrollContentBackground(.hidden) + .background(Color.element.formBackground.ignoresSafeArea()) + } + + /// Applies a standard style for form header text. + func formSectionHeader() -> some View { + foregroundColor(.element.secondaryContent) .font(.compound.bodyXS) } -} - -/// Standard style for form sections -struct FormSectionStyle: ViewModifier { - func body(content: Content) -> some View { - content - .listRowSeparator(.hidden) + + /// Applies a standard style for form sections. + func formSectionStyle() -> some View { + listRowSeparator(.hidden) .listRowInsets(FormRow.insets) .listRowBackground(Color.element.formRowBackground) } } - -extension View { - /// Applies the `FormSectionHeaderStyle` modifier to the view - func formSectionHeader() -> some View { - modifier(FormSectionHeaderStyle()) - } - - func formSectionStyle() -> some View { - modifier(FormSectionStyle()) - } -} diff --git a/ElementX/Sources/Screens/CreateRoom/View/CreateRoomScreen.swift b/ElementX/Sources/Screens/CreateRoom/View/CreateRoomScreen.swift index e6484bbd7..bcc6cbf66 100644 --- a/ElementX/Sources/Screens/CreateRoom/View/CreateRoomScreen.swift +++ b/ElementX/Sources/Screens/CreateRoom/View/CreateRoomScreen.swift @@ -28,8 +28,7 @@ struct CreateRoomScreen: View { var body: some View { mainContent .scrollDismissesKeyboard(.immediately) - .scrollContentBackground(.hidden) - .background(Color.element.formBackground.ignoresSafeArea()) + .elementFormStyle() .navigationTitle(L10n.screenCreateRoomTitle) .navigationBarTitleDisplayMode(.inline) .toolbar { diff --git a/ElementX/Sources/Screens/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift b/ElementX/Sources/Screens/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift index 21b63dd08..7a1c2f97d 100644 --- a/ElementX/Sources/Screens/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift +++ b/ElementX/Sources/Screens/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift @@ -85,8 +85,7 @@ struct DeveloperOptionsScreen: View { } } .overlay(effectsView) - .scrollContentBackground(.hidden) - .background(Color.element.formBackground.ignoresSafeArea()) + .elementFormStyle() .navigationTitle(L10n.commonDeveloperOptions) .navigationBarTitleDisplayMode(.inline) } diff --git a/ElementX/Sources/Screens/InviteUsersScreen/View/InviteUsersScreen.swift b/ElementX/Sources/Screens/InviteUsersScreen/View/InviteUsersScreen.swift index b82486065..4cc85697d 100644 --- a/ElementX/Sources/Screens/InviteUsersScreen/View/InviteUsersScreen.swift +++ b/ElementX/Sources/Screens/InviteUsersScreen/View/InviteUsersScreen.swift @@ -22,8 +22,7 @@ struct InviteUsersScreen: View { var body: some View { mainContent - .scrollContentBackground(.hidden) - .background(Color.element.formBackground.ignoresSafeArea()) + .elementFormStyle() .navigationTitle(L10n.screenCreateRoomActionInvitePeople) .navigationBarTitleDisplayMode(.inline) .toolbar { diff --git a/ElementX/Sources/Screens/RoomDetailsEditScreen/View/RoomDetailsEditScreen.swift b/ElementX/Sources/Screens/RoomDetailsEditScreen/View/RoomDetailsEditScreen.swift index adbc3e17f..4adab292b 100644 --- a/ElementX/Sources/Screens/RoomDetailsEditScreen/View/RoomDetailsEditScreen.swift +++ b/ElementX/Sources/Screens/RoomDetailsEditScreen/View/RoomDetailsEditScreen.swift @@ -27,8 +27,7 @@ struct RoomDetailsEditScreen: View { var body: some View { mainContent - .scrollContentBackground(.hidden) - .background(Color.element.formBackground.ignoresSafeArea()) + .elementFormStyle() .scrollDismissesKeyboard(.immediately) .navigationTitle(L10n.screenRoomDetailsEditRoomTitle) .navigationBarTitleDisplayMode(.inline) diff --git a/ElementX/Sources/Screens/RoomDetailsScreen/View/RoomDetailsScreen.swift b/ElementX/Sources/Screens/RoomDetailsScreen/View/RoomDetailsScreen.swift index d4b2218ba..97e946bcb 100644 --- a/ElementX/Sources/Screens/RoomDetailsScreen/View/RoomDetailsScreen.swift +++ b/ElementX/Sources/Screens/RoomDetailsScreen/View/RoomDetailsScreen.swift @@ -41,8 +41,7 @@ struct RoomDetailsScreen: View { leaveRoomSection } } - .scrollContentBackground(.hidden) - .background(Color.element.formBackground.ignoresSafeArea()) + .elementFormStyle() .alert(item: $context.alertInfo) { $0.alert } .alert(item: $context.leaveRoomAlertItem, actions: leaveRoomAlertActions, diff --git a/ElementX/Sources/Screens/RoomMemberDetailsScreen/View/RoomMemberDetailsScreen.swift b/ElementX/Sources/Screens/RoomMemberDetailsScreen/View/RoomMemberDetailsScreen.swift index 063b38409..4a3f46c2d 100644 --- a/ElementX/Sources/Screens/RoomMemberDetailsScreen/View/RoomMemberDetailsScreen.swift +++ b/ElementX/Sources/Screens/RoomMemberDetailsScreen/View/RoomMemberDetailsScreen.swift @@ -27,8 +27,7 @@ struct RoomMemberDetailsScreen: View { blockUserSection } } - .scrollContentBackground(.hidden) - .background(Color.element.formBackground.ignoresSafeArea()) + .elementFormStyle() .alert(item: $context.ignoreUserAlert, actions: blockUserAlertActions, message: blockUserAlertMessage) .errorAlert(item: $context.errorAlert) } diff --git a/ElementX/Sources/Screens/StartChatScreen/View/StartChatScreen.swift b/ElementX/Sources/Screens/StartChatScreen/View/StartChatScreen.swift index 1bfb844b8..95b5e5cb7 100644 --- a/ElementX/Sources/Screens/StartChatScreen/View/StartChatScreen.swift +++ b/ElementX/Sources/Screens/StartChatScreen/View/StartChatScreen.swift @@ -28,8 +28,7 @@ struct StartChatScreen: View { searchContent } } - .scrollContentBackground(.hidden) - .background(Color.element.formBackground.ignoresSafeArea()) + .elementFormStyle() .navigationTitle(L10n.actionStartChat) .navigationBarTitleDisplayMode(.inline) .toolbar {