Created
November 30, 2021 15:46
-
-
Save AdamMc331/84e09f1a62f654a8974bf24a2ca51278 to your computer and use it in GitHub Desktop.
Shows how UIImage concept can be used for prod and previews.
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
sealed class UiImage { | |
data class LocalImage(val imageRes: Int) : UiImage() | |
data class RemoteImage(val imageUrl: String) : UiImage() | |
} | |
// Component | |
@Composable | |
fun UserProfile( | |
avatar: UiImage, | |
) | |
// In production | |
UserProfile( | |
avatar = UiImage.RemoteImage(avatarURL) | |
) | |
// In preview | |
@Preview | |
@Composable | |
fun UserProfilePreview() { | |
UserProfile( | |
avatar = UiImage.LocalImage(R.drawable.preview_avatar) | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment