Skip to content

Commit 95a2152

Browse files
authored
Fix long press on voice message with screen reader (#1704)
As a workaround, disable seeking within the waveform so that it does not interfere with the long press menu. Seeking behaviour is already suboptimal given that there is no spoken feedback about the current seek position. No core functionality is lost as voice messages can be played using a screen reader.
1 parent 5757789 commit 95a2152

File tree

2 files changed

+43
-0
lines changed
  • features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/event
  • libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/accessibility

2 files changed

+43
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import androidx.compose.material3.IconButtonDefaults
2929
import androidx.compose.runtime.Composable
3030
import androidx.compose.ui.Alignment
3131
import androidx.compose.ui.Modifier
32+
import androidx.compose.ui.platform.LocalContext
3233
import androidx.compose.ui.res.stringResource
3334
import androidx.compose.ui.semantics.contentDescription
3435
import androidx.compose.ui.semantics.semantics
@@ -42,6 +43,7 @@ import io.element.android.features.messages.impl.timeline.model.event.TimelineIt
4243
import io.element.android.features.messages.impl.voicemessages.timeline.VoiceMessageEvents
4344
import io.element.android.features.messages.impl.voicemessages.timeline.VoiceMessageState
4445
import io.element.android.features.messages.impl.voicemessages.timeline.VoiceMessageStateProvider
46+
import io.element.android.libraries.androidutils.accessibility.isScreenReaderEnabled
4547
import io.element.android.libraries.designsystem.components.media.WaveformPlaybackView
4648
import io.element.android.libraries.designsystem.preview.ElementPreview
4749
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
@@ -86,13 +88,15 @@ fun TimelineItemVoiceView(
8688
overflow = TextOverflow.Ellipsis,
8789
)
8890
Spacer(Modifier.width(8.dp))
91+
val context = LocalContext.current
8992
WaveformPlaybackView(
9093
showCursor = state.button == VoiceMessageState.Button.Pause,
9194
playbackProgress = state.progress,
9295
waveform = content.waveform,
9396
modifier = Modifier
9497
.height(34.dp)
9598
.weight(1f),
99+
seekEnabled = !context.isScreenReaderEnabled(),
96100
onSeek = { state.eventSink(VoiceMessageEvents.Seek(it)) },
97101
)
98102
Spacer(Modifier.width(extraPadding.getDpSize()))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2023 New Vector Ltd
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.element.android.libraries.androidutils.accessibility
18+
19+
import android.content.Context
20+
import android.view.accessibility.AccessibilityManager
21+
import androidx.core.content.getSystemService
22+
23+
/**
24+
* Whether a screen reader is enabled.
25+
*
26+
* Avoid changing UI or app behavior based on the state of accessibility.
27+
* See [AccessibilityManager.isTouchExplorationEnabled] for more details.
28+
*
29+
* @return true if the screen reader is enabled.
30+
*/
31+
fun Context.isScreenReaderEnabled(): Boolean {
32+
val accessibilityManager = getSystemService<AccessibilityManager>()
33+
?: return false
34+
35+
return accessibilityManager.let {
36+
it.isEnabled && it.isTouchExplorationEnabled
37+
}
38+
}
39+

0 commit comments

Comments
 (0)