Skip to content

Commit e9f9942

Browse files
committed
feat: Adapt BottomAppBar for accessibility
The BottomAppBar now adapts its behavior based on whether touch exploration is enabled in the accessibility settings. When touch exploration is enabled, it will always show the label in the navigation bar. Otherwise it will use the default `exitAlwaysScrollBehavior`.
1 parent 2a7ab6b commit e9f9942

File tree

1 file changed

+9
-3
lines changed
  • app/src/main/java/com/github/jing332/tts_server_android/compose

1 file changed

+9
-3
lines changed

app/src/main/java/com/github/jing332/tts_server_android/compose/MainPager.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import androidx.compose.material3.NavigationBarItem
1515
import androidx.compose.material3.Scaffold
1616
import androidx.compose.material3.Text
1717
import androidx.compose.runtime.Composable
18+
import androidx.compose.runtime.remember
1819
import androidx.compose.runtime.rememberCoroutineScope
1920
import androidx.compose.ui.Modifier
2021
import androidx.compose.ui.input.nestedscroll.nestedScroll
@@ -26,6 +27,7 @@ import com.github.jing332.tts_server_android.compose.systts.MigrationTips
2627
import com.github.jing332.tts_server_android.compose.systts.TtsLogScreen
2728
import com.github.jing332.tts_server_android.compose.systts.list.ListManagerScreen
2829
import kotlinx.coroutines.launch
30+
import splitties.systemservices.accessibilityManager
2931

3032
@OptIn(
3133
ExperimentalFoundationApi::class, ExperimentalLayoutApi::class,
@@ -37,23 +39,27 @@ fun MainPager(sharedVM: SharedViewModel) {
3739
val scope = rememberCoroutineScope()
3840

3941
MigrationTips()
40-
val scrollBehavior = BottomAppBarDefaults.exitAlwaysScrollBehavior()
42+
val allyEnabled = remember { accessibilityManager.isTouchExplorationEnabled }
43+
val scrollBehavior = BottomAppBarDefaults.exitAlwaysScrollBehavior(canScroll = {
44+
!allyEnabled
45+
})
4146

4247
Scaffold(
4348
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
4449
bottomBar = {
4550
val containerColor = NavigationBarDefaults.containerColor
4651
InitSystemNavigation(containerColor)
4752
BottomAppBar(
48-
modifier = Modifier.fillMaxWidth(),
53+
modifier = Modifier
54+
.fillMaxWidth(),
4955
containerColor = containerColor,
5056
scrollBehavior = scrollBehavior,
5157
actions = {
5258
for (destination in PagerDestination.routes) {
5359
val isSelected = pagerState.currentPage == destination.index
5460
NavigationBarItem(
5561
selected = isSelected,
56-
alwaysShowLabel = false,
62+
alwaysShowLabel = allyEnabled,
5763
onClick = {
5864
scope.launch {
5965
pagerState.animateScrollToPage(destination.index)

0 commit comments

Comments
 (0)