a11y: Make isTalkbackActive() live.

We made the assumption that the user needs to navigate to the setting to enable or disable the talkback, but there is a way to add a talkback switch on the bottom navigation bar. So the talkback can be enabled/disabled when the application is resumed. Since the UI may render differently depending on the talkback state, we need to make the composable `isTalkbackActive()` backed on a mutable state.
This commit is contained in:
Benoit Marty
2025-06-20 09:43:01 +02:00
parent 0dfec51889
commit f0508d342f

View File

@@ -9,12 +9,26 @@ package io.element.android.libraries.ui.utils.time
import android.view.accessibility.AccessibilityManager import android.view.accessibility.AccessibilityManager
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
@Composable @Composable
fun isTalkbackActive(): Boolean { fun isTalkbackActive(): Boolean {
val context = LocalContext.current val context = LocalContext.current
val accessibilityManager = remember { context.getSystemService(AccessibilityManager::class.java) } val accessibilityManager = remember { context.getSystemService(AccessibilityManager::class.java) }
return accessibilityManager.isTouchExplorationEnabled var isTouchExplorationEnabled by remember { mutableStateOf(accessibilityManager.isTouchExplorationEnabled) }
DisposableEffect(Unit) {
val listener = AccessibilityManager.TouchExplorationStateChangeListener { enabled ->
isTouchExplorationEnabled = enabled
}
accessibilityManager.addTouchExplorationStateChangeListener(listener)
onDispose {
accessibilityManager.removeTouchExplorationStateChangeListener(listener)
}
}
return isTouchExplorationEnabled
} }