Skip to content

Instantly share code, notes, and snippets.

@AdamMc331
Created November 30, 2021 15:46
Show Gist options
  • Save AdamMc331/84e09f1a62f654a8974bf24a2ca51278 to your computer and use it in GitHub Desktop.
Save AdamMc331/84e09f1a62f654a8974bf24a2ca51278 to your computer and use it in GitHub Desktop.
Shows how UIImage concept can be used for prod and previews.
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