7
7
8
8
package io.element.android.libraries.matrix.ui.components
9
9
10
- import androidx.compose.foundation.clickable
11
- import androidx.compose.foundation.interaction.MutableInteractionSource
12
- import androidx.compose.foundation.layout.Box
13
- import androidx.compose.foundation.layout.Column
14
- import androidx.compose.foundation.layout.padding
15
- import androidx.compose.foundation.layout.size
16
- import androidx.compose.foundation.layout.width
17
- import androidx.compose.foundation.shape.CircleShape
18
- import androidx.compose.material3.MaterialTheme
19
- import androidx.compose.material3.ripple
20
10
import androidx.compose.runtime.Composable
21
11
import androidx.compose.runtime.CompositionLocalProvider
22
- import androidx.compose.runtime.remember
23
- import androidx.compose.ui.Alignment
24
12
import androidx.compose.ui.Modifier
25
- import androidx.compose.ui.draw.clip
26
- import androidx.compose.ui.draw.drawWithContent
27
- import androidx.compose.ui.geometry.Offset
28
- import androidx.compose.ui.graphics.BlendMode
29
- import androidx.compose.ui.graphics.Color
30
- import androidx.compose.ui.graphics.CompositingStrategy
31
- import androidx.compose.ui.graphics.graphicsLayer
32
13
import androidx.compose.ui.platform.LocalLayoutDirection
33
14
import androidx.compose.ui.res.stringResource
34
- import androidx.compose.ui.semantics.clearAndSetSemantics
35
- import androidx.compose.ui.semantics.contentDescription
36
- import androidx.compose.ui.semantics.onClick
37
- import androidx.compose.ui.text.style.TextOverflow
38
15
import androidx.compose.ui.tooling.preview.PreviewParameter
39
16
import androidx.compose.ui.unit.LayoutDirection
40
- import androidx.compose.ui.unit.dp
41
- import io.element.android.compound.theme.ElementTheme
42
- import io.element.android.compound.tokens.generated.CompoundIcons
43
- import io.element.android.libraries.designsystem.components.avatar.Avatar
44
17
import io.element.android.libraries.designsystem.components.avatar.AvatarSize
45
18
import io.element.android.libraries.designsystem.components.avatar.AvatarType
46
19
import io.element.android.libraries.designsystem.preview.ElementPreview
47
20
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
48
- import io.element.android.libraries.designsystem.text.toPx
49
- import io.element.android.libraries.designsystem.theme.components.Icon
50
- import io.element.android.libraries.designsystem.theme.components.Surface
51
- import io.element.android.libraries.designsystem.theme.components.Text
52
21
import io.element.android.libraries.matrix.ui.model.SelectRoomInfo
53
22
import io.element.android.libraries.matrix.ui.model.getAvatarData
54
23
import io.element.android.libraries.ui.strings.CommonStrings
@@ -60,89 +29,22 @@ fun SelectedRoom(
60
29
onRemoveRoom : (SelectRoomInfo ) -> Unit ,
61
30
modifier : Modifier = Modifier ,
62
31
) {
63
- val actionRemove = stringResource(id = CommonStrings .action_remove)
64
- val a11yRoomName = stringResource(id = CommonStrings .common_room_name)
65
- Box (
66
- modifier = modifier
67
- .width(AvatarSize .SelectedRoom .dp)
68
- .clearAndSetSemantics {
69
- contentDescription = roomInfo.name
70
- ? : roomInfo.canonicalAlias?.value
71
- ? : a11yRoomName
72
- // Note: this does not set the click effect to the whole Box
73
- // when talkback is not enabled
74
- onClick(
75
- label = actionRemove,
76
- action = {
77
- onRemoveRoom(roomInfo)
78
- true
79
- }
80
- )
81
- }
82
- ) {
83
- Column (
84
- horizontalAlignment = Alignment .CenterHorizontally ,
85
- ) {
86
- val isRtl = LocalLayoutDirection .current == LayoutDirection .Rtl
87
- val closeIconRadius = 12 .dp.toPx()
88
- val closeIconOffset = 10 .dp.toPx()
89
- Avatar (
90
- modifier = Modifier
91
- .graphicsLayer {
92
- compositingStrategy = CompositingStrategy .Offscreen
93
- }
94
- .drawWithContent {
95
- drawContent()
96
- val xOffset = if (isRtl) {
97
- closeIconOffset
98
- } else {
99
- size.width - closeIconOffset
100
- }
101
- drawCircle(
102
- color = Color .Black ,
103
- center = Offset (
104
- x = xOffset,
105
- y = closeIconOffset,
106
- ),
107
- radius = closeIconRadius,
108
- blendMode = BlendMode .Clear ,
109
- )
110
- },
111
- avatarData = roomInfo.getAvatarData(AvatarSize .SelectedRoom ),
112
- avatarType = AvatarType .Room (
113
- heroes = roomInfo.heroes.map { it.getAvatarData(AvatarSize .SelectedRoom ) }.toImmutableList(),
114
- isTombstoned = roomInfo.isTombstoned,
115
- ),
116
- )
117
- Text (
118
- // If name is null, we do not have space to render "No room name", so just use `#` here.
119
- text = roomInfo.name ? : " #" ,
120
- overflow = TextOverflow .Ellipsis ,
121
- maxLines = 1 ,
122
- style = MaterialTheme .typography.bodyMedium,
123
- color = ElementTheme .colors.textSecondary,
124
- )
125
- }
126
- Surface (
127
- color = ElementTheme .colors.bgActionPrimaryRest,
128
- modifier = Modifier
129
- .clip(CircleShape )
130
- .size(20 .dp)
131
- .align(Alignment .TopEnd )
132
- .clickable(
133
- indication = ripple(),
134
- interactionSource = remember { MutableInteractionSource () },
135
- onClick = { onRemoveRoom(roomInfo) }
136
- ),
137
- ) {
138
- Icon (
139
- imageVector = CompoundIcons .Close (),
140
- contentDescription = stringResource(id = CommonStrings .action_remove),
141
- tint = ElementTheme .colors.iconOnSolidPrimary,
142
- modifier = Modifier .padding(2 .dp)
143
- )
144
- }
145
- }
32
+ SelectedItem (
33
+ avatarData = roomInfo.getAvatarData(AvatarSize .SelectedRoom ),
34
+ avatarType = AvatarType .Room (
35
+ heroes = roomInfo.heroes.map { it.getAvatarData(AvatarSize .SelectedRoom ) }.toImmutableList(),
36
+ isTombstoned = roomInfo.isTombstoned,
37
+ ),
38
+ // If name is null, we do not have space to render "No room name", so just use `#` here.
39
+ text = roomInfo.name ? : " #" ,
40
+ maxLines = 1 ,
41
+ a11yContentDescription = roomInfo.name
42
+ ? : roomInfo.canonicalAlias?.value
43
+ ? : stringResource(id = CommonStrings .common_room_name),
44
+ canRemove = true ,
45
+ onRemoveClick = { onRemoveRoom(roomInfo) },
46
+ modifier = modifier,
47
+ )
146
48
}
147
49
148
50
@PreviewsDayNight
0 commit comments