a11y: Extract method to avoid code duplication
This commit is contained in:
@@ -53,6 +53,7 @@ import io.element.android.features.messages.impl.crypto.sendfailure.VerifiedUser
|
||||
import io.element.android.features.messages.impl.crypto.sendfailure.VerifiedUserSendFailure.ChangedIdentity
|
||||
import io.element.android.features.messages.impl.crypto.sendfailure.VerifiedUserSendFailure.None
|
||||
import io.element.android.features.messages.impl.crypto.sendfailure.VerifiedUserSendFailure.UnsignedDevice
|
||||
import io.element.android.features.messages.impl.timeline.a11y.a11yReactionAction
|
||||
import io.element.android.features.messages.impl.timeline.components.MessageShieldView
|
||||
import io.element.android.features.messages.impl.timeline.model.TimelineItem
|
||||
import io.element.android.features.messages.impl.timeline.model.event.TimelineItemAudioContent
|
||||
@@ -438,11 +439,10 @@ private fun EmojiButton(
|
||||
} else {
|
||||
Color.Transparent
|
||||
}
|
||||
val a11yClickLabel = if (isHighlighted) {
|
||||
stringResource(id = CommonStrings.a11y_remove_reaction_with, emoji)
|
||||
} else {
|
||||
stringResource(id = CommonStrings.a11y_react_with, emoji)
|
||||
}
|
||||
val a11yClickLabel = a11yReactionAction(
|
||||
emoji = emoji,
|
||||
userAlreadyReacted = isHighlighted,
|
||||
)
|
||||
Box(
|
||||
modifier = modifier
|
||||
.size(48.dp)
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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.features.messages.impl.timeline.a11y
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.ReadOnlyComposable
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import io.element.android.libraries.ui.strings.CommonStrings
|
||||
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
fun a11yReactionAction(
|
||||
emoji: String,
|
||||
userAlreadyReacted: Boolean = false,
|
||||
): String {
|
||||
return if (userAlreadyReacted) {
|
||||
stringResource(id = CommonStrings.a11y_remove_reaction_with, emoji)
|
||||
} else {
|
||||
stringResource(id = CommonStrings.a11y_react_with, emoji)
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,7 @@ import androidx.compose.ui.unit.sp
|
||||
import coil3.compose.AsyncImage
|
||||
import io.element.android.compound.theme.ElementTheme
|
||||
import io.element.android.features.messages.impl.R
|
||||
import io.element.android.features.messages.impl.timeline.a11y.a11yReactionAction
|
||||
import io.element.android.features.messages.impl.timeline.model.AggregatedReaction
|
||||
import io.element.android.features.messages.impl.timeline.model.AggregatedReactionProvider
|
||||
import io.element.android.features.messages.impl.timeline.model.aTimelineItemReactions
|
||||
@@ -105,11 +106,10 @@ fun MessagesReactionButton(
|
||||
}
|
||||
|
||||
val a11yClickLabel = if (content is MessagesReactionsButtonContent.Reaction) {
|
||||
if (content.isHighlighted) {
|
||||
stringResource(id = CommonStrings.a11y_remove_reaction_with, content.reaction.key)
|
||||
} else {
|
||||
stringResource(id = CommonStrings.a11y_react_with, content.reaction.key)
|
||||
}
|
||||
a11yReactionAction(
|
||||
emoji = content.reaction.key,
|
||||
userAlreadyReacted = content.isHighlighted
|
||||
)
|
||||
} else {
|
||||
""
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.clearAndSetSemantics
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.unit.TextUnit
|
||||
@@ -30,11 +29,11 @@ import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import io.element.android.compound.theme.ElementTheme
|
||||
import io.element.android.emojibasebindings.Emoji
|
||||
import io.element.android.features.messages.impl.timeline.a11y.a11yReactionAction
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreview
|
||||
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
||||
import io.element.android.libraries.designsystem.text.toDp
|
||||
import io.element.android.libraries.designsystem.theme.components.Text
|
||||
import io.element.android.libraries.ui.strings.CommonStrings
|
||||
|
||||
@Composable
|
||||
fun EmojiItem(
|
||||
@@ -49,11 +48,10 @@ fun EmojiItem(
|
||||
} else {
|
||||
Color.Transparent
|
||||
}
|
||||
val description = if (isSelected) {
|
||||
stringResource(id = CommonStrings.a11y_remove_reaction_with, item.unicode)
|
||||
} else {
|
||||
stringResource(id = CommonStrings.a11y_react_with, item.unicode)
|
||||
}
|
||||
val description = a11yReactionAction(
|
||||
emoji = item.unicode,
|
||||
userAlreadyReacted = isSelected,
|
||||
)
|
||||
Box(
|
||||
modifier = modifier
|
||||
.sizeIn(minWidth = 40.dp, minHeight = 40.dp)
|
||||
|
||||
Reference in New Issue
Block a user