https://kotlinlang.org logo
Title
f

FEDUSS

05/26/2023, 10:11 PM
Hello! The NavView of my app is composed by: MaterialTheme>SwipeToDismissBox>WearNavScaffold>PagerView(inside a scrollable block). I was wondering if having a PagerView inside a scrollable could be ok because, after scrolling horizontaly in a page with button, i need two tap to interact with that button (the first tap isn't recognized or is fired by something else i suppose). Every page inside the PagerView has a ScalingLazyColumn with the column state of the scrollable block. Thanks for your help (i hope so :D) ps: if you need more info about my app ui structure, feel free to ask
y

yschimke

05/26/2023, 10:17 PM
Why do you need SwipeToDismissBox and WearNavScaffold also?
I'm not sure about the double tap, but should work, so next is probably a bug with executable repro.
f

FEDUSS

05/27/2023, 6:40 AM
Does WearNavScaffold handle back swipe too? Btw i think that SwipeToDismissBox is an old refuse in my code, because it doesn't work with PagerScreen ahahaah (and that's correct)
Yeah, the double tap could be a bug, because it has to work with the first one only (or maybe it's the complex layout in my app that is the cause). If you needed, i can provide you a sample project and a video to show the bug.
y

yschimke

05/27/2023, 7:15 AM
You can pass the swipe to dismiss state into WearNavScaffold. I'll send a sample later.
f

FEDUSS

05/27/2023, 7:25 AM
Cool, thanks! I still trying to figure out the double tap button, so weird :'D
y

yschimke

05/27/2023, 10:44 AM
This sample shows combining them
val swipeToDismissBoxState = rememberSwipeToDismissBoxState()
    val navHostState =
        rememberSwipeDismissableNavHostState(swipeToDismissBoxState = swipeToDismissBoxState)
    val navController = rememberSwipeDismissableNavController()
Then passed into the screen with a pager
@Composable
fun SamplePagerScreen(swipeToDismissBoxState: SwipeToDismissBoxState) {
    PagerScreen(
        modifier = Modifier.edgeSwipeToDismiss(swipeToDismissBoxState),
        state = rememberPagerState {
            10
        }
    ) {
        PagerItemScreen(item = "item $it")
    }
}
f

FEDUSS

05/27/2023, 10:57 AM
Thanks man, very kind! I'll try it asap...maybe it will fix double tap bug too. Do you still need the sample to reproduce this bug? I'm not at pc right now, but this afternoon yep
y

yschimke

05/27/2023, 11:16 AM
If still failing, yep code as text to repro would be helpful. I'll take a look on Tuesday (Monday is a holiday)
f

FEDUSS

05/27/2023, 11:24 AM
Sure...See you on Tuesday! Have a nice weekend ;)
Hi @yschimke! I have attached a zip with the sample project. I can reproduce the double tap bug. Moreover, i'm definitely makeing a mistake in my code because i can't scroll pages after changing page in PagerScreen (with horizontal swipe). Can you please help me to figure out what's wrong? I think that the "scrollable" func is in the wrong place, but i'm too newbie to be sure of that :P. These two bugs are the only remaining in my app (atm :D) and i don't how to fix them XD
OT: i realized that i don't need swipeToDismissHandler in my app
y

yschimke

05/30/2023, 1:10 PM
OK, couple of issues, one easy one for you, one harder one for us.
1. We should document it better, but 0.4.x is tracking the betas of Compose 1.5 and Wear Compose 1.2. So you should make sure you use those versions or downgrade to Horologist 0.3.x
2. There isn't currently a navigation DSL method, similar to scrollable() for the pager screen. See https://github.com/google/horologist/issues/823
So this, is sharing column state, that isn't safe/working.
scrollable(route = "BaseNav") { scrollableScaffoldContext ->
                PagerScreen(
                    state = pagerState
                ) { selectedPage ->

                    when(selectedPage) {
                        0 -> PageOne(
                            navController = navController,
                            columnState = scrollableScaffoldContext.columnState
                        )

                        1 -> PageTwo(
                            navController = navController,
                            columnState = scrollableScaffoldContext.columnState
                        )
Instead of
scrollable
you'll need to use
composable
and then create the ColumnState yourself. That also means for now putting the PositionIndicator and TimeText on each page.
f

FEDUSS

05/30/2023, 1:23 PM
thanks for the answer, i'll try to fix with your suggestions 🙂
y

yschimke

05/30/2023, 1:35 PM
I should really implement that issue, would be nice, just not sure of the right API for it.
f

FEDUSS

06/01/2023, 7:59 AM
Hi! I have replace scrollable to composable as you said, and i created N column state with "ScalingLazyColumnDefaults.belowTimeText().create()". Then i disabled time text and position indicator, and i implemented them in every page (i need only timetext atm):
@Composable
private fun PagerContent(
    focusRequester: FocusRequester,
    content: @Composable () -> Unit
) {
    Scaffold(
        modifier = Modifier
            .focusRequester(focusRequester)
            .focusable(),
        timeText = {
            TimeText()
        },
        content = {
            content()
        }
    )
}
The problem is that, when i click a button in a page inside PagerScreen to navigate in a nested page and then i go back, i land in the first page. I also tried changing the initial page of a remembered pager state, without changes. update: this problem is due to the rollback of Horologist to 0.3.11, fixed in 0.4.8 Another question i have is the following. I'm trying to implement swipeToDismissBoxState as you suggested me few days ago. The problem is that, differently from SwipeToDismissBox, i don't have a closure to customize what happen when i swipe back, but only when the swipe back is enabled. Am i missing something? Thanks for your time! :)