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
| @Stable | |
| public class ImagePluginComponent( | |
| internal val mutablePlugins: MutableList<ImagePlugin> = mutableListOf(), | |
| ) : ImageComponent { | |
| public val plugins: List<ImagePlugin> | |
| inline get() = mutablePlugins | |
| public fun add(imagePlugin: ImagePlugin): ImagePluginComponent = apply { | |
| mutablePlugins.add(imagePlugin) |
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
| public interface SuccessStatePlugin : ImagePlugin { | |
| @Composable | |
| public fun compose( | |
| modifier: Modifier, | |
| imageModel: Any?, | |
| imageOptions: ImageOptions, | |
| imageBitmap: ImageBitmap?, | |
| ): ImagePlugin | |
| } |
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
| @Immutable | |
| public sealed interface ImagePlugin { | |
| public interface PainterPlugin : ImagePlugin { | |
| @Composable | |
| public fun compose(imageBitmap: ImageBitmap, painter: Painter): Painter | |
| } | |
| public interface LoadingStatePlugin : ImagePlugin { | |
| @Composable |
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( | |
| imageModel = { imageUrl }, | |
| component = rememberImageComponent { | |
| +ShimmerPlugin() // attach shimmer during loading | |
| +CircularRevealPlugin() // attach reveal animation on success | |
| +PalettePlugin { palette -> } // attach color extraction | |
| }, | |
| ) |
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( | |
| imageModel = { imageUrl }, | |
| loading = { | |
| // manually build shimmer UI | |
| }, | |
| success = { imageState, painter -> | |
| // manually animate circular reveal | |
| // manually extract palette colors | |
| }, | |
| failure = { |
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 | |
| public fun LandscapistImage( | |
| imageModel: () -> Any?, | |
| modifier: Modifier = Modifier, | |
| component: ImageComponent = rememberImageComponent {}, | |
| imageOptions: ImageOptions = ImageOptions(), | |
| loading: @Composable (BoxScope.(LandscapistImageState.Loading) -> Unit)? = null, | |
| success: @Composable (BoxScope.(LandscapistImageState.Success, Painter) -> Unit)? = null, | |
| failure: @Composable (BoxScope.(LandscapistImageState.Failure) -> Unit)? = null, | |
| ) |
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
| public final class ExtensionFunctionKt { | |
| public static String addExclamation(String receiver) { | |
| return receiver + "!"; | |
| } | |
| } |
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
| fun String.addExclamation(): String { | |
| return this + "!" | |
| } | |
| fun main() { | |
| val result = "skydoves".addExclamation() | |
| println(result) // Output: skydoves! | |
| } |
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
| int result = 10 * 2; |
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
| inline fun inlineHigherOrderExample(operation: (Int) -> Int): Int { | |
| return operation(10) | |
| } | |
| val result = inlineHigherOrderExample { it * 2 } |