tylerwilson
07/11/2023, 9:19 PMtylerwilson
07/11/2023, 9:20 PMval tabs = listOf("Search", "Recommended", "History")
    val pagerState = rememberPagerState(pageCount = { tabs.count() })
    val coroutineScope = rememberCoroutineScope()
    Column(modifier = Modifier.background(MaterialTheme.colorScheme.background)) {
        TabRow(selectedTabIndex = pagerState.currentPage,
            modifier = Modifier
                .fillMaxWidth()
                .wrapContentHeight()
        ) {
            tabs.forEachIndexed { index, title ->
                Tab(selected = pagerState.currentPage == index, onClick = { coroutineScope.launch { pagerState.animateScrollToPage(index) } },
                    Modifier.padding(bottom = 8.dp, top = 12.dp)) {
                        Text(title)
                }
            }
        }
        HorizontalPager(state = pagerState, userScrollEnabled = false) {
            when (pagerState.currentPage) {
                0 -> ProductSearchView(viewModel, callback)
                1 -> ProductRecommendedView(viewModel, callback)
                2 -> ProductHistoryView(viewModel, callback)
            }
        }
    }Timo Drick
07/11/2023, 9:49 PMtylerwilson
07/11/2023, 9:53 PM@OptIn(ExperimentalFoundationApi::class)
@Composable
fun ProductLookupView(viewModel: ProductSearchViewModel, callback: (action: String, context: Any?) -> Unit) {
    val loading = viewModel.loading.collectAsState()
    val error = viewModel.error.collectAsState()
so yeah, I do have a viewmodel. I will first try to save scrollstate in this composable, since this a shared viewmodel and i dont want the scroll to persist outside of this view.
The first issue i mentioned is only within one page: scroll down, let go, and it scrolls it to the top. I cannot tell who is making it go to the top, but i tried putting the same LazyColumn outside the tabset, and it worked fine. That is why I suspected the pager is somehow telling its child to scroll. More debugging required.Timo Drick
07/11/2023, 10:16 PMStylianos Gakis
07/12/2023, 6:16 AM