This file contains hidden or 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
// Event.kt | |
sealed interface Event { | |
fun nextDestination(): Destination | |
data object OnBack : Event { | |
override fun nextDestination(): Destination = Destination.Back | |
} | |
} | |
// ShoppingEvent.kt |
This file contains hidden or 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
// Destination.kt | |
sealed interface Destination { | |
@Serializable | |
data object Back : Destination | |
} | |
// ShoppingDestination.kt | |
object ShoppingDestination { | |
@Serializable |
This file contains hidden or 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 screen code | |
when (state) { | |
MainState.Loading -> { | |
ShimmerProvider { | |
ItemCard(item = fakeData) | |
} | |
} | |
is MainState.Success -> { | |
ItemCard(item = state.itemData) |
This file contains hidden or 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 Modifier.shimmerable( | |
shape: Shape = RoundedCornerShape(8.dp), | |
color: Color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.6f) | |
): Modifier { | |
if (!LocalShimmerState.current.isLoading) return this | |
return this | |
.shimmer() | |
.background(color = color, shape = shape) |
This file contains hidden or 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 screen code | |
when (state) { | |
MainState.Loading -> { | |
ItemCard( | |
item = fakeData, | |
isLoading = true, | |
) | |
} | |
is MainState.Success -> { |
This file contains hidden or 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 | |
private fun ItemCard( | |
item: ItemData, | |
isLoading: Boolean = false | |
modifier: Modifier = Modifier | |
) { | |
Text( | |
text = item.description, | |
style = MaterialTheme.typography.bodyMedium, | |
modifier = Modifier.shimmerable(enabled = isLoading) |
This file contains hidden or 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
@PreviewLightDark | |
@Composable | |
private fun ShimmerablePreview() { | |
ExampleTheme { | |
Column( | |
modifier = Modifier | |
.background(MaterialTheme.colorScheme.surface) | |
.padding(8.dp) | |
) { | |
Text( |
NewerOlder