Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HorizontalPager from 0.19 no more support dragEnabled #756

Closed
Patresko opened this issue Sep 30, 2021 · 18 comments
Closed

HorizontalPager from 0.19 no more support dragEnabled #756

Patresko opened this issue Sep 30, 2021 · 18 comments
Assignees

Comments

@Patresko
Copy link

Is this what was planned? Because I have not found any mention about removing dragEnabled.

For example, if im using HorizontalPager for images, which are able to zoom, i was disable dragging to previous / next page.

@mamilov
Copy link

mamilov commented Sep 30, 2021

+1 here, also a little bit confused about this change. How can we now achieve this? modifier.scrollable(enabled=false) does not work for me...

@MojRoid
Copy link

MojRoid commented Sep 30, 2021

+1

@LittleBoxOfChicken
Copy link

+1 I'm really confused as to why they broke everything like this

@offvanHooijdonk
Copy link

+1 Would be nice to have. I find workaround in my UI, but still a useful property.

@gvozditskiy
Copy link

Always use Pager with disabled drag for screens like Onboarding. This update breaks expected behavior

@ArthurKun21
Copy link

hello, is there any way to implement back the dragEnabled?

@kikasik
Copy link

kikasik commented Oct 15, 2021

+1

1 similar comment
@GreatWolfXX
Copy link

+1

@ChargemapMobile
Copy link

Same here, we found this attribute very useful !
We will try to implement an interceptor on top the Pager I guess :(

@ArthurKun21
Copy link

so i did found out how to temporarily make this comment work #678 (comment)

@ExperimentalPagerApi
fun PagerState.disableScrolling(scope: CoroutineScope) {
    scope.launch {
        scroll(scrollPriority = MutatePriority.PreventUserInput) {
            // Await indefinitely, blocking scrolls
            awaitCancellation()
        }
    }
}

@ExperimentalPagerApi
fun PagerState.enableScrolling(scope: CoroutineScope) {
    scope.launch {
        scroll(scrollPriority = MutatePriority.PreventUserInput) {
            // Do nothing, just cancel the previous indefinite "scroll"

        }
    }
}

and then according to the use case of it

val scope = rememberCoroutineScope()
val pagerState = rememberPagerState()
pagerState.disableScrolling(scope)

and this is how I did use it

HorizontalPager(
content = { page ->
   when(page){
    0 -> item( onclick = {
                scope.launch(
                           pagerState.enableScrolling(this)
                           delay(100)
                           pagerState.scrollToPage(1)
                           pagerState.disableScrolling(this)
               )

@ChargemapMobile
Copy link

ChargemapMobile commented Oct 28, 2021

@RulerKun thank you for your comment but it sounds inconvenient for me right now but I found a working solution.

I am using a container for my pages to intercept the drag events and it seems to work :

HorizontalPager(
...
) { index ->
Box(modifier = Modifier.pointerInput(Unit) {
detectDragGestures { _, _ -> }
}) {
// My real page content
}
}

@ArthurKun21
Copy link

oh nice, thanks for another solution

@github-actions
Copy link

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 github-actions bot added the stale Stale issues which are marked for closure label Nov 28, 2021
@jakoss
Copy link

jakoss commented Nov 28, 2021

It's not stale Google bot, it's just ignored by maintainers 😂

@github-actions github-actions bot removed the stale Stale issues which are marked for closure label Nov 29, 2021
@andkulikov andkulikov self-assigned this Dec 1, 2021
@chippmann
Copy link
Contributor

Another use case which is common and could be considered is scrolling only upon a specific page.
This is often used in onboarding flows as well.
So let's say the pager has 5 pages. On each page the user has to enter some information or grant some permissions.
We only want the user to be able to freely scroll between the pages he has filled out + 1 (for the one he currently has to fill out.

@andkulikov
Copy link
Collaborator

Another use case which is common and could be considered is scrolling only upon a specific page. This is often used in onboarding flows as well. So let's say the pager has 5 pages. On each page the user has to enter some information or grant some permissions. We only want the user to be able to freely scroll between the pages he has filled out + 1 (for the one he currently has to fill out.

I don't think this will even be supported in the way you described. You probably just need to only pass pageCount of the filled out pages and add more pages once the user filled the current one

@andkulikov
Copy link
Collaborator

andkulikov commented Dec 3, 2021

There is a simple workaround available

private val VerticalScrollConsumer = object : NestedScrollConnection {
    override fun onPreScroll(available: Offset, source: NestedScrollSource) = available.copy(x = 0f)
}

private val HorizontalScrollConsumer = object : NestedScrollConnection {
    override fun onPreScroll(available: Offset, source: NestedScrollSource) = available.copy(y = 0f)
}

fun Modifier.disableVerticalPointerInputScroll() = this.nestedScroll(VerticalScrollConsumer)

fun Modifier.disableHorizontalPointerInputScroll() = this.nestedScroll(HorizontalScrollConsumer)

Apply an appropriate modifier on Pager in order to disable the touch based scrolling. I will close this bug for now, please follow https://issuetracker.google.com/issues/201150093 where we will track the final decision on if we want to add scrollEnabled param on components or provide such modifier in the api

@Homa-Shafiei
Copy link

Homa-Shafiei commented Aug 2, 2022

I found a working solution. I am using userScrollEnabled and set it false like this:

HorizontalPager(userScrollEnabled = false){}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests