Skip to content

Instantly share code, notes, and snippets.

@yuriyskulskiy
Created September 28, 2024 23:04
Show Gist options
  • Save yuriyskulskiy/e41f84e0390f8188b5cfceeb4ddbb96d to your computer and use it in GitHub Desktop.
Save yuriyskulskiy/e41f84e0390f8188b5cfceeb4ddbb96d to your computer and use it in GitHub Desktop.
@Composable
fun ParallaxRoute(
viewModel: ParallaxVewModel = hiltViewModel(),
) {
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
ParallaxScreen(uiState)
}
@Composable
fun ParallaxScreen(
uiState: List<ListItemUi>
) {
ParallaxLazyColumn(uiState)
}
@Composable
fun ParallaxLazyColumn(uiState: List<ListItemUi>) {
val listState = rememberLazyListState()
val viewportHeight by remember {
derivedStateOf {
listState.layoutInfo.viewportEndOffset.toFloat() - listState.layoutInfo.viewportStartOffset.toFloat()
}
}
LazyColumn(
verticalArrangement = Arrangement.spacedBy(16.dp),
contentPadding = PaddingValues(16.dp),
state = listState,
modifier = Modifier.fillMaxSize()
) {
this.itemsIndexed(items = uiState,
key = { index, itemUi -> itemUi.id }) { index, itemUi: ListItemUi ->
ScrollPositionListItem(
itemUi = itemUi,
listState = listState,
index = index,
viewportHeight = viewportHeight
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment