Skip to content

Commit

Permalink
Add AllProperties model equality delegate.
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrtwhite committed Oct 26, 2024
1 parent 2b8bda7 commit cab1e5e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions coil-compose-core/api/android/coil-compose-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public final class coil3/compose/AsyncImageKt {
}

public abstract interface class coil3/compose/AsyncImageModelEqualityDelegate {
public static final field AllProperties Lcoil3/compose/AsyncImageModelEqualityDelegate;
public static final field Companion Lcoil3/compose/AsyncImageModelEqualityDelegate$Companion;
public static final field Default Lcoil3/compose/AsyncImageModelEqualityDelegate;
public abstract fun equals (Ljava/lang/Object;Ljava/lang/Object;)Z
Expand Down
2 changes: 2 additions & 0 deletions coil-compose-core/api/coil-compose-core.klib.api
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ abstract interface coil3.compose/AsyncImageModelEqualityDelegate { // coil3.comp
abstract fun hashCode(kotlin/Any?): kotlin/Int // coil3.compose/AsyncImageModelEqualityDelegate.hashCode|hashCode(kotlin.Any?){}[0]

final object Companion { // coil3.compose/AsyncImageModelEqualityDelegate.Companion|null[0]
final val AllProperties // coil3.compose/AsyncImageModelEqualityDelegate.Companion.AllProperties|{}AllProperties[0]
final fun <get-AllProperties>(): coil3.compose/AsyncImageModelEqualityDelegate // coil3.compose/AsyncImageModelEqualityDelegate.Companion.AllProperties.<get-AllProperties>|<get-AllProperties>(){}[0]
final val Default // coil3.compose/AsyncImageModelEqualityDelegate.Companion.Default|{}Default[0]
final fun <get-Default>(): coil3.compose/AsyncImageModelEqualityDelegate // coil3.compose/AsyncImageModelEqualityDelegate.Companion.Default.<get-Default>|<get-Default>(){}[0]
}
Expand Down
1 change: 1 addition & 0 deletions coil-compose-core/api/jvm/coil-compose-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public final class coil3/compose/AsyncImageKt {
}

public abstract interface class coil3/compose/AsyncImageModelEqualityDelegate {
public static final field AllProperties Lcoil3/compose/AsyncImageModelEqualityDelegate;
public static final field Companion Lcoil3/compose/AsyncImageModelEqualityDelegate$Companion;
public static final field Default Lcoil3/compose/AsyncImageModelEqualityDelegate;
public abstract fun equals (Ljava/lang/Object;Ljava/lang/Object;)Z
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package coil3.compose

import androidx.compose.runtime.remember
import androidx.compose.runtime.Stable
import androidx.compose.runtime.staticCompositionLocalOf
import coil3.annotation.ExperimentalCoilApi
Expand All @@ -16,7 +17,7 @@ val LocalAsyncImageModelEqualityDelegate = staticCompositionLocalOf {
* Determines equality between two models.
*
* This allows you to control when [rememberAsyncImagePainter], [AsyncImage], and
* [SubcomposeAsyncImage] execute a new request and recompose due to a `model` change.
* [SubcomposeAsyncImage] execute a new request and recompose due to a model change.
*/
@ExperimentalCoilApi
@Stable
Expand All @@ -25,7 +26,11 @@ interface AsyncImageModelEqualityDelegate {
fun hashCode(self: Any?): Int

companion object {
@JvmField val Default: AsyncImageModelEqualityDelegate = object : AsyncImageModelEqualityDelegate {
/**
* The default model equality delegate that only compares a subset of [ImageRequest]'s
* properties instead of delegating to its own [equals] and [hashCode] implementations.
*/
@JvmField val Default = object : AsyncImageModelEqualityDelegate {

override fun equals(self: Any?, other: Any?): Boolean {
if (this === other) return true
Expand Down Expand Up @@ -53,6 +58,22 @@ interface AsyncImageModelEqualityDelegate {
result = 31 * result + self.precision.hashCode()
return result
}

override fun toString(): String {
return "AsyncImageModelEqualityDelegate.Default"
}
}

/**
* A model equality delegate that always delegates to the model's [equals] and [hashCode].
* If the model is an [ImageRequest] this will compare all of its properties and this may
* cause recompositions than necessary. Consider [remember]ing your [ImageRequest]s if you
* use this model equality delegate.
*/
@JvmField val AllProperties = object : AsyncImageModelEqualityDelegate {
override fun equals(self: Any?, other: Any?) = self == other
override fun hashCode(self: Any?) = self.hashCode()
override fun toString() = "AsyncImageModelEqualityDelegate.AllProperties"
}
}
}
Expand Down

0 comments on commit cab1e5e

Please sign in to comment.