Skip to content

Commit

Permalink
Add a Transition API and a CrossFade Transition for Compose
Browse files Browse the repository at this point in the history
Similar to Glide's existing Transitions, but intended for use with
Animatable instead of views. I've started with a simple CrossFade. We
probably should add at least a FadeOnTopOf (or something similar) to
mimic the existing Crossfade support.
  • Loading branch information
sjudd committed Aug 14, 2023
1 parent 60b567e commit 553b2d5
Show file tree
Hide file tree
Showing 4 changed files with 327 additions and 39 deletions.
38 changes: 37 additions & 1 deletion integration/compose/api/compose.api
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
public final class com/bumptech/glide/integration/compose/CrossFade : com/bumptech/glide/integration/compose/Transition {
public static final field $stable I
public static final field OPAQUE_ALPHA I
public synthetic fun <init> (Landroidx/compose/animation/core/AnimationSpec;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun getDrawCurrent ()Lkotlin/jvm/functions/Function2;
public fun getDrawPlaceholder ()Lkotlin/jvm/functions/Function2;
public fun stop (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun transition (Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}

public final class com/bumptech/glide/integration/compose/CrossFade$Factory : com/bumptech/glide/integration/compose/Transition$Factory {
public static final field $stable I
public static final field Companion Lcom/bumptech/glide/integration/compose/CrossFade$Factory$Companion;
public fun <init> ()V
public fun <init> (Landroidx/compose/animation/core/AnimationSpec;)V
public synthetic fun <init> (Landroidx/compose/animation/core/AnimationSpec;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun build ()Lcom/bumptech/glide/integration/compose/Transition;
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
}

public final class com/bumptech/glide/integration/compose/CrossFade$Factory$Companion {
public final fun getDEFAULT ()Lcom/bumptech/glide/integration/compose/CrossFade$Factory;
}

public abstract interface annotation class com/bumptech/glide/integration/compose/ExperimentalGlideComposeApi : java/lang/annotation/Annotation {
}

public final class com/bumptech/glide/integration/compose/GlideImageKt {
public static final fun GlideImage (Ljava/lang/Object;Ljava/lang/String;Landroidx/compose/ui/Modifier;Landroidx/compose/ui/Alignment;Landroidx/compose/ui/layout/ContentScale;FLandroidx/compose/ui/graphics/ColorFilter;Lcom/bumptech/glide/integration/compose/Placeholder;Lcom/bumptech/glide/integration/compose/Placeholder;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;II)V
public static final fun GlideImage (Ljava/lang/Object;Ljava/lang/String;Landroidx/compose/ui/Modifier;Landroidx/compose/ui/Alignment;Landroidx/compose/ui/layout/ContentScale;FLandroidx/compose/ui/graphics/ColorFilter;Lcom/bumptech/glide/integration/compose/Placeholder;Lcom/bumptech/glide/integration/compose/Placeholder;Lcom/bumptech/glide/integration/compose/Transition$Factory;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;III)V
public static final fun GlideSubcomposition (Ljava/lang/Object;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function3;Landroidx/compose/runtime/Composer;II)V
public static final fun placeholder (I)Lcom/bumptech/glide/integration/compose/Placeholder;
public static final fun placeholder (Landroid/graphics/drawable/Drawable;)Lcom/bumptech/glide/integration/compose/Placeholder;
Expand Down Expand Up @@ -54,3 +79,14 @@ public final class com/bumptech/glide/integration/compose/RequestState$Success :
public fun toString ()Ljava/lang/String;
}

public abstract interface class com/bumptech/glide/integration/compose/Transition {
public abstract fun getDrawCurrent ()Lkotlin/jvm/functions/Function2;
public abstract fun getDrawPlaceholder ()Lkotlin/jvm/functions/Function2;
public abstract fun stop (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun transition (Lkotlin/jvm/functions/Function0;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}

public abstract interface class com/bumptech/glide/integration/compose/Transition$Factory {
public abstract fun build ()Lcom/bumptech/glide/integration/compose/Transition;
}

Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ public typealias RequestBuilderTransform<T> = (RequestBuilder<T>) -> RequestBuil
* opposed to resource id or [Drawable]), this [Placeholder] will not be used unless the `error`
* [RequestBuilder] also fails. This parameter does not override error [RequestBuilder]s, only error
* resource ids and/or [Drawable]s.
* @param transition An optional [TransitionFactory] that can animate the transition from a
* placeholder to a loaded image. The transition will only be called once, when the load transitions
* from showing the placeholder to showing the first resource. The transition will persist across
* multiple resources if you're using thumbnail, but will not be called for each successive resource
* in the request chain. The transition factory will not be called across different requests if
* multiple are made. The transition will not be called if you use [placeholder] or [failure] with
* the deprecated [Composable] API. See [CrossFade]
*/
// TODO(judds): the API here is not particularly composeesque, we should consider alternatives
// to RequestBuilder (though thumbnail() may make that a challenge).
Expand All @@ -104,6 +111,7 @@ public fun GlideImage(
// See http://shortn/_x79pjkMZIH for an internal discussion.
loading: Placeholder? = null,
failure: Placeholder? = null,
transition: Transition.Factory? = null,
// TODO(judds): Consider defaulting to load the model here instead of always doing so below.
requestBuilderTransform: RequestBuilderTransform<Drawable> = { it },
) {
Expand Down Expand Up @@ -154,6 +162,7 @@ public fun GlideImage(
contentScale,
alpha,
colorFilter,
transition,
)
}
}
Expand Down Expand Up @@ -482,7 +491,8 @@ private fun ModifierGlideImage(
alignment: Alignment,
contentScale: ContentScale,
alpha: Float,
colorFilter: ColorFilter?
colorFilter: ColorFilter?,
transitionFactory: Transition.Factory?,
) {
Layout(
{},
Expand All @@ -495,6 +505,7 @@ private fun ModifierGlideImage(
contentScale,
alpha,
colorFilter,
transitionFactory,
)
) { _, constraints ->
layout(constraints.minWidth, constraints.minHeight) {}
Expand Down
Loading

0 comments on commit 553b2d5

Please sign in to comment.