Created
September 28, 2024 23:04
-
-
Save yuriyskulskiy/e41f84e0390f8188b5cfceeb4ddbb96d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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