Skip to content

Instantly share code, notes, and snippets.

View skydoves's full-sized avatar
💡
Practice is the only shortcut

Jaewoong Eum skydoves

💡
Practice is the only shortcut
View GitHub Profile
@skydoves
skydoves / ImagePluginComponent.kt
Created March 28, 2026 01:14
ImagePluginComponent DSL
@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)
@skydoves
skydoves / ImagePluginPart2.kt
Created March 28, 2026 01:14
ImagePlugin sealed interface - SuccessStatePlugin, FailureStatePlugin, ComposablePlugin
public interface SuccessStatePlugin : ImagePlugin {
@Composable
public fun compose(
modifier: Modifier,
imageModel: Any?,
imageOptions: ImageOptions,
imageBitmap: ImageBitmap?,
): ImagePlugin
}
@skydoves
skydoves / ImagePluginPart1.kt
Created March 28, 2026 01:14
ImagePlugin sealed interface - PainterPlugin and LoadingStatePlugin
@Immutable
public sealed interface ImagePlugin {
public interface PainterPlugin : ImagePlugin {
@Composable
public fun compose(imageBitmap: ImageBitmap, painter: Painter): Painter
}
public interface LoadingStatePlugin : ImagePlugin {
@Composable
@skydoves
skydoves / PluginAttachDetach.kt
Created March 28, 2026 01:14
Plugin attach/detach with + operator
LandscapistImage(
imageModel = { imageUrl },
component = rememberImageComponent {
+ShimmerPlugin() // attach shimmer during loading
+CircularRevealPlugin() // attach reveal animation on success
+PalettePlugin { palette -> } // attach color extraction
},
)
@skydoves
skydoves / ManualImageLoading.kt
Created March 28, 2026 01:14
Manual image loading without plugins
LandscapistImage(
imageModel = { imageUrl },
loading = {
// manually build shimmer UI
},
success = { imageState, painter ->
// manually animate circular reveal
// manually extract palette colors
},
failure = {
@skydoves
skydoves / LandscapistImageSignature.kt
Created March 28, 2026 01:14
LandscapistImage composable signature
@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,
)
@skydoves
skydoves / 17_ExtensionFunctionDecompiled.java
Created February 17, 2026 01:14
Decompiled Extension Function - Static Method
public final class ExtensionFunctionKt {
public static String addExclamation(String receiver) {
return receiver + "!";
}
}
@skydoves
skydoves / 16_ExtensionFunction.kt
Created February 17, 2026 01:14
Kotlin Extension Function
fun String.addExclamation(): String {
return this + "!"
}
fun main() {
val result = "skydoves".addExclamation()
println(result) // Output: skydoves!
}
@skydoves
skydoves / 15_InlineFunctionDecompiled.java
Created February 17, 2026 01:14
Decompiled Inline Function - Zero Allocation
int result = 10 * 2;
@skydoves
skydoves / 14_InlineFunction.kt
Created February 17, 2026 01:14
Kotlin Inline Function
inline fun inlineHigherOrderExample(operation: (Int) -> Int): Int {
return operation(10)
}
val result = inlineHigherOrderExample { it * 2 }