JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.27k stars 1.11k forks source link

Disable tab navigation to focus on other Pager's page Composable when Pager sets userScrollEnable = false #4907

Open Moriafly opened 1 month ago

Moriafly commented 1 month ago

Describe the bug The userScrollEnable = false is to prevent users from sliding and switching between pages on a Pager, allowing switching between different pages to be completely controlled by the logic set by the developer, such as automatically jumping through a button click or triggering a specific event, but tag navigation breaks this logic.

Affected platforms

Versions

To Reproduce Steps to reproduce the behavior:

  1. Run this code snippet:

    @Composable
    fun BugReproduction() {
       val pagerState = rememberPagerState {
           2
       }
    
       VerticalPager(
           state = pagerState,
           modifier = Modifier
               .fillMaxSize(),
           beyondBoundsPageCount = 1,
           userScrollEnabled = false
       ) { page ->
           when (page) {
               0 -> {
                   // Focusable elements
               }
    
               1 -> {
                   // Focusable elements
               }
           }
       }
    }
  2. Use tab navigation.
  3. When focusing on the last focus element in the first page, click the Tab button again, and Pager will scroll to the second page and focus on the focus element of the second page.
  4. Another point: If scrollable elements such as LazyColumn/LazyRow are used in the first Pager, using tab navigation multiple times may cause the Pager to get stuck in the middle of the page switch. And userScrollEnable = false makes it impossible for users to scroll through the Pager.

Expected behavior I think userScrollEnable = false should prevent users from switching pages of the Pager through tag navigation.