Skip to content

Commit

Permalink
Merge pull request #157 from skydoves/feature/imageplugincomponent
Browse files Browse the repository at this point in the history
Introduce ImageComponent and ImagePlugin to conjunct pluggable interfaces
  • Loading branch information
skydoves authored Sep 5, 2022
2 parents af40c31 + 1abb889 commit 4b40e7b
Show file tree
Hide file tree
Showing 17 changed files with 334 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import com.github.skydoves.landscapistdemo.theme.shimmerHighLight
import com.skydoves.landscapist.ShimmerParams
import com.skydoves.landscapist.animation.circular.CircularReveal
import com.skydoves.landscapist.coil.CoilImage
import com.skydoves.landscapist.components.rememberImageComponent
import com.skydoves.landscapist.fresco.FrescoImage
import com.skydoves.landscapist.glide.GlideImage
import com.skydoves.landscapist.palette.BitmapPalette
Expand Down Expand Up @@ -138,9 +139,9 @@ private fun SelectedPoster(
imageModel = poster.poster,
modifier = Modifier
.aspectRatio(0.8f),
imagePlugins = listOf(
CircularReveal()
),
component = rememberImageComponent {
add(CircularReveal())
},
bitmapPalette = BitmapPalette { palette = it },
previewPlaceholder = R.drawable.poster
)
Expand Down Expand Up @@ -252,7 +253,9 @@ private fun HomePoster(
.makeText(context, poster.name, Toast.LENGTH_SHORT)
.show()
},
imagePlugins = listOf(CircularReveal()),
component = rememberImageComponent {
+CircularReveal()
},
shimmerParams = ShimmerParams(
baseColor = background800,
highlightColor = shimmerHighLight
Expand Down
12 changes: 6 additions & 6 deletions coil/api/coil.api
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
public final class com/skydoves/landscapist/coil/CoilImage {
public static final fun CoilImage (Lcoil/request/ImageRequest;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function2;Ljava/util/List;Landroidx/compose/ui/Alignment;Landroidx/compose/ui/layout/ContentScale;Ljava/lang/String;FLandroidx/compose/ui/graphics/ColorFilter;Lcom/skydoves/landscapist/ShimmerParams;Lcom/skydoves/landscapist/palette/BitmapPalette;ILkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Landroidx/compose/runtime/Composer;III)V
public static final fun CoilImage (Lcoil/request/ImageRequest;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function2;Ljava/util/List;Landroidx/compose/ui/Alignment;Landroidx/compose/ui/layout/ContentScale;Ljava/lang/String;FLandroidx/compose/ui/graphics/ColorFilter;Lcom/skydoves/landscapist/palette/BitmapPalette;ILkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Landroidx/compose/runtime/Composer;III)V
public static final fun CoilImage (Ljava/lang/Object;Landroidx/compose/ui/Modifier;Landroid/content/Context;Landroidx/lifecycle/LifecycleOwner;Lkotlin/jvm/functions/Function2;Ljava/util/List;Lcoil/request/ImageRequest$Listener;Landroidx/compose/ui/Alignment;FLandroidx/compose/ui/layout/ContentScale;Ljava/lang/String;Landroidx/compose/ui/graphics/ColorFilter;Lcom/skydoves/landscapist/ShimmerParams;Lcom/skydoves/landscapist/palette/BitmapPalette;Ljava/lang/Object;ILandroidx/compose/runtime/Composer;III)V
public static final fun CoilImage (Ljava/lang/Object;Landroidx/compose/ui/Modifier;Landroid/content/Context;Landroidx/lifecycle/LifecycleOwner;Lkotlin/jvm/functions/Function2;Ljava/util/List;Lcoil/request/ImageRequest$Listener;Landroidx/compose/ui/Alignment;FLandroidx/compose/ui/layout/ContentScale;Ljava/lang/String;Lcom/skydoves/landscapist/palette/BitmapPalette;Landroidx/compose/ui/graphics/ColorFilter;Ljava/lang/Object;Ljava/lang/Object;ILandroidx/compose/runtime/Composer;III)V
public static final fun CoilImage (Ljava/lang/Object;Landroidx/compose/ui/Modifier;Landroid/content/Context;Landroidx/lifecycle/LifecycleOwner;Lkotlin/jvm/functions/Function2;Ljava/util/List;Lcoil/request/ImageRequest$Listener;Landroidx/compose/ui/Alignment;Landroidx/compose/ui/layout/ContentScale;Ljava/lang/String;FLandroidx/compose/ui/graphics/ColorFilter;Lcom/skydoves/landscapist/ShimmerParams;Lcom/skydoves/landscapist/palette/BitmapPalette;ILkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Landroidx/compose/runtime/Composer;III)V
public static final fun CoilImage (Ljava/lang/Object;Landroidx/compose/ui/Modifier;Landroid/content/Context;Landroidx/lifecycle/LifecycleOwner;Lkotlin/jvm/functions/Function2;Ljava/util/List;Lcoil/request/ImageRequest$Listener;Landroidx/compose/ui/Alignment;Landroidx/compose/ui/layout/ContentScale;Ljava/lang/String;FLandroidx/compose/ui/graphics/ColorFilter;Lcom/skydoves/landscapist/palette/BitmapPalette;ILkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Landroidx/compose/runtime/Composer;III)V
public static final fun CoilImage (Lcoil/request/ImageRequest;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function2;Lcom/skydoves/landscapist/components/ImageComponent;Landroidx/compose/ui/Alignment;Landroidx/compose/ui/layout/ContentScale;Ljava/lang/String;FLandroidx/compose/ui/graphics/ColorFilter;Lcom/skydoves/landscapist/ShimmerParams;Lcom/skydoves/landscapist/palette/BitmapPalette;ILkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Landroidx/compose/runtime/Composer;III)V
public static final fun CoilImage (Lcoil/request/ImageRequest;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function2;Lcom/skydoves/landscapist/components/ImageComponent;Landroidx/compose/ui/Alignment;Landroidx/compose/ui/layout/ContentScale;Ljava/lang/String;FLandroidx/compose/ui/graphics/ColorFilter;Lcom/skydoves/landscapist/palette/BitmapPalette;ILkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Landroidx/compose/runtime/Composer;III)V
public static final fun CoilImage (Ljava/lang/Object;Landroidx/compose/ui/Modifier;Landroid/content/Context;Landroidx/lifecycle/LifecycleOwner;Lkotlin/jvm/functions/Function2;Lcom/skydoves/landscapist/components/ImageComponent;Lcoil/request/ImageRequest$Listener;Landroidx/compose/ui/Alignment;FLandroidx/compose/ui/layout/ContentScale;Ljava/lang/String;Landroidx/compose/ui/graphics/ColorFilter;Lcom/skydoves/landscapist/ShimmerParams;Lcom/skydoves/landscapist/palette/BitmapPalette;Ljava/lang/Object;ILandroidx/compose/runtime/Composer;III)V
public static final fun CoilImage (Ljava/lang/Object;Landroidx/compose/ui/Modifier;Landroid/content/Context;Landroidx/lifecycle/LifecycleOwner;Lkotlin/jvm/functions/Function2;Lcom/skydoves/landscapist/components/ImageComponent;Lcoil/request/ImageRequest$Listener;Landroidx/compose/ui/Alignment;FLandroidx/compose/ui/layout/ContentScale;Ljava/lang/String;Lcom/skydoves/landscapist/palette/BitmapPalette;Landroidx/compose/ui/graphics/ColorFilter;Ljava/lang/Object;Ljava/lang/Object;ILandroidx/compose/runtime/Composer;III)V
public static final fun CoilImage (Ljava/lang/Object;Landroidx/compose/ui/Modifier;Landroid/content/Context;Landroidx/lifecycle/LifecycleOwner;Lkotlin/jvm/functions/Function2;Lcom/skydoves/landscapist/components/ImageComponent;Lcoil/request/ImageRequest$Listener;Landroidx/compose/ui/Alignment;Landroidx/compose/ui/layout/ContentScale;Ljava/lang/String;FLandroidx/compose/ui/graphics/ColorFilter;Lcom/skydoves/landscapist/ShimmerParams;Lcom/skydoves/landscapist/palette/BitmapPalette;ILkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Landroidx/compose/runtime/Composer;III)V
public static final fun CoilImage (Ljava/lang/Object;Landroidx/compose/ui/Modifier;Landroid/content/Context;Landroidx/lifecycle/LifecycleOwner;Lkotlin/jvm/functions/Function2;Lcom/skydoves/landscapist/components/ImageComponent;Lcoil/request/ImageRequest$Listener;Landroidx/compose/ui/Alignment;Landroidx/compose/ui/layout/ContentScale;Ljava/lang/String;FLandroidx/compose/ui/graphics/ColorFilter;Lcom/skydoves/landscapist/palette/BitmapPalette;ILkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Landroidx/compose/runtime/Composer;III)V
}

public abstract class com/skydoves/landscapist/coil/CoilImageState {
Expand Down
39 changes: 21 additions & 18 deletions coil/src/main/kotlin/com/skydoves/landscapist/coil/CoilImage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@ import coil.request.ImageRequest
import com.skydoves.landscapist.ImageBySource
import com.skydoves.landscapist.ImageLoad
import com.skydoves.landscapist.ImageLoadState
import com.skydoves.landscapist.ImagePlugin
import com.skydoves.landscapist.Shimmer
import com.skydoves.landscapist.ShimmerParams
import com.skydoves.landscapist.components.ImageComponent
import com.skydoves.landscapist.components.imagePlugins
import com.skydoves.landscapist.components.rememberImageComponent
import com.skydoves.landscapist.palette.BitmapPalette
import com.skydoves.landscapist.plugins.ImagePlugin
import com.skydoves.landscapist.rememberDrawablePainter
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.suspendCancellableCoroutine
Expand Down Expand Up @@ -102,7 +105,7 @@ public fun CoilImage(
context: Context = LocalContext.current,
lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current,
imageLoader: @Composable () -> ImageLoader = { LocalCoilProvider.getCoilImageLoader() },
imagePlugins: List<ImagePlugin> = emptyList(),
component: ImageComponent = rememberImageComponent {},
requestListener: ImageRequest.Listener? = null,
alignment: Alignment = Alignment.Center,
alpha: Float = DefaultAlpha,
Expand All @@ -119,7 +122,7 @@ public fun CoilImage(
context = context,
lifecycleOwner = lifecycleOwner,
imageLoader = imageLoader,
imagePlugins = imagePlugins,
component = component,
requestListener = requestListener,
modifier = modifier,
alignment = alignment,
Expand Down Expand Up @@ -168,7 +171,7 @@ public fun CoilImage(
* @param context The context for creating the [ImageRequest.Builder].
* @param lifecycleOwner The [LifecycleOwner] for constructing the [ImageRequest.Builder].
* @param imageLoader The [ImageLoader] to use when requesting the image.
* @param imagePlugins A list of plugins to be executed for loading images.
* @param component An image component that conjuncts pluggable [ImagePlugin]s.
* @param requestListener A class for monitoring the status of a request while images load.
* @param alignment The alignment parameter used to place the loaded [ImageBitmap] in the image container.
* @param alpha The alpha parameter used to apply for the image when it is rendered onscreen.
Expand All @@ -187,7 +190,7 @@ public fun CoilImage(
context: Context = LocalContext.current,
lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current,
imageLoader: @Composable () -> ImageLoader = { LocalCoilProvider.getCoilImageLoader() },
imagePlugins: List<ImagePlugin> = emptyList(),
component: ImageComponent = rememberImageComponent {},
requestListener: ImageRequest.Listener? = null,
alignment: Alignment = Alignment.Center,
alpha: Float = DefaultAlpha,
Expand All @@ -204,7 +207,7 @@ public fun CoilImage(
context = context,
lifecycleOwner = lifecycleOwner,
imageLoader = imageLoader,
imagePlugins = imagePlugins,
component = component,
requestListener = requestListener,
modifier = modifier,
alignment = alignment,
Expand Down Expand Up @@ -263,7 +266,7 @@ public fun CoilImage(
* @param context The context for creating the [ImageRequest.Builder].
* @param lifecycleOwner The [LifecycleOwner] for constructing the [ImageRequest.Builder].
* @param imageLoader The [ImageLoader] to use when requesting the image.
* @param imagePlugins A list of plugins to be executed for loading images.
* @param component An image component that conjuncts pluggable [ImagePlugin]s.
* @param requestListener A class for monitoring the status of a request while images load.
* @param alignment The alignment parameter used to place the loaded [ImageBitmap] in the image container.
* @param alpha The alpha parameter used to apply for the image when it is rendered onscreen.
Expand All @@ -282,7 +285,7 @@ public fun CoilImage(
context: Context = LocalContext.current,
lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current,
imageLoader: @Composable () -> ImageLoader = { LocalCoilProvider.getCoilImageLoader() },
imagePlugins: List<ImagePlugin> = emptyList(),
component: ImageComponent = rememberImageComponent {},
requestListener: ImageRequest.Listener? = null,
alignment: Alignment = Alignment.Center,
contentScale: ContentScale = ContentScale.Crop,
Expand All @@ -302,7 +305,7 @@ public fun CoilImage(
.lifecycle(lifecycleOwner)
.build(),
imageLoader = imageLoader,
imagePlugins = imagePlugins,
component = component,
modifier = modifier,
alignment = alignment,
contentScale = contentScale,
Expand Down Expand Up @@ -341,7 +344,7 @@ public fun CoilImage(
* @param context The context for creating the [ImageRequest.Builder].
* @param lifecycleOwner The [LifecycleOwner] for constructing the [ImageRequest.Builder].
* @param imageLoader The [ImageLoader] to use when requesting the image.
* @param imagePlugins A list of plugins to be executed for loading images.
* @param component An image component that conjuncts pluggable [ImagePlugin]s.
* @param requestListener A class for monitoring the status of a request while images load.
* @param alignment The alignment parameter used to place the loaded [ImageBitmap] in the image container.
* @param alpha The alpha parameter used to apply for the image when it is rendered onscreen.
Expand All @@ -361,7 +364,7 @@ public fun CoilImage(
context: Context = LocalContext.current,
lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current,
imageLoader: @Composable () -> ImageLoader = { LocalCoilProvider.getCoilImageLoader() },
imagePlugins: List<ImagePlugin> = emptyList(),
component: ImageComponent = rememberImageComponent {},
requestListener: ImageRequest.Listener? = null,
alignment: Alignment = Alignment.Center,
contentScale: ContentScale = ContentScale.Crop,
Expand All @@ -381,7 +384,7 @@ public fun CoilImage(
.lifecycle(lifecycleOwner)
.build(),
imageLoader = imageLoader,
imagePlugins = imagePlugins,
component = component,
modifier = modifier,
alignment = alignment,
contentScale = contentScale,
Expand Down Expand Up @@ -418,7 +421,7 @@ public fun CoilImage(
* @param imageRequest The request to execute.
* @param modifier [Modifier] used to adjust the layout or drawing content.
* @param imageLoader The [ImageLoader] to use when requesting the image.
* @param imagePlugins A list of plugins to be executed for loading images.
* @param component An image component that conjuncts pluggable [ImagePlugin]s.
* @param alignment The alignment parameter used to place the loaded [ImageBitmap] in the image container.
* @param alpha The alpha parameter used to apply for the image when it is rendered onscreen.
* @param contentScale The scale parameter used to determine the aspect ratio scaling to be used for the loaded [ImageBitmap].
Expand All @@ -434,7 +437,7 @@ public fun CoilImage(
imageRequest: ImageRequest,
modifier: Modifier = Modifier,
imageLoader: @Composable () -> ImageLoader = { LocalCoilProvider.getCoilImageLoader() },
imagePlugins: List<ImagePlugin> = emptyList(),
component: ImageComponent = rememberImageComponent {},
alignment: Alignment = Alignment.Center,
contentScale: ContentScale = ContentScale.Crop,
contentDescription: String? = null,
Expand Down Expand Up @@ -488,7 +491,7 @@ public fun CoilImage(
modifier = Modifier.fillMaxSize(),
painter = rememberDrawablePainter(
drawable = drawable,
imagePlugins = imagePlugins
imagePlugins = component.imagePlugins
),
alignment = alignment,
contentScale = contentScale,
Expand Down Expand Up @@ -527,7 +530,7 @@ public fun CoilImage(
* @param imageRequest The request to execute.
* @param modifier [Modifier] used to adjust the layout or drawing content.
* @param imageLoader The [ImageLoader] to use when requesting the image.
* @param imagePlugins A list of plugins to be executed for loading images.
* @param component An image component that conjuncts pluggable [ImagePlugin]s.
* @param alignment The alignment parameter used to place the loaded [ImageBitmap] in the image container.
* @param alpha The alpha parameter used to apply for the image when it is rendered onscreen.
* @param contentScale The scale parameter used to determine the aspect ratio scaling to be used for the loaded [ImageBitmap].
Expand All @@ -544,7 +547,7 @@ public fun CoilImage(
imageRequest: ImageRequest,
modifier: Modifier = Modifier,
imageLoader: @Composable () -> ImageLoader = { LocalCoilProvider.getCoilImageLoader() },
imagePlugins: List<ImagePlugin> = emptyList(),
component: ImageComponent = rememberImageComponent {},
alignment: Alignment = Alignment.Center,
contentScale: ContentScale = ContentScale.Crop,
contentDescription: String? = null,
Expand Down Expand Up @@ -589,7 +592,7 @@ public fun CoilImage(
modifier = Modifier.fillMaxSize(),
painter = rememberDrawablePainter(
drawable = drawable,
imagePlugins = imagePlugins
imagePlugins = component.imagePlugins
),
alignment = alignment,
contentScale = contentScale,
Expand Down
Loading

0 comments on commit 4b40e7b

Please sign in to comment.