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

Pages not calling onPageSelected #526

Closed
qavan opened this issue Nov 14, 2023 · 2 comments
Closed

Pages not calling onPageSelected #526

qavan opened this issue Nov 14, 2023 · 2 comments

Comments

@qavan
Copy link

qavan commented Nov 14, 2023

Pages not calling onPageSelected, for example, if swiped slowly to page

Decompose: 2.1.4

sealed class PageConfig : Parcelable {
    @Parcelize
    data object Page1: PageConfig()
    @Parcelize
    data object Page2: PageConfig()
}

class PageComponent(val page: PageConfig)

@ExperimentalDecomposeApi
class PagesComponent(context: ComponentContext): ComponentContext by context {
    private val navigation = PagesNavigation<PageConfig>()

    val tabs: Value<ChildPages<PageConfig, PageComponent>> = childPages(
        source = navigation,
        initialPages = {
            Pages(
                items = listOf(
                    PageConfig.Page1,
                    PageConfig.Page2,
                ),
                0
            )
        },
    ) { config, _ ->
        return@childPages PageComponent(config)
    }

    fun selectPage(page: Int) {
        navigation.select(page)
    }
}

@ExperimentalDecomposeApi
@Preview
@Composable
fun PagesIssue() {
    val lifecycleOwner = LocalLifecycleOwner.current
    val component = remember { PagesComponent(DefaultComponentContext(lifecycleOwner.lifecycle.asEssentyLifecycle())) }
    val pages by component.tabs.subscribeAsState()
    Column {
        Text(
            text = "${pages.selectedIndex}",
        )
        Pages(
            pages = component.tabs,
            modifier = Modifier.weight(1f),
            onPageSelected = component::selectPage
        ) { index, page ->
            Text(
                text = "${page.page}",
                modifier = Modifier
                    .fillMaxSize()
                    .wrapContentSize(align = Alignment.TopCenter)
                    .padding(top = 12.dp)
            )
        }
    }
}
Screen_recording_20231114_115241.mp4
@arkivanov
Copy link
Owner

Hello. I believe this should be fixed in Compose 1.6.0-alpha08. Please try this version.

@qavan
Copy link
Author

qavan commented Nov 16, 2023

yeah, fixed(checked in 1.6.0-beta01)

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

2 participants