-
Notifications
You must be signed in to change notification settings - Fork 265
Space UI component #5197
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
Merged
Merged
Space UI component #5197
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3391cfb
Add UI component EditableOrgAvatar
bmarty d31ada9
Add UI component OrganizationHeader
bmarty 2ee4b4f
Move AvatarRow to designsystem module, because it will be used by spa…
bmarty d9d6161
Add a revered parameter to AvatarRow to be able to stack avatar the o…
bmarty c3bd149
Rename `RoomPreviewMembersCountMolecule` to `MembersCountMolecule`
bmarty bc655c6
Introduce SpaceMembersView.
bmarty f11a32a
Fix test.
bmarty 05fcf66
Fix preview issue.
bmarty 90c7c6c
Update screenshots
ElementBot dc0d810
Use Surface API for border and shape.
bmarty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
...ui/src/main/kotlin/io/element/android/libraries/matrix/ui/components/EditableOrgAvatar.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
/* | ||
* Copyright 2025 New Vector Ltd. | ||
* | ||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial | ||
* Please see LICENSE files in the repository root for full details. | ||
*/ | ||
|
||
package io.element.android.libraries.matrix.ui.components | ||
|
||
import androidx.compose.foundation.border | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.interaction.MutableInteractionSource | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.foundation.shape.CircleShape | ||
import androidx.compose.material3.ripple | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.draw.drawWithContent | ||
import androidx.compose.ui.geometry.Offset | ||
import androidx.compose.ui.graphics.BlendMode | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.CompositingStrategy | ||
import androidx.compose.ui.graphics.graphicsLayer | ||
import androidx.compose.ui.platform.LocalLayoutDirection | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.semantics.clearAndSetSemantics | ||
import androidx.compose.ui.semantics.contentDescription | ||
import androidx.compose.ui.semantics.onClick | ||
import androidx.compose.ui.unit.LayoutDirection | ||
import androidx.compose.ui.unit.dp | ||
import io.element.android.compound.theme.ElementTheme | ||
import io.element.android.compound.tokens.generated.CompoundIcons | ||
import io.element.android.libraries.designsystem.components.avatar.Avatar | ||
import io.element.android.libraries.designsystem.components.avatar.AvatarData | ||
import io.element.android.libraries.designsystem.components.avatar.AvatarSize | ||
import io.element.android.libraries.designsystem.components.avatar.AvatarType | ||
import io.element.android.libraries.designsystem.components.avatar.anAvatarData | ||
import io.element.android.libraries.designsystem.preview.ElementPreview | ||
import io.element.android.libraries.designsystem.preview.PreviewsDayNight | ||
import io.element.android.libraries.designsystem.text.toPx | ||
import io.element.android.libraries.designsystem.theme.components.Icon | ||
import io.element.android.libraries.designsystem.theme.components.Surface | ||
import io.element.android.libraries.ui.strings.CommonStrings | ||
|
||
/** | ||
* Ref: https://www.figma.com/design/G1xy0HDZKJf5TCRFmKb5d5/Compound-Android-Components?node-id=3643-2678&m=dev | ||
*/ | ||
@Composable | ||
fun EditableOrgAvatar( | ||
avatarData: AvatarData, | ||
onEdit: () -> Unit, | ||
modifier: Modifier = Modifier, | ||
) { | ||
val actionEdit = stringResource(id = CommonStrings.action_edit) | ||
val description = stringResource(CommonStrings.a11y_avatar) | ||
Box( | ||
modifier = modifier | ||
.width(avatarData.size.dp + 16.dp) | ||
.clearAndSetSemantics { | ||
contentDescription = description | ||
// Note: this does not set the click effect to the whole Box | ||
// when talkback is not enabled | ||
onClick( | ||
label = actionEdit, | ||
action = { | ||
onEdit() | ||
true | ||
} | ||
) | ||
} | ||
) { | ||
val isRtl = LocalLayoutDirection.current == LayoutDirection.Rtl | ||
val editIconRadius = 17.dp.toPx() | ||
val editIconXOffset = 7.dp.toPx() | ||
val editIconYOffset = 15.dp.toPx() | ||
Avatar( | ||
avatarData = avatarData, | ||
avatarType = AvatarType.Space(false), | ||
modifier = Modifier | ||
.align(Alignment.Center) | ||
.graphicsLayer { | ||
compositingStrategy = CompositingStrategy.Offscreen | ||
} | ||
.drawWithContent { | ||
drawContent() | ||
val xOffset = if (isRtl) { | ||
editIconXOffset | ||
} else { | ||
size.width - editIconXOffset | ||
} | ||
drawCircle( | ||
color = Color.Black, | ||
center = Offset( | ||
x = xOffset, | ||
y = size.height - editIconYOffset, | ||
), | ||
radius = editIconRadius, | ||
blendMode = BlendMode.Clear, | ||
) | ||
}, | ||
) | ||
Surface( | ||
color = ElementTheme.colors.bgCanvasDefault, | ||
modifier = Modifier | ||
.clip(CircleShape) | ||
.size(30.dp) | ||
.border(1.dp, color = ElementTheme.colors.borderInteractiveSecondary, shape = CircleShape) | ||
.align(Alignment.BottomEnd) | ||
.clickable( | ||
indication = ripple(), | ||
interactionSource = remember { MutableInteractionSource() }, | ||
onClick = onEdit, | ||
), | ||
) { | ||
Icon( | ||
imageVector = CompoundIcons.Edit(), | ||
// Note: keep the context description for the test | ||
contentDescription = stringResource(id = CommonStrings.action_edit), | ||
tint = ElementTheme.colors.iconPrimary, | ||
modifier = Modifier.padding(6.dp) | ||
) | ||
} | ||
} | ||
} | ||
|
||
@PreviewsDayNight | ||
@Composable | ||
internal fun EditableOrgAvatarPreview() = ElementPreview { | ||
EditableOrgAvatar( | ||
avatarData = anAvatarData( | ||
url = "anUrl", | ||
size = AvatarSize.OrganizationHeader, | ||
), | ||
onEdit = {}, | ||
) | ||
} | ||
|
||
@PreviewsDayNight | ||
@Composable | ||
internal fun EditableOrgAvatarRtlPreview() = CompositionLocalProvider( | ||
LocalLayoutDirection provides LayoutDirection.Rtl, | ||
) { | ||
ElementPreview { | ||
EditableOrgAvatar( | ||
avatarData = anAvatarData( | ||
url = "anUrl", | ||
size = AvatarSize.OrganizationHeader, | ||
), | ||
onEdit = {}, | ||
) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't
Surface
already haveshape
andborderStroke
parameters?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot about it. dc0d810