Created
July 8, 2021 11:33
-
-
Save catalinghita8/db9672af27a7c10380afe18b32e799db 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 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