Skip to content

Instantly share code, notes, and snippets.

View catalinghita8's full-sized avatar

Catalin Ghita catalinghita8

View GitHub Profile
fun CardContainer(
modifier: Modifier,
onClick: () -> Unit = { },
contents: @Composable RowScope.() -> Unit
) {
var size by remember { mutableStateOf(Size.Zero) }
val shader = SweepGradientShader(
center = Offset(size.width / 2, size.height / 2),
colors = listOf(Color.Transparent, Color(0xFFF1C374)),
colorStops = listOf(0.5f, 1f),
@Composable
fun AnimatedBorderCard(
modifier: Modifier,
contents: @Composable RowScope.() -> Unit
) {
val containerSize = 200.dp
var offsetFloat by remember { mutableStateOf(0f) }
LaunchedEffect(null) {
delay(100)
offsetFloat = containerSize.value * 10f
@ExperimentalCoroutinesApi
class RestaurantsViewModelTest {
private val dispatcher = StandardTestDispatcher()
private val scope = TestScope(dispatcher)
@Test
fun stateWithError_isProduced() = scope.runTest {
val testVM = getViewModel(shouldThrowException = true)
advanceUntilIdle()
val currentState = testVM.state.value
// Consumer usage
class MyFragment : Fragment(R.layout.my_fragment) {
private val viewModel: MyViewModel by viewModels()
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val consumer = consumeState(viewModel)
}
}
@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))
@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()
...
}
@Composable
private fun CategoryDetailsCollapsingToolbar(category: FoodItem?, scrollOffset: Float) {
val imageSize by animateDpAsState(targetValue = max(72.dp, 128.dp * scrollOffset))
val linesCount = max(3f, scrollOffset * 6).toInt()
Row {
Image(modifier = Modifier.size(imageSize), ...)
Column {
Text(text = item?.name)
Text(
text = item.description.trim(),
@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)
...
val scrollOffset: Float = min(
1f,
1 - (scrollState.firstVisibleItemScrollOffset / 600f +
scrollState.firstVisibleItemIndex)
)
@Composable
fun FoodCategoryDetailsScreen(state: FoodCategoryDetailsContract.State) {
val scrollState = rememberLazyListState()
Column {
...
LazyColumn(state = scrollState) { ... }
}
}