Skip to content

Commit

Permalink
Change Glide's preloading API to be data based
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sjudd committed Dec 15, 2022
1 parent 18bba92 commit e63c5d2
Show file tree
Hide file tree
Showing 9 changed files with 483 additions and 369 deletions.
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ ANDROID_X_ANNOTATION_VERSION=1.3.0
ANDROID_X_APPCOMPAT_VERSION=1.3.1
ANDROID_X_BENCHMARK_VERSION=1.1.0
ANDROID_X_CARDVIEW_VERSION=1.0.0
ANDROID_X_COMPOSE_VERSION=1.2.1
ANDROID_X_COMPOSE_VERSION=1.3.2
ANDROID_X_COMPOSE_FOUNDATION_VERSION=1.3.1
ANDROID_X_COMPOSE_MATERIAL_VERSION=1.3.1
ANDROID_X_CONCURRENT_FUTURES_VERSION=1.1.0
ANDROID_X_CORE_VERSION=1.6.0
ANDROID_X_EXIF_INTERFACE_VERSION=1.3.3
Expand Down
8 changes: 7 additions & 1 deletion integration/compose/api/compose.api
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ public final class com/bumptech/glide/integration/compose/GlideImageKt {
public static final fun placeholder (Lkotlin/jvm/functions/Function2;)Lcom/bumptech/glide/integration/compose/Placeholder;
}

public abstract interface class com/bumptech/glide/integration/compose/GlidePreloadingData {
public abstract fun get (ILandroidx/compose/runtime/Composer;I)Lkotlin/Pair;
public abstract fun getSize ()I
}

public abstract class com/bumptech/glide/integration/compose/Placeholder {
public static final field $stable I
}

public final class com/bumptech/glide/integration/compose/PreloadKt {
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
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;
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;
}

8 changes: 4 additions & 4 deletions integration/compose/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ plugins {
}

android {
compileSdk 32
compileSdk 33

defaultConfig {
minSdk 21
targetSdk 32
targetSdk 33

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -50,7 +50,7 @@ dependencies {
implementation(project(':integration:recyclerview')) {
transitive = false
}
implementation "androidx.compose.foundation:foundation:$ANDROID_X_COMPOSE_VERSION"
implementation "androidx.compose.foundation:foundation:$ANDROID_X_COMPOSE_FOUNDATION_VERSION"
implementation "androidx.compose.ui:ui:$ANDROID_X_COMPOSE_VERSION"
implementation "com.google.accompanist:accompanist-drawablepainter:$ACCOMPANIEST_VERSION"
implementation "androidx.core:core-ktx:$ANDROID_X_CORE_KTX_VERSION"
Expand All @@ -60,7 +60,7 @@ dependencies {
androidTestImplementation "androidx.test.espresso:espresso-core:$ANDROID_X_TEST_ESPRESSO_VERSION"
androidTestImplementation "androidx.test.espresso.idling:idling-concurrent:$ANDROID_X_TEST_ESPRESSO_VERSION"
androidTestImplementation "androidx.test.ext:junit:$ANDROID_X_TEST_JUNIT_VERSION"
androidTestImplementation "androidx.compose.material:material:$ANDROID_X_COMPOSE_VERSION"
androidTestImplementation "androidx.compose.material:material:$ANDROID_X_COMPOSE_MATERIAL_VERSION"
androidTestImplementation project(':testutil')
androidTestImplementation "com.google.truth:truth:${TRUTH_VERSION}"
}
Expand Down

This file was deleted.

Loading

0 comments on commit e63c5d2

Please sign in to comment.