Skip to content

Instantly share code, notes, and snippets.

@catalinghita8
Created July 8, 2021 11:33
Show Gist options
  • Save catalinghita8/db9672af27a7c10380afe18b32e799db to your computer and use it in GitHub Desktop.
Save catalinghita8/db9672af27a7c10380afe18b32e799db to your computer and use it in GitHub Desktop.
@Composable
fun FoodCategoryDetailsScreen(state: FoodCategoryDetailsContract.State) {
val scrollState = rememberLazyListState()
val scrollOffset: Float = min(
1f,
1 - (scrollState.firstVisibleItemScrollOffset / 600f + scrollState.firstVisibleItemIndex)
)
Column {
CategoryDetailsCollapsingToolbar(state.category, scrollOffset)
Spacer(modifier = Modifier.height(2.dp))
LazyColumn(state = scrollState) {
items(state.categoryFoodItems) { item ->
FoodItemRow(item = item)
}
}
}
}
@Composable
private fun CategoryDetailsCollapsingToolbar(category: FoodItem?, scrollOffset: Float) {
val imageSize by animateDpAsState(targetValue = max(72.dp, 128.dp * scrollOffset))
val dynamicLines = max(3f, scrollOffset * 6).toInt()
Row {
Image(
painterResource(id = ... ),
modifier = Modifier.size(imageSize),
contentDescription = "Food Category thumbnail"
)
Column {
Text(text = category?.name ?: "")
Text(
text = category?.description?.trim() ?: "",
maxLines = dynamicLines
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment