<@UHAJKUSTU> I have a Flow<PagingData<T>>, now I w...
# decompose
v
@Arkadii Ivanov I have a Flow<PagingDataT>, now I want each item of this PagingData to be a page in the Pager Navigation How can i achieve this?
a
Sorry, I'm not quite familiar with paging libraries. You might need to subscribe to the paging source and use StackNavigation to append new pages. And also trigger next page loading on scroll.
v
Thanks, I'll try this out
👍 1
a
This discussion might be helpful as well: https://github.com/arkivanov/Decompose/discussions/462
v
Thanks a lot, ill try this way
Hi @Arkadii Ivanov I was trying this out This is how I have created the Pages
Copy code
val childPages = childPages(
    source = navigation,
    serializer = IdeathonPagesConfig.serializer(),
    childFactory = { config, context ->
        IdeathonPages.Competition(createComponent(config, context))
    }
)
and this how i am adding the pages
Copy code
val index = if(childPages.value.selectedIndex == -1) 0 else childPages.value.selectedIndex
navigation.navigate {
    it.copy(
        items = it.items + configs,
        selectedIndex = index
    )
}
Ui
Copy code
Pages(
    pages = pages,
    onPageSelected = component::selectPage,
    modifier = Modifier.fillMaxSize().padding(innerPadding),
    scrollAnimation = PagesScrollAnimation.Default,
){ _, page ->
    CompetitionPage(component = page.component)
}
But i am getting index error > java.lang.IndexOutOfBoundsException: Index -1, size 3 What am i doing wrong?
if I add this before Pages, it works
Copy code
if(selectedPage == -1) return@Scaffold
a
What version of Decompose you are using?
v
3.0.0
a
Interesting! This actually might be a bug in HorizontalPager. I will take a look.
There are multiple similar issues reported previously but already fixed: https://issuetracker.google.com/issues?q=HorizontalPager%20indexoutofboundsexception%20 You may also try different versions of Compose.
v
Oh i see Using that If check wont be causing any issue if I'm not wrong
a
Yeah, but I think ideally it should work regardless.
I will try adding more tests and see how it works.
v
Thanks I'm already on CMP 1.6.2, not sure when the fix will be released
Seems to be fixed in 1.7.0
a
Wow, thanks for letting me know!
v
The duplicate issue link in the last comment is the fix, If i'm not wrong says fixed in 1.7.0
a
I will check, thanks.
I could reproduce the issue without Decompose. It looks like
HorizontalPager
doesn't like the initial index -1, but works if the initial index is 0. Could you please try setting the following argument for your
childPages
?
Copy code
initialPages = { Pages(items = emptyList(), selectedIndex = 0) },