Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change previewPlaceholder type to Painter #406

Merged
merged 1 commit into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private fun PosterItem(
component = rememberImageComponent {
+CrossfadePlugin()
},
previewPlaceholder = R.drawable.poster,
previewPlaceholder = painterResource(id = R.drawable.poster),
)
}
}
Expand Down Expand Up @@ -183,7 +183,7 @@ private fun SelectedPoster(
.fillMaxWidth()
.padding(8.dp)
.clip(RoundedCornerShape(8.dp)),
previewPlaceholder = R.drawable.poster,
previewPlaceholder = painterResource(id = R.drawable.poster),
)

Spacer(modifier = Modifier.height(12.dp))
Expand Down Expand Up @@ -219,6 +219,12 @@ private fun ColorPalettes(palette: Palette?) {
@Composable
private fun SelectedPosterPreview() {
DisneyComposeTheme(darkTheme = false) {
SelectedPoster(poster = MockUtil.getMockPoster())
Column(
modifier = Modifier
.fillMaxSize()
.verticalScroll(rememberScrollState()),
) {
SelectedPoster(poster = MockUtil.getMockPoster())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.skydoves.benchmark.landscapist.app
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import com.skydoves.landscapist.ImageOptions
import com.skydoves.landscapist.coil.CoilImage
Expand All @@ -31,7 +32,7 @@ fun CoilImageProfiles() {
"https://user-images.githubusercontent.com/" +
"24237865/75087936-5c1d9f80-553e-11ea-81d3-a912634dd8f7.jpg"
},
previewPlaceholder = R.drawable.poster,
previewPlaceholder = painterResource(id = R.drawable.poster),
component = LocalImageComponent.current,
imageOptions = ImageOptions(tag = "CoilImage"),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.skydoves.benchmark.landscapist.app
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import com.skydoves.landscapist.ImageOptions
import com.skydoves.landscapist.components.LocalImageComponent
Expand All @@ -29,7 +30,7 @@ fun FrescoImageProfiles() {
modifier = Modifier.size(120.dp),
imageUrl = "https://user-images.githubusercontent.com/" +
"24237865/75087936-5c1d9f80-553e-11ea-81d3-a912634dd8f7.jpg",
previewPlaceholder = R.drawable.poster,
previewPlaceholder = painterResource(id = R.drawable.poster),
component = LocalImageComponent.current,
imageOptions = ImageOptions(tag = "FrescoImage"),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.skydoves.benchmark.landscapist.app
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import com.skydoves.landscapist.ImageOptions
import com.skydoves.landscapist.components.LocalImageComponent
Expand All @@ -31,7 +32,7 @@ fun GlideImageProfiles() {
"https://user-images.githubusercontent.com/" +
"24237865/75087936-5c1d9f80-553e-11ea-81d3-a912634dd8f7.jpg"
},
previewPlaceholder = R.drawable.poster,
previewPlaceholder = painterResource(id = R.drawable.poster),
component = LocalImageComponent.current,
imageOptions = ImageOptions(tag = "GlideImage"),
)
Expand Down
4 changes: 2 additions & 2 deletions coil/api/coil.api
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
public final class com/skydoves/landscapist/coil/CoilImage {
public static final fun CoilImage (Lkotlin/jvm/functions/Function0;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function2;Lcom/skydoves/landscapist/components/ImageComponent;Lcom/skydoves/landscapist/ImageOptions;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function5;Lkotlin/jvm/functions/Function4;Landroidx/compose/runtime/Composer;II)V
public static final fun CoilImage (Lkotlin/jvm/functions/Function0;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function2;Lcom/skydoves/landscapist/components/ImageComponent;Lkotlin/jvm/functions/Function0;Lcom/skydoves/landscapist/ImageOptions;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function5;Lkotlin/jvm/functions/Function4;Landroidx/compose/runtime/Composer;III)V
public static final fun CoilImage (Lkotlin/jvm/functions/Function0;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function2;Lcom/skydoves/landscapist/components/ImageComponent;Lcom/skydoves/landscapist/ImageOptions;Lkotlin/jvm/functions/Function1;Landroidx/compose/ui/graphics/painter/Painter;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function5;Lkotlin/jvm/functions/Function4;Landroidx/compose/runtime/Composer;II)V
public static final fun CoilImage (Lkotlin/jvm/functions/Function0;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function2;Lcom/skydoves/landscapist/components/ImageComponent;Lkotlin/jvm/functions/Function0;Lcom/skydoves/landscapist/ImageOptions;Lkotlin/jvm/functions/Function1;Landroidx/compose/ui/graphics/painter/Painter;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function5;Lkotlin/jvm/functions/Function4;Landroidx/compose/runtime/Composer;III)V
}

public abstract class com/skydoves/landscapist/coil/CoilImageState : com/skydoves/landscapist/ImageState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.IntSize
import androidx.core.graphics.drawable.toBitmap
import coil.ImageLoader
Expand Down Expand Up @@ -95,7 +94,7 @@ import java.nio.ByteBuffer
* @param requestListener A class for monitoring the status of a request while images load.
* @param imageOptions Represents parameters to load generic [Image] Composable.
* @param onImageStateChanged An image state change listener will be triggered whenever the image state is changed.
* @param previewPlaceholder Drawable resource ID which will be displayed when this function is ran in preview mode.
* @param previewPlaceholder A painter that is specifically rendered when this function operates in preview mode.
* @param loading Content to be displayed when the request is in progress.
* @param success Content to be displayed when the request is succeeded.
* @param failure Content to be displayed when the request is failed.
Expand All @@ -109,7 +108,7 @@ public fun CoilImage(
requestListener: (() -> ImageRequest.Listener)? = null,
imageOptions: ImageOptions = ImageOptions(),
onImageStateChanged: (CoilImageState) -> Unit = {},
@DrawableRes previewPlaceholder: Int = 0,
previewPlaceholder: Painter? = null,
loading: @Composable (BoxScope.(imageState: CoilImageState.Loading) -> Unit)? = null,
success: @Composable (
BoxScope.(
Expand Down Expand Up @@ -171,7 +170,7 @@ public fun CoilImage(
* @param component An image component that conjuncts pluggable [ImagePlugin]s.
* @param imageOptions Represents parameters to load generic [Image] Composable.
* @param onImageStateChanged An image state change listener will be triggered whenever the image state is changed.
* @param previewPlaceholder Drawable resource ID which will be displayed when this function is ran in preview mode.
* @param previewPlaceholder A painter that is specifically rendered when this function operates in preview mode.
* @param loading Content to be displayed when the request is in progress.
* @param success Content to be displayed when the request is succeeded.
* @param failure Content to be displayed when the request is failed.
Expand All @@ -184,7 +183,7 @@ public fun CoilImage(
component: ImageComponent = rememberImageComponent {},
imageOptions: ImageOptions = ImageOptions(),
onImageStateChanged: (CoilImageState) -> Unit = {},
@DrawableRes previewPlaceholder: Int = 0,
previewPlaceholder: Painter? = null,
loading: @Composable (BoxScope.(imageState: CoilImageState.Loading) -> Unit)? = null,
success: @Composable (
BoxScope.(
Expand All @@ -194,11 +193,11 @@ public fun CoilImage(
)? = null,
failure: @Composable (BoxScope.(imageState: CoilImageState.Failure) -> Unit)? = null,
) {
if (LocalInspectionMode.current && previewPlaceholder != 0) {
if (LocalInspectionMode.current && previewPlaceholder != null) {
with(imageOptions) {
Image(
modifier = modifier,
painter = painterResource(id = previewPlaceholder),
painter = previewPlaceholder,
alignment = alignment,
contentScale = contentScale,
alpha = alpha,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ import kotlinx.coroutines.flow.channelFlow
* @param requestListener A class for monitoring the status of a request while images load.
* @param imageOptions Represents parameters to load generic [Image] Composable.
* @param onImageStateChanged An image state change listener will be triggered whenever the image state is changed.
* @param previewPlaceholder Drawable resource ID which will be displayed when this function is ran in preview mode.
* @param previewPlaceholder A painter that is specifically rendered when this function operates in preview mode.
* @param loading Content to be displayed when the request is in progress.
* @param success Content to be displayed when the request is succeeded.
* @param failure Content to be displayed when the request is failed.
Expand Down Expand Up @@ -149,7 +149,7 @@ public fun CoilImage(
* @param component An image component that conjuncts pluggable [ImagePlugin]s.
* @param imageOptions Represents parameters to load generic [Image] Composable.
* @param onImageStateChanged An image state change listener will be triggered whenever the image state is changed.
* @param previewPlaceholder Drawable resource ID which will be displayed when this function is ran in preview mode.
* @param previewPlaceholder A painter that is specifically rendered when this function operates in preview mode.
* @param loading Content to be displayed when the request is in progress.
* @param success Content to be displayed when the request is succeeded.
* @param failure Content to be displayed when the request is failed.
Expand Down
2 changes: 1 addition & 1 deletion fresco/api/fresco.api
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public final class com/skydoves/landscapist/fresco/ComposableSingletons$FrescoIm
}

public final class com/skydoves/landscapist/fresco/FrescoImage {
public static final fun FrescoImage (Ljava/lang/String;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function2;Lcom/skydoves/landscapist/components/ImageComponent;Lcom/skydoves/landscapist/ImageOptions;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function5;Lkotlin/jvm/functions/Function4;Landroidx/compose/runtime/Composer;II)V
public static final fun FrescoImage (Ljava/lang/String;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function2;Lcom/skydoves/landscapist/components/ImageComponent;Lcom/skydoves/landscapist/ImageOptions;Lkotlin/jvm/functions/Function1;Landroidx/compose/ui/graphics/painter/Painter;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function5;Lkotlin/jvm/functions/Function4;Landroidx/compose/runtime/Composer;II)V
}

public abstract class com/skydoves/landscapist/fresco/FrescoImageState : com/skydoves/landscapist/ImageState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package com.skydoves.landscapist.fresco

import androidx.annotation.DrawableRes
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.BoxWithConstraintsScope
Expand All @@ -30,7 +29,6 @@ import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.IntSize
import com.facebook.common.executors.CallerThreadExecutor
import com.facebook.drawee.backends.pipeline.info.ImageOriginRequestListener
Expand Down Expand Up @@ -80,7 +78,7 @@ import kotlinx.coroutines.suspendCancellableCoroutine
* @param success Content to be displayed when the request is succeeded.
* @param failure Content to be displayed when the request is failed.
* @param onImageStateChanged An image state change listener will be triggered whenever the image state is changed.ø
* @param previewPlaceholder Drawable resource ID which will be displayed when this function is ran in preview mode.
* @param previewPlaceholder A painter that is specifically rendered when this function operates in preview mode.
*/
@Composable
public fun FrescoImage(
Expand All @@ -92,7 +90,7 @@ public fun FrescoImage(
component: ImageComponent = rememberImageComponent {},
imageOptions: ImageOptions = ImageOptions(),
onImageStateChanged: (FrescoImageState) -> Unit = {},
@DrawableRes previewPlaceholder: Int = 0,
previewPlaceholder: Painter? = null,
loading: @Composable (BoxScope.(imageState: FrescoImageState.Loading) -> Unit)? = null,
success: @Composable (
BoxScope.(
Expand All @@ -102,11 +100,11 @@ public fun FrescoImage(
)? = null,
failure: @Composable (BoxScope.(imageState: FrescoImageState.Failure) -> Unit)? = null,
) {
if (LocalInspectionMode.current && previewPlaceholder != 0) {
if (LocalInspectionMode.current && previewPlaceholder != null) {
with(imageOptions) {
Image(
modifier = modifier,
painter = painterResource(id = previewPlaceholder),
painter = previewPlaceholder,
alignment = alignment,
contentScale = contentScale,
alpha = alpha,
Expand Down
2 changes: 1 addition & 1 deletion glide/api/glide.api
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public final class com/skydoves/landscapist/glide/ComposableSingletons$GlideImag
}

public final class com/skydoves/landscapist/glide/GlideImage {
public static final fun GlideImage (Lkotlin/jvm/functions/Function0;Landroidx/compose/ui/Modifier;Lcom/skydoves/landscapist/glide/GlideRequestType;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function0;Lcom/skydoves/landscapist/components/ImageComponent;Lcom/skydoves/landscapist/ImageOptions;ZLkotlin/jvm/functions/Function1;ILkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function5;Lkotlin/jvm/functions/Function4;Landroidx/compose/runtime/Composer;III)V
public static final fun GlideImage (Lkotlin/jvm/functions/Function0;Landroidx/compose/ui/Modifier;Lcom/skydoves/landscapist/glide/GlideRequestType;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function0;Lcom/skydoves/landscapist/components/ImageComponent;Lcom/skydoves/landscapist/ImageOptions;ZLkotlin/jvm/functions/Function1;Landroidx/compose/ui/graphics/painter/Painter;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function5;Lkotlin/jvm/functions/Function4;Landroidx/compose/runtime/Composer;III)V
}

public abstract class com/skydoves/landscapist/glide/GlideImageState : com/skydoves/landscapist/ImageState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package com.skydoves.landscapist.glide

import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import androidx.annotation.DrawableRes
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.BoxWithConstraintsScope
Expand All @@ -30,7 +29,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.IntSize
import com.bumptech.glide.RequestBuilder
import com.bumptech.glide.RequestManager
Expand Down Expand Up @@ -92,7 +90,7 @@ import kotlinx.coroutines.flow.callbackFlow
* @param imageOptions Represents parameters to load generic [Image] Composable.
* @param clearTarget Whether clear the target or not.
* @param onImageStateChanged An image state change listener will be triggered whenever the image state is changed.
* @param previewPlaceholder Drawable resource ID which will be displayed when this function is ran in preview mode.
* @param previewPlaceholder A painter that is specifically rendered when this function operates in preview mode.
* @param loading Content to be displayed when the request is in progress.
* @param success Content to be displayed when the request is succeeded.
* @param failure Content to be displayed when the request is failed.
Expand All @@ -113,7 +111,7 @@ public fun GlideImage(
imageOptions: ImageOptions = ImageOptions(),
clearTarget: Boolean = false,
onImageStateChanged: (GlideImageState) -> Unit = {},
@DrawableRes previewPlaceholder: Int = 0,
previewPlaceholder: Painter? = null,
loading: @Composable (BoxScope.(imageState: GlideImageState.Loading) -> Unit)? = null,
success: @Composable (
BoxScope.(
Expand All @@ -123,11 +121,11 @@ public fun GlideImage(
)? = null,
failure: @Composable (BoxScope.(imageState: GlideImageState.Failure) -> Unit)? = null,
) {
if (LocalInspectionMode.current && previewPlaceholder != 0) {
if (LocalInspectionMode.current && previewPlaceholder != null) {
with(imageOptions) {
Image(
modifier = modifier,
painter = painterResource(id = previewPlaceholder),
painter = previewPlaceholder,
alignment = alignment,
contentScale = contentScale,
alpha = alpha,
Expand Down