Skip to content

Commit e63c5d2

Browse files
committedDec 15, 2022
Change Glide's preloading API to be data based
By data based we mean that we preload based on access to the data, rather than the position of the user in the view. Data based access matches how the Compose paging API works and is much simpler to implement in safe / reasonable way. The primary compromise is that we cannot begin preloading until the data is accessed. If there are multiple disjoint data sets or multiple header rows, we may not preload data while scrolling until we reach the first item in each data set. Users can work around this in each application by manually accessing the prealoding data set, but it's not super convenient. Another option would be to wrap LazyListState and track each insertion via item / items. That would let our preloader track exactly which positions are preloadable and which are not. While the functionality is somewhat better and it's safe, the implementation is much larger and it's more complex for callers to call correctly. We can add it in later if we find that the data based API is painful to use. Yet another option would be to more faithfully implement the ListPreloader interface and rely on users to paper over more gaps, just as we do for non-Compose code. This is significantly more complex for users to implement. We've discussed a few options for this API here: https://chat.google.com/room/AAAAYRnp4-Y/Q61ILNtb8hu
1 parent 18bba92 commit e63c5d2

File tree

9 files changed

+483
-369
lines changed

9 files changed

+483
-369
lines changed
 

‎gradle.properties

+3-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ ANDROID_X_ANNOTATION_VERSION=1.3.0
5656
ANDROID_X_APPCOMPAT_VERSION=1.3.1
5757
ANDROID_X_BENCHMARK_VERSION=1.1.0
5858
ANDROID_X_CARDVIEW_VERSION=1.0.0
59-
ANDROID_X_COMPOSE_VERSION=1.2.1
59+
ANDROID_X_COMPOSE_VERSION=1.3.2
60+
ANDROID_X_COMPOSE_FOUNDATION_VERSION=1.3.1
61+
ANDROID_X_COMPOSE_MATERIAL_VERSION=1.3.1
6062
ANDROID_X_CONCURRENT_FUTURES_VERSION=1.1.0
6163
ANDROID_X_CORE_VERSION=1.6.0
6264
ANDROID_X_EXIF_INTERFACE_VERSION=1.3.3

‎integration/compose/api/compose.api

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@ public final class com/bumptech/glide/integration/compose/GlideImageKt {
88
public static final fun placeholder (Lkotlin/jvm/functions/Function2;)Lcom/bumptech/glide/integration/compose/Placeholder;
99
}
1010

11+
public abstract interface class com/bumptech/glide/integration/compose/GlidePreloadingData {
12+
public abstract fun get (ILandroidx/compose/runtime/Composer;I)Lkotlin/Pair;
13+
public abstract fun getSize ()I
14+
}
15+
1116
public abstract class com/bumptech/glide/integration/compose/Placeholder {
1217
public static final field $stable I
1318
}
1419

1520
public final class com/bumptech/glide/integration/compose/PreloadKt {
16-
public static final fun GlideLazyListPreloader-aVSU5A8 (Landroidx/compose/foundation/lazy/LazyListState;Ljava/util/List;Lkotlin/jvm/functions/Function1;JILjava/lang/Integer;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;II)V
21+
public static final fun rememberGlidePreloadingData-Z8o_i8w (Ljava/util/List;JILjava/lang/Integer;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;II)Lcom/bumptech/glide/integration/compose/GlidePreloadingData;
22+
public static final fun rememberGlidePreloadingData-u6VnWhU (ILkotlin/jvm/functions/Function1;JILjava/lang/Integer;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;II)Lcom/bumptech/glide/integration/compose/GlidePreloadingData;
1723
}
1824

‎integration/compose/build.gradle

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ plugins {
44
}
55

66
android {
7-
compileSdk 32
7+
compileSdk 33
88

99
defaultConfig {
1010
minSdk 21
11-
targetSdk 32
11+
targetSdk 33
1212

1313
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1414
}
@@ -50,7 +50,7 @@ dependencies {
5050
implementation(project(':integration:recyclerview')) {
5151
transitive = false
5252
}
53-
implementation "androidx.compose.foundation:foundation:$ANDROID_X_COMPOSE_VERSION"
53+
implementation "androidx.compose.foundation:foundation:$ANDROID_X_COMPOSE_FOUNDATION_VERSION"
5454
implementation "androidx.compose.ui:ui:$ANDROID_X_COMPOSE_VERSION"
5555
implementation "com.google.accompanist:accompanist-drawablepainter:$ACCOMPANIEST_VERSION"
5656
implementation "androidx.core:core-ktx:$ANDROID_X_CORE_KTX_VERSION"
@@ -60,7 +60,7 @@ dependencies {
6060
androidTestImplementation "androidx.test.espresso:espresso-core:$ANDROID_X_TEST_ESPRESSO_VERSION"
6161
androidTestImplementation "androidx.test.espresso.idling:idling-concurrent:$ANDROID_X_TEST_ESPRESSO_VERSION"
6262
androidTestImplementation "androidx.test.ext:junit:$ANDROID_X_TEST_JUNIT_VERSION"
63-
androidTestImplementation "androidx.compose.material:material:$ANDROID_X_COMPOSE_VERSION"
63+
androidTestImplementation "androidx.compose.material:material:$ANDROID_X_COMPOSE_MATERIAL_VERSION"
6464
androidTestImplementation project(':testutil')
6565
androidTestImplementation "com.google.truth:truth:${TRUTH_VERSION}"
6666
}

‎integration/compose/src/androidTest/java/com/bumptech/glide/integration/compose/GlidePreloaderTest.kt

-188
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.