Skip to content

Commit

Permalink
Move to better location
Browse files Browse the repository at this point in the history
  • Loading branch information
StaehliJ committed Dec 16, 2024
1 parent 8d7e684 commit 34b2a38
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,27 @@ fun rememberIsTouchExplorationEnabled(): Boolean {

return isTouchExplorationEnabled
}

/**
* A composable function that returns a boolean indicating whether TalkBack is currently enabled.
*
* This function uses a [DisposableEffect] to register an [AccessibilityManager.AccessibilityStateChangeListener]
* that updates the state of the composable when the accessibility state changes.
*
* @return `true` if TalkBack is enabled, `false` otherwise.
*/
@Composable
fun rememberIsTalkBackEnabled(): Boolean {
val accessibilityManager = LocalContext.current.getSystemService<AccessibilityManager>() ?: return false
val (isTalkBackEnabled, setTalkBackEnabled) = remember {
mutableStateOf(accessibilityManager.isEnabled)
}
DisposableEffect(Unit) {
val l = AccessibilityManager.AccessibilityStateChangeListener(setTalkBackEnabled)
accessibilityManager.addAccessibilityStateChangeListener(l)
onDispose {
accessibilityManager.removeAccessibilityStateChangeListener(l)
}
}
return isTalkBackEnabled
}

This file was deleted.

0 comments on commit 34b2a38

Please sign in to comment.