Add support for homeserver capabilities to disable the UserDetailsEditScreen UI. (#5421)

Add support for homeserver capabilities to disable editing your user profile.

Also updates editable avatar size/formatting to match the latest Figma at the same time.
This commit is contained in:
Doug
2026-04-17 11:52:46 +01:00
committed by GitHub
parent c40454bbd3
commit eef4a2497a
46 changed files with 482 additions and 142 deletions
@@ -67,14 +67,12 @@ struct UserDetailsEditScreen: View {
shape: .circle,
avatarSize: .user(on: .editUserDetails),
mediaProvider: context.mediaProvider)
.overlay(alignment: .bottomTrailing) {
avatarOverlayIcon
}
.confirmationDialog("", isPresented: $context.showMediaSheet) {
mediaActionSheet
}
}
.buttonStyle(.plain)
.buttonStyle(EditAvatarButtonStyle())
.disabled(!context.viewState.canEditAvatar)
.frame(maxWidth: .infinity, alignment: .center)
.listRowBackground(Color.clear)
}
@@ -84,22 +82,13 @@ struct UserDetailsEditScreen: View {
ListRow(label: .plain(title: L10n.screenEditProfileDisplayNamePlaceholder),
kind: .textField(text: $context.name, axis: .horizontal))
.focused($focus)
.disabled(!context.viewState.canEditDisplayName)
} header: {
Text(L10n.screenEditProfileDisplayName)
.compoundListSectionHeader()
}
}
private var avatarOverlayIcon: some View {
CompoundIcon(\.editSolid, size: .xSmall, relativeTo: .compound.bodyLG)
.foregroundColor(.white)
.padding(4)
.background {
Circle()
.foregroundColor(.black)
}
}
@ViewBuilder
private var mediaActionSheet: some View {
Button {
@@ -126,13 +115,26 @@ struct UserDetailsEditScreen: View {
// MARK: - Previews
struct UserDetailsEditScreen_Previews: PreviewProvider, TestablePreview {
static let viewModel = UserDetailsEditScreenViewModel(userSession: UserSessionMock(.init(clientProxy: ClientProxyMock(.init(userID: "@stefan:matrix.org")))),
mediaUploadingPreprocessor: .init(appSettings: ServiceLocator.shared.settings),
userIndicatorController: UserIndicatorControllerMock.default)
static let viewModel = makeViewModel()
static let readOnlyViewModel = makeViewModel(canChangeProfile: false)
static var previews: some View {
ElementNavigationStack {
UserDetailsEditScreen(context: viewModel.context)
}
.previewDisplayName("Default")
ElementNavigationStack {
UserDetailsEditScreen(context: readOnlyViewModel.context)
}
.previewDisplayName("Read Only")
}
static func makeViewModel(canChangeProfile: Bool = true) -> UserDetailsEditScreenViewModel {
UserDetailsEditScreenViewModel(userSession: UserSessionMock(.init(clientProxy: ClientProxyMock(.init(userID: "@stefan:matrix.org",
canChangeAvatar: canChangeProfile,
canChangeDisplayName: canChangeProfile)))),
mediaUploadingPreprocessor: .init(appSettings: ServiceLocator.shared.settings),
userIndicatorController: UserIndicatorControllerMock.default)
}
}