accompanist icon indicating copy to clipboard operation
accompanist copied to clipboard

[Pager] HorizontalPager goes to previous/next page on vertical scroll

Open miduch opened this issue 3 years ago • 5 comments

Description Trying to use WebView composable (from Accompanist) inside HorizontalPager, when webpage is scrolled (vertically), pager tries to go to next page/ sometime even does go to next page.

Steps to reproduce Run attached sample project and vertically scroll opened webpage in webview.

@OptIn(ExperimentalPagerApi::class)
@SuppressLint("SetJavaScriptEnabled")
@Composable
fun WebViewPager() {
    val pagerState = rememberPagerState()
    HorizontalPager(
        count = 5,
        state = pagerState,
    ) { page ->
        val webViewState = rememberWebViewState("https://duckduckgo.com/?q=${page.inc()}")
        WebView(
            state = webViewState,
            modifier = Modifier.fillMaxSize(),
            onCreated = { it.settings.javaScriptEnabled = true }
        )
    }
}

Expected behavior When webview/ webpage is scrolled vertically, HorizontalPager shouldn't try to go to previous/next page

Additional context

        compose_compiler_version = '1.2.0'
        compose_ui_version = '1.2.0-rc03'
        accompanist_version = '0.24.13-rc'
        kotlin 1.7.0

WebViewPager.zip

miduch avatar Jul 07 '22 21:07 miduch

https://user-images.githubusercontent.com/22243296/177878788-10bd97ac-90aa-42ce-afc1-45000f57ac9b.mp4

miduch avatar Jul 07 '22 22:07 miduch

when doing same with only compose without any AndroidView/WebView then it works fine e.g. any vertical scroll on following doesn't cause HorizontalPager trying to open page when its not wanted, one has to clearly do horizontal scroll to go to next page.

@OptIn(ExperimentalPagerApi::class)
@Composable
fun ComposePager() {
    val pagerState = rememberPagerState()
    HorizontalPager(
        count = 5,
        state = pagerState,
    ) { page ->
        Column(
            modifier = Modifier
                .fillMaxSize()
                .verticalScroll(state = rememberScrollState())
        ) {
            repeat(30) {
                Card(
                    modifier = Modifier
                        .fillMaxWidth()
                        .padding(horizontal = 8.dp, vertical = 12.dp)
                        .wrapContentHeight()
                ) {
                    Text(
                        text ="Item $it",
                        fontSize = MaterialTheme.typography.h3.fontSize
                    )
                }
            }
        }
    }
}

miduch avatar Jul 07 '22 22:07 miduch

I'm facing the same issue in a layout that includes a LazyColumn inside a pager inside a BackdropScaffold. I'm seeing random unpredictable scroll behavior on a generic user's vertical swipe, which should only scroll the lazycolumn (according to the expectations and previous behavior) This issue started only after migrating to accompanist 0.24.13 from 0.24.10

Nek-12 avatar Jul 13 '22 13:07 Nek-12

anything available that the possible couse of this? I am facing the same issue too like @Nek-12 with a scaffold containing horizontal view pager including lazy column

alitahabundle avatar Aug 05 '22 12:08 alitahabundle

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Sep 05 '22 04:09 github-actions[bot]

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Oct 06 '22 03:10 github-actions[bot]

Not stale

Nek-12 avatar Oct 06 '22 06:10 Nek-12

Is there a chance you can share a reproducible sample for the case when it happens without WebView?

andkulikov avatar Oct 06 '22 11:10 andkulikov

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Nov 07 '22 03:11 github-actions[bot]

I have same issue. Is there a solution?

Acorde avatar Mar 06 '23 13:03 Acorde

I have same issue. Is there a solution?

@Acorde Did you try foundation pager? Maybe they fixed it there, even if it was abandoned here.

Zhuinden avatar Mar 12 '23 21:03 Zhuinden

I'm using the foundation pager and this issue is still present, is there any know workaround?

leinardi avatar Jul 28 '23 09:07 leinardi

Please file a bug in the main compose bug tracker with a reproducible sample. Thanks!

andkulikov avatar Jul 28 '23 10:07 andkulikov

Couldn't this be an issue related to the WebView accompanist wrapper? In the end the issue happens with the WebView wrapper with both the old and new pager.

@andkulikov Shouldn't I file a WebView issue here instead?

EDIT I've created #1687

leinardi avatar Jul 28 '23 10:07 leinardi

Right, sorry. It is indeed a WebView related issue most likely

andkulikov avatar Jul 28 '23 11:07 andkulikov