Merge pull request #6074 from element-hq/feature/fga/fix_edit_details

Fix RoomDetailsEditView avatar picker for spaces
This commit is contained in:
ganfra 2026-01-23 15:55:37 +01:00 committed by GitHub
commit 5d40c64a3b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 48 additions and 28 deletions

View file

@ -101,9 +101,9 @@ fun RoomDetailsEditView(
.verticalScroll(rememberScrollState()) .verticalScroll(rememberScrollState())
) { ) {
Spacer(modifier = Modifier.height(24.dp)) Spacer(modifier = Modifier.height(24.dp))
val avatarPickerState = remember(state.roomAvatarUrl) { val avatarPickerState = remember(state.roomAvatarUrl, state.roomRawName) {
val size = AvatarSize.EditRoomDetails val size = AvatarSize.EditRoomDetails
val type = AvatarType.Room() val type = if (state.isSpace) AvatarType.Space() else AvatarType.Room()
AvatarPickerState.Selected( AvatarPickerState.Selected(
avatarData = AvatarData(id = state.roomId.value, name = state.roomRawName, size = size, url = state.roomAvatarUrl), avatarData = AvatarData(id = state.roomId.value, name = state.roomRawName, size = size, url = state.roomAvatarUrl),
type = type type = type
@ -112,6 +112,7 @@ fun RoomDetailsEditView(
AvatarPickerView( AvatarPickerView(
state = avatarPickerState, state = avatarPickerState,
onClick = ::onAvatarClick, onClick = ::onAvatarClick,
enabled = state.canChangeAvatar,
modifier = Modifier.align(Alignment.CenterHorizontally), modifier = Modifier.align(Alignment.CenterHorizontally),
) )
Spacer(modifier = Modifier.height(32.dp)) Spacer(modifier = Modifier.height(32.dp))

View file

@ -78,18 +78,19 @@ fun AvatarPickerView(
enabled: Boolean = true, enabled: Boolean = true,
) { ) {
val a11yAvatar = stringResource(CommonStrings.a11y_avatar) val a11yAvatar = stringResource(CommonStrings.a11y_avatar)
val interactionSource = remember { MutableInteractionSource() }
val clickableModifier = Modifier.clickable( val clickableModifier = Modifier
enabled = enabled, .clickable(
interactionSource = remember { MutableInteractionSource() }, enabled = enabled,
onClickLabel = onClickLabel, interactionSource = interactionSource,
onClick = onClick, onClickLabel = onClickLabel,
indication = ripple(bounded = false), onClick = onClick,
) indication = ripple(bounded = false),
.testTag(TestTags.editAvatar) )
.clearAndSetSemantics { .testTag(TestTags.editAvatar)
contentDescription = a11yAvatar .clearAndSetSemantics {
} contentDescription = a11yAvatar
}
val layoutDirection = LocalLayoutDirection.current val layoutDirection = LocalLayoutDirection.current
@ -123,18 +124,30 @@ fun AvatarPickerView(
buttonSize = state.buttonSize, buttonSize = state.buttonSize,
iconSize = state.iconSize, iconSize = state.iconSize,
iconId = state.iconId, iconId = state.iconId,
modifier = modifier.padding(state.externalPadding).then(clickableModifier), modifier = modifier
.padding(state.externalPadding)
.then(clickableModifier),
) )
} }
is AvatarPickerState.Selected -> { is AvatarPickerState.Selected -> {
Box(modifier = modifier) { Box(modifier = modifier) {
val backgroundModifier = if (enabled) {
eraseBackgroundModifier(state.avatarData.size.dp, state.avatarData.size.dp * 0.225f)
} else {
Modifier
}
Avatar( Avatar(
avatarData = state.avatarData, avatarData = state.avatarData,
avatarType = state.type, avatarType = state.type,
modifier = clickableModifier.then(eraseBackgroundModifier(state.avatarData.size.dp, state.avatarData.size.dp * 0.225f)), modifier = clickableModifier.then(backgroundModifier),
) )
if (enabled) {
OverlayEditButton(editButtonSize = state.avatarData.size.dp * 0.44f) OverlayEditButton(
editButtonSize = state.avatarData.size.dp * 0.44f,
onClick = onClick,
interactionSource = interactionSource
)
}
} }
} }
} }
@ -165,12 +178,18 @@ private fun PickButton(
} }
@Composable @Composable
private fun BoxScope.OverlayEditButton(editButtonSize: Dp) { private fun BoxScope.OverlayEditButton(
editButtonSize: Dp,
onClick: () -> Unit,
interactionSource: MutableInteractionSource
) {
Box( Box(
modifier = Modifier.align(Alignment.BottomEnd) modifier = Modifier
.align(Alignment.BottomEnd)
.size(editButtonSize) .size(editButtonSize)
.offset(x = editButtonSize * 0.266f) .offset(x = editButtonSize * 0.266f)
.clip(CircleShape) .clip(CircleShape)
.clickable(interactionSource = interactionSource, onClick = onClick, indication = null)
.background(ElementTheme.colors.bgCanvasDefault) .background(ElementTheme.colors.bgCanvasDefault)
.border(BorderStroke(1.dp, ElementTheme.colors.borderInteractiveSecondary), shape = CircleShape), .border(BorderStroke(1.dp, ElementTheme.colors.borderInteractiveSecondary), shape = CircleShape),
contentAlignment = Alignment.Center, contentAlignment = Alignment.Center,

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:e8c00c06c9da1432f196aafa11e529e393f6b03310fa4d9984bf66d4f7faa058 oid sha256:144ec8da9382f33c7566452515a379eb7fec3e7c1cbd1c6c79a871e12093e6ee
size 44922 size 48043

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:13d339ed6e27f32f7820048acf35008f406f7ad2597cf1487a05b0a7e6b1ab5b oid sha256:fa16dfc8c993212b66a1ac610952bec40ac922bbefae6d69455335e38042aadc
size 28289 size 26291

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:9f9eb9966b578538160a181719f3ea1a22caa0541ccc579f363f9e0f00f5851c oid sha256:53cf288c75a59cb97d2c0d648273e233b0ac9ba41f04b2cc57f7fe24657cf924
size 43811 size 47069

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:0c3abff638ea74e7d2913ce45de920f896b546d705424ea09e10eda4b1ff6072 oid sha256:992d2a4cafdcfcbf9e1b7517855bad1ec6141152b087012fa32c3da413b98921
size 27467 size 25636