@@ -15,19 +15,29 @@ import androidx.compose.foundation.layout.padding
15
15
import androidx.compose.foundation.layout.size
16
16
import androidx.compose.foundation.layout.width
17
17
import androidx.compose.foundation.shape.CircleShape
18
+ import androidx.compose.material3.MaterialTheme
18
19
import androidx.compose.material3.ripple
19
20
import androidx.compose.runtime.Composable
21
+ import androidx.compose.runtime.CompositionLocalProvider
20
22
import androidx.compose.runtime.remember
21
23
import androidx.compose.ui.Alignment
22
24
import androidx.compose.ui.Modifier
23
25
import androidx.compose.ui.draw.clip
24
26
import androidx.compose.ui.draw.clipToBounds
27
+ import androidx.compose.ui.draw.drawWithContent
28
+ import androidx.compose.ui.geometry.Offset
29
+ import androidx.compose.ui.graphics.BlendMode
30
+ import androidx.compose.ui.graphics.Color
31
+ import androidx.compose.ui.graphics.CompositingStrategy
32
+ import androidx.compose.ui.graphics.graphicsLayer
33
+ import androidx.compose.ui.platform.LocalLayoutDirection
25
34
import androidx.compose.ui.res.stringResource
26
35
import androidx.compose.ui.semantics.clearAndSetSemantics
27
36
import androidx.compose.ui.semantics.contentDescription
28
37
import androidx.compose.ui.semantics.onClick
29
38
import androidx.compose.ui.text.style.TextAlign
30
39
import androidx.compose.ui.text.style.TextOverflow
40
+ import androidx.compose.ui.unit.LayoutDirection
31
41
import androidx.compose.ui.unit.dp
32
42
import io.element.android.compound.theme.ElementTheme
33
43
import io.element.android.compound.tokens.generated.CompoundIcons
@@ -36,6 +46,7 @@ import io.element.android.libraries.designsystem.components.avatar.AvatarSize
36
46
import io.element.android.libraries.designsystem.components.avatar.AvatarType
37
47
import io.element.android.libraries.designsystem.preview.ElementPreview
38
48
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
49
+ import io.element.android.libraries.designsystem.text.toPx
39
50
import io.element.android.libraries.designsystem.theme.components.Icon
40
51
import io.element.android.libraries.designsystem.theme.components.Surface
41
52
import io.element.android.libraries.designsystem.theme.components.Text
@@ -73,22 +84,49 @@ fun SelectedUser(
73
84
Column (
74
85
horizontalAlignment = Alignment .CenterHorizontally ,
75
86
) {
87
+ val isRtl = LocalLayoutDirection .current == LayoutDirection .Rtl
88
+ val closeRadius = 12 .dp.toPx()
89
+ val closeOffset = 10 .dp.toPx()
76
90
Avatar (
77
91
avatarData = matrixUser.getAvatarData(size = AvatarSize .SelectedUser ),
78
92
avatarType = AvatarType .User ,
93
+ modifier = Modifier
94
+ .graphicsLayer {
95
+ compositingStrategy = CompositingStrategy .Offscreen
96
+ }
97
+ .drawWithContent {
98
+ drawContent()
99
+ if (canRemove) {
100
+ val xOffset = if (isRtl) {
101
+ closeOffset
102
+ } else {
103
+ size.width - closeOffset
104
+ }
105
+ drawCircle(
106
+ color = Color .Black ,
107
+ center = Offset (
108
+ x = xOffset,
109
+ y = closeOffset,
110
+ ),
111
+ radius = closeRadius,
112
+ blendMode = BlendMode .Clear ,
113
+ )
114
+ }
115
+ }
79
116
)
80
117
Text (
81
118
modifier = Modifier .clipToBounds(),
82
119
text = matrixUser.getBestName(),
83
120
overflow = TextOverflow .Ellipsis ,
84
121
maxLines = 2 ,
85
- style = ElementTheme .typography.fontBodyMdRegular,
122
+ style = MaterialTheme .typography.bodyMedium,
123
+ color = ElementTheme .colors.textSecondary,
86
124
textAlign = TextAlign .Center ,
87
125
)
88
126
}
89
127
if (canRemove) {
90
128
Surface (
91
- color = ElementTheme .colors.textPrimary ,
129
+ color = ElementTheme .colors.bgActionPrimaryRest ,
92
130
modifier = Modifier
93
131
.clip(CircleShape )
94
132
.size(20 .dp)
@@ -121,6 +159,20 @@ internal fun SelectedUserPreview() = ElementPreview {
121
159
)
122
160
}
123
161
162
+ @PreviewsDayNight
163
+ @Composable
164
+ internal fun SelectedUserRtlPreview () = CompositionLocalProvider (
165
+ LocalLayoutDirection provides LayoutDirection .Rtl ,
166
+ ) {
167
+ ElementPreview {
168
+ SelectedUser (
169
+ aMatrixUser(displayName = " John Doe" ),
170
+ canRemove = true ,
171
+ onUserRemove = {},
172
+ )
173
+ }
174
+ }
175
+
124
176
@PreviewsDayNight
125
177
@Composable
126
178
internal fun SelectedUserCannotRemovePreview () = ElementPreview {
0 commit comments