Skip to content

Commit 74081f3

Browse files
committed
a11y: Extract method to avoid code duplication
1 parent 3bf51ba commit 74081f3

File tree

4 files changed

+41
-17
lines changed

4 files changed

+41
-17
lines changed

features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/ActionListView.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import io.element.android.features.messages.impl.crypto.sendfailure.VerifiedUser
5353
import io.element.android.features.messages.impl.crypto.sendfailure.VerifiedUserSendFailure.ChangedIdentity
5454
import io.element.android.features.messages.impl.crypto.sendfailure.VerifiedUserSendFailure.None
5555
import io.element.android.features.messages.impl.crypto.sendfailure.VerifiedUserSendFailure.UnsignedDevice
56+
import io.element.android.features.messages.impl.timeline.a11y.a11yReactionAction
5657
import io.element.android.features.messages.impl.timeline.components.MessageShieldView
5758
import io.element.android.features.messages.impl.timeline.model.TimelineItem
5859
import io.element.android.features.messages.impl.timeline.model.event.TimelineItemAudioContent
@@ -438,11 +439,10 @@ private fun EmojiButton(
438439
} else {
439440
Color.Transparent
440441
}
441-
val a11yClickLabel = if (isHighlighted) {
442-
stringResource(id = CommonStrings.a11y_remove_reaction_with, emoji)
443-
} else {
444-
stringResource(id = CommonStrings.a11y_react_with, emoji)
445-
}
442+
val a11yClickLabel = a11yReactionAction(
443+
emoji = emoji,
444+
userAlreadyReacted = isHighlighted,
445+
)
446446
Box(
447447
modifier = modifier
448448
.size(48.dp)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2025 New Vector Ltd.
3+
*
4+
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
5+
* Please see LICENSE files in the repository root for full details.
6+
*/
7+
8+
package io.element.android.features.messages.impl.timeline.a11y
9+
10+
import androidx.compose.runtime.Composable
11+
import androidx.compose.runtime.ReadOnlyComposable
12+
import androidx.compose.ui.res.stringResource
13+
import io.element.android.libraries.ui.strings.CommonStrings
14+
15+
@Composable
16+
@ReadOnlyComposable
17+
fun a11yReactionAction(
18+
emoji: String,
19+
userAlreadyReacted: Boolean = false,
20+
): String {
21+
return if (userAlreadyReacted) {
22+
stringResource(id = CommonStrings.a11y_remove_reaction_with, emoji)
23+
} else {
24+
stringResource(id = CommonStrings.a11y_react_with, emoji)
25+
}
26+
}

features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/MessagesReactionButton.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import androidx.compose.ui.unit.sp
3939
import coil3.compose.AsyncImage
4040
import io.element.android.compound.theme.ElementTheme
4141
import io.element.android.features.messages.impl.R
42+
import io.element.android.features.messages.impl.timeline.a11y.a11yReactionAction
4243
import io.element.android.features.messages.impl.timeline.model.AggregatedReaction
4344
import io.element.android.features.messages.impl.timeline.model.AggregatedReactionProvider
4445
import io.element.android.features.messages.impl.timeline.model.aTimelineItemReactions
@@ -105,11 +106,10 @@ fun MessagesReactionButton(
105106
}
106107

107108
val a11yClickLabel = if (content is MessagesReactionsButtonContent.Reaction) {
108-
if (content.isHighlighted) {
109-
stringResource(id = CommonStrings.a11y_remove_reaction_with, content.reaction.key)
110-
} else {
111-
stringResource(id = CommonStrings.a11y_react_with, content.reaction.key)
112-
}
109+
a11yReactionAction(
110+
emoji = content.reaction.key,
111+
userAlreadyReacted = content.isHighlighted
112+
)
113113
} else {
114114
""
115115
}

features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/customreaction/EmojiItem.kt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,18 @@ import androidx.compose.runtime.remember
2222
import androidx.compose.ui.Alignment
2323
import androidx.compose.ui.Modifier
2424
import androidx.compose.ui.graphics.Color
25-
import androidx.compose.ui.res.stringResource
2625
import androidx.compose.ui.semantics.clearAndSetSemantics
2726
import androidx.compose.ui.semantics.contentDescription
2827
import androidx.compose.ui.unit.TextUnit
2928
import androidx.compose.ui.unit.dp
3029
import androidx.compose.ui.unit.sp
3130
import io.element.android.compound.theme.ElementTheme
3231
import io.element.android.emojibasebindings.Emoji
32+
import io.element.android.features.messages.impl.timeline.a11y.a11yReactionAction
3333
import io.element.android.libraries.designsystem.preview.ElementPreview
3434
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
3535
import io.element.android.libraries.designsystem.text.toDp
3636
import io.element.android.libraries.designsystem.theme.components.Text
37-
import io.element.android.libraries.ui.strings.CommonStrings
3837

3938
@Composable
4039
fun EmojiItem(
@@ -49,11 +48,10 @@ fun EmojiItem(
4948
} else {
5049
Color.Transparent
5150
}
52-
val description = if (isSelected) {
53-
stringResource(id = CommonStrings.a11y_remove_reaction_with, item.unicode)
54-
} else {
55-
stringResource(id = CommonStrings.a11y_react_with, item.unicode)
56-
}
51+
val description = a11yReactionAction(
52+
emoji = item.unicode,
53+
userAlreadyReacted = isSelected,
54+
)
5755
Box(
5856
modifier = modifier
5957
.sizeIn(minWidth = 40.dp, minHeight = 40.dp)

0 commit comments

Comments
 (0)