@@ -28,6 +28,7 @@ import androidx.compose.foundation.layout.size
28
28
import androidx.compose.foundation.layout.width
29
29
import androidx.compose.runtime.Composable
30
30
import androidx.compose.runtime.LaunchedEffect
31
+ import androidx.compose.runtime.ReadOnlyComposable
31
32
import androidx.compose.runtime.getValue
32
33
import androidx.compose.runtime.mutableStateOf
33
34
import androidx.compose.runtime.remember
@@ -39,7 +40,11 @@ import androidx.compose.ui.Modifier
39
40
import androidx.compose.ui.draw.clip
40
41
import androidx.compose.ui.platform.LocalView
41
42
import androidx.compose.ui.res.stringResource
43
+ import androidx.compose.ui.semantics.SemanticsPropertyReceiver
44
+ import androidx.compose.ui.semantics.clearAndSetSemantics
45
+ import androidx.compose.ui.semantics.contentDescription
42
46
import androidx.compose.ui.semantics.hideFromAccessibility
47
+ import androidx.compose.ui.semantics.onClick
43
48
import androidx.compose.ui.semantics.semantics
44
49
import androidx.compose.ui.tooling.preview.Preview
45
50
import androidx.compose.ui.tooling.preview.PreviewParameter
@@ -280,6 +285,13 @@ fun TextComposer(
280
285
else -> sendButton
281
286
}
282
287
288
+ val endButtonA11y = endButtonA11y(
289
+ composerMode = composerMode,
290
+ voiceMessageState = voiceMessageState,
291
+ enableVoiceMessages = enableVoiceMessages,
292
+ canSendMessage = canSendMessage,
293
+ )
294
+
283
295
val voiceRecording = @Composable {
284
296
when (voiceMessageState) {
285
297
is VoiceMessageState .Preview ->
@@ -323,6 +335,7 @@ fun TextComposer(
323
335
)
324
336
},
325
337
textFormatting = textFormattingOptions,
338
+ endButtonA11y = endButtonA11y,
326
339
sendButton = sendButton,
327
340
)
328
341
} else {
@@ -334,6 +347,7 @@ fun TextComposer(
334
347
composerOptionsButton = composerOptionsButton,
335
348
textInput = textInput,
336
349
endButton = sendOrRecordButton,
350
+ endButtonA11y = endButtonA11y,
337
351
voiceRecording = voiceRecording,
338
352
voiceDeleteButton = voiceDeleteButton,
339
353
)
@@ -359,6 +373,40 @@ fun TextComposer(
359
373
}
360
374
}
361
375
376
+ @ReadOnlyComposable
377
+ @Composable
378
+ private fun endButtonA11y (
379
+ composerMode : MessageComposerMode ,
380
+ voiceMessageState : VoiceMessageState ,
381
+ enableVoiceMessages : Boolean ,
382
+ canSendMessage : Boolean ,
383
+ ): (SemanticsPropertyReceiver ) -> Unit {
384
+ val a11ySendButtonDescription = stringResource(
385
+ id = when {
386
+ enableVoiceMessages && ! canSendMessage ->
387
+ when (voiceMessageState) {
388
+ VoiceMessageState .Idle ,
389
+ is VoiceMessageState .Recording -> if (voiceMessageState is VoiceMessageState .Recording ) {
390
+ CommonStrings .a11y_voice_message_stop_recording
391
+ } else {
392
+ CommonStrings .a11y_voice_message_record
393
+ }
394
+ is VoiceMessageState .Preview -> when (voiceMessageState.isSending) {
395
+ true -> CommonStrings .common_sending
396
+ false -> CommonStrings .action_send_voice_message
397
+ }
398
+ }
399
+ composerMode.isEditing -> CommonStrings .action_send_edited_message
400
+ else -> CommonStrings .action_send_message
401
+ }
402
+ )
403
+ val endButtonA11y: (SemanticsPropertyReceiver .() -> Unit ) = {
404
+ contentDescription = a11ySendButtonDescription
405
+ onClick(null , null )
406
+ }
407
+ return endButtonA11y
408
+ }
409
+
362
410
@Composable
363
411
private fun StandardLayout (
364
412
voiceMessageState : VoiceMessageState ,
@@ -369,6 +417,7 @@ private fun StandardLayout(
369
417
voiceRecording : @Composable () -> Unit ,
370
418
voiceDeleteButton : @Composable () -> Unit ,
371
419
endButton : @Composable () -> Unit ,
420
+ endButtonA11y : (SemanticsPropertyReceiver .() -> Unit ),
372
421
modifier : Modifier = Modifier ,
373
422
) {
374
423
Column (modifier = modifier) {
@@ -416,7 +465,8 @@ private fun StandardLayout(
416
465
Box (
417
466
Modifier
418
467
.padding(bottom = 5 .dp, top = 5 .dp, end = 6 .dp, start = 6 .dp)
419
- .size(48 .dp),
468
+ .size(48 .dp)
469
+ .clearAndSetSemantics(endButtonA11y),
420
470
contentAlignment = Alignment .Center ,
421
471
) {
422
472
endButton()
@@ -454,6 +504,7 @@ private fun TextFormattingLayout(
454
504
dismissTextFormattingButton : @Composable () -> Unit ,
455
505
textFormatting : @Composable () -> Unit ,
456
506
sendButton : @Composable () -> Unit ,
507
+ endButtonA11y : (SemanticsPropertyReceiver .() -> Unit ),
457
508
modifier : Modifier = Modifier
458
509
) {
459
510
Column (
@@ -485,10 +536,12 @@ private fun TextFormattingLayout(
485
536
textFormatting()
486
537
}
487
538
Box (
488
- modifier = Modifier .padding(
489
- start = 14 .dp,
490
- end = 6 .dp
491
- )
539
+ modifier = Modifier
540
+ .padding(
541
+ start = 14 .dp,
542
+ end = 6 .dp,
543
+ )
544
+ .clearAndSetSemantics(endButtonA11y)
492
545
) {
493
546
sendButton()
494
547
}
0 commit comments