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
| // Before: Coil | |
| CoilImage( | |
| model = imageUrl, | |
| contentDescription = "Photo", | |
| component = rememberImageComponent { | |
| +ShimmerPlugin() | |
| +CrossfadePlugin() | |
| } | |
| ) |
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
| // Before: Glide | |
| GlideImage( | |
| model = imageUrl, | |
| contentDescription = "Photo", | |
| modifier = Modifier.size(200.dp) | |
| ) | |
| // After: LandscapistImage (same API) | |
| LandscapistImage( | |
| model = imageUrl, |
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
| // commonMain: Define expected interface | |
| expect fun createPlatformLandscapist(): Landscapist | |
| // androidMain: Provide Android implementation | |
| actual fun createPlatformLandscapist(): Landscapist { | |
| return Landscapist.builder(applicationContext) | |
| .config(LandscapistConfig(diskCacheSize = 200 * 1024 * 1024L)) | |
| .build() | |
| } |
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
| val imageComponent = rememberImageComponent { | |
| +ShimmerPlugin(Shimmer.Flash()) | |
| +CrossfadePlugin(duration = 500) | |
| +PalettePlugin( | |
| imageModel = imageUrl, | |
| useCache = true, | |
| paletteLoadedListener = { palette -> | |
| dominantColor = palette.dominantSwatch?.rgb | |
| } | |
| ) |
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
| LandscapistImage( | |
| model = imageUrl, | |
| component = rememberImageComponent { | |
| +ShimmerPlugin( | |
| shimmer = Shimmer.Resonate( | |
| baseColor = Color.LightGray, | |
| highlightColor = Color.White | |
| ) | |
| ) | |
| +CrossfadePlugin( |
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
| LandscapistImage( | |
| model = imageUrl, | |
| onImageStateChanged = { state -> | |
| when (state) { | |
| is LandscapistImageState.Loading -> { | |
| analytics.trackImageLoadStart(imageUrl) | |
| } | |
| is LandscapistImageState.Success -> { | |
| analytics.trackImageLoadComplete( | |
| url = imageUrl, |
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
| LandscapistImage( | |
| model = imageUrl, | |
| loading = { | |
| Box(modifier = Modifier.matchParentSize()) { | |
| CircularProgressIndicator( | |
| modifier = Modifier.align(Alignment.Center) | |
| ) | |
| } | |
| }, | |
| success = { state -> |
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
| import com.skydoves.landscapist.image.LandscapistImage | |
| @Composable | |
| fun ProfileImage(imageUrl: String) { | |
| LandscapistImage( | |
| model = imageUrl, | |
| contentDescription = "Profile photo", | |
| modifier = Modifier | |
| .size(120.dp) | |
| .clip(CircleShape), |
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
| // Without explicit size - calculates from Compose constraints | |
| LandscapistImage( | |
| model = "https://example.com/large-image.jpg", | |
| modifier = Modifier.size(200.dp) // Auto-calculates target size | |
| ) | |
| // With explicit size constraint | |
| val request = ImageRequest.builder() | |
| .model(imageUrl) | |
| .size(width = 400, height = 300) // Target size in pixels |
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
| val request = ImageRequest.builder() | |
| .model(imageUrl) | |
| .memoryCachePolicy(CachePolicy.ENABLED) // Read and write | |
| .diskCachePolicy(CachePolicy.READ_ONLY) // Only read, never write | |
| .build() | |
| // Available policies: | |
| // CachePolicy.ENABLED - Read and write (default) | |
| // CachePolicy.READ_ONLY - Only read from cache | |
| // CachePolicy.WRITE_ONLY - Only write to cache |
NewerOlder