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 / ZoomablePlugin.kt
Created March 28, 2026 01:15
ZoomablePlugin implementation
@Immutable
public data class ZoomablePlugin(
public val state: ZoomableState? = null,
public val enabled: Boolean = true,
public val onTransformChanged: ((ContentTransformation) -> Unit)? = null,
) : ImagePlugin.ComposablePlugin {
@Composable
override fun compose(content: @Composable () -> Unit) {
val zoomableState = state ?: rememberZoomableState()
@skydoves
skydoves / PalettePluginCompose.kt
Created March 28, 2026 01:14
PalettePlugin compose function
@Composable
override fun compose(
modifier: Modifier,
imageModel: Any?,
imageOptions: ImageOptions,
imageBitmap: ImageBitmap?,
): ImagePlugin =
apply {
if (LocalInspectionMode.current) return@apply
@skydoves
skydoves / PalettePluginDefinition.kt
Created March 28, 2026 01:14
PalettePlugin implementation - class definition
@Immutable
public data class PalettePlugin(
private val imageModel: Any? = null,
private val useCache: Boolean = true,
private val interceptor: PaletteBuilderInterceptor? = null,
private val paletteLoadedListener: PaletteLoadedListener? = null,
) : ImagePlugin.SuccessStatePlugin {
private val bitmapPalette = BitmapPalette(
imageModel = imageModel,
@skydoves
skydoves / BlurTransformationPlugin.kt
Created March 28, 2026 01:14
BlurTransformationPlugin implementation
@Immutable
public data class BlurTransformationPlugin(
public val radius: Int = 10,
) : ImagePlugin.PainterPlugin {
@Composable
override fun compose(imageBitmap: ImageBitmap, painter: Painter): Painter {
return painter.rememberBlurPainter(
imageBitmap = imageBitmap,
radius = radius,
@skydoves
skydoves / CircularRevealPlugin.kt
Created March 28, 2026 01:14
CircularRevealPlugin implementation
@Immutable
public data class CircularRevealPlugin(
public val duration: Int = DefaultCircularRevealDuration,
public val onFinishListener: CircularRevealFinishListener? = null,
) : ImagePlugin.PainterPlugin {
@Composable
override fun compose(imageBitmap: ImageBitmap, painter: Painter): Painter {
return painter.rememberCircularRevealPainter(
imageBitmap = imageBitmap,
@skydoves
skydoves / ShimmerPlugin.kt
Created March 28, 2026 01:14
ShimmerPlugin implementation
@Immutable
public data class ShimmerPlugin(
val shimmer: Shimmer = Shimmer.Flash(
baseColor = Color.DarkGray,
highlightColor = Color.LightGray,
),
) : ImagePlugin.LoadingStatePlugin {
@Composable
override fun compose(
@skydoves
skydoves / PlaceholderPluginFailure.kt
Created March 28, 2026 01:14
PlaceholderPlugin.Failure implementation
public data class Failure(val source: Any?) :
PlaceholderPlugin(),
ImagePlugin.FailureStatePlugin {
@Composable
override fun compose(
modifier: Modifier,
imageOptions: ImageOptions,
reason: Throwable?,
): ImagePlugin = apply {
@skydoves
skydoves / PlaceholderPluginLoading.kt
Created March 28, 2026 01:14
PlaceholderPlugin.Loading implementation
public data class Loading(val source: Any?) :
PlaceholderPlugin(),
ImagePlugin.LoadingStatePlugin {
@Composable
override fun compose(
modifier: Modifier,
imageOptions: ImageOptions,
executor: @Composable (IntSize) -> Unit,
): ImagePlugin = apply {
@skydoves
skydoves / ThreePluginsExample.kt
Created March 28, 2026 01:14
Three plugins usage example
LandscapistImage(
imageModel = { imageUrl },
component = rememberImageComponent {
+ShimmerPlugin()
+CircularRevealPlugin(duration = 500)
+PalettePlugin(paletteLoadedListener = { palette -> })
},
)
@skydoves
skydoves / RememberImageComponent.kt
Created March 28, 2026 01:14
rememberImageComponent function
@Composable
public fun rememberImageComponent(
block: @Composable ImagePluginComponent.() -> Unit,
): ImagePluginComponent {
val imageComponent = imageComponent(block)
return remember { imageComponent }
}