HorizontalPager pagination with dynamic load from server in jetpack compose

137 views Asked by At

I have HorizontalPager and some list of object id. This HorizontalPager is a Card. The opened activity is and object which was fetch from server.

How to load in background next and previous object from server to background?

@Composable
fun ObjectViewLayout(
agent: Agent //or list of Agent
) {
val pagerState = rememberPagerState(
        pageCount = 3, //list of Agent size
        initialPage = 2
    )
  Card(
        modifier = Modifier
            .fillMaxWidth()
    ) {
       HorizontalPager(
            state = pagerState, modifier = Modifier
        ) { page ->
            Scaffold(
                topBar = { FragmentMenu(onBackClick = onBackClick, onReplyClick = onReplyClick) },
                modifier = Modifier.fillMaxSize(),
                backgroundColor = Color(android.graphics.Color.parseColor("#ffE0E0E0"))
            ) { paddingValues ->
                Column(
                    Modifier
                        .fillMaxSize()
                        .padding(paddingValues = paddingValues),
                ) {
                    SubjectRow(agent = agent)
                    ReceivedDateRow(agent = agent)
                    Divider(
                        color = Color(android.graphics.Color.parseColor("#ff676767")),
                        thickness = 1.dp
                    )
                    if (!fullContactInfo) {
                        Info(from = agent.froms, onShowFullInfoClick = {
                            fullInfo = true
                        })
                    } else {
                        FullInfo(
                            from = agent.froms,
                            onHideClick = {
                                fullInfo = false
                            })
                    }
                    if (object.Text != null) {
                        WebView(agent = agent)
                    }

                }
            }
        }
    
0

There are 0 answers