Skip to content

Commit 5967213

Browse files
authored
Various changes and fixes to Pilot coil components in android (#25)
Allow image builder to be customized externally in PilotResizableRemoteImage & PilotRemoteImage Make sure AsyncImagePainter transform does not override image with placeholder when loading from cache. Fix an issue in PilotResizableRemoteImage where the provided modifier was applied twice (once on the BoxWithContraints and once on the AsyncImage). Instead of doing that we now match parent size on the AsyncImage modifier. Note: Binary incompatible change but source compatible
1 parent 500753b commit 5967213

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
public final class com/mirego/pilot/components/ui/coil/PilotRemoteImageKt {
2-
public static final fun PilotRemoteImage-_kETKwk (Lcom/mirego/pilot/components/PilotRemoteImage;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function1;Landroidx/compose/ui/Alignment;Landroidx/compose/ui/layout/ContentScale;FLandroidx/compose/ui/graphics/ColorFilter;IZLandroidx/compose/runtime/Composer;II)V
2+
public static final fun PilotRemoteImage-nWU5RSE (Lcom/mirego/pilot/components/PilotRemoteImage;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function1;Landroidx/compose/ui/Alignment;Landroidx/compose/ui/layout/ContentScale;FLandroidx/compose/ui/graphics/ColorFilter;IZLkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;II)V
33
}
44

55
public final class com/mirego/pilot/components/ui/coil/PilotResizableRemoteImageKt {
6-
public static final fun PilotResizableRemoteImage-_kETKwk (Lcom/mirego/pilot/components/PilotResizableRemoteImage;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function1;Landroidx/compose/ui/Alignment;Landroidx/compose/ui/layout/ContentScale;FLandroidx/compose/ui/graphics/ColorFilter;IZLandroidx/compose/runtime/Composer;II)V
6+
public static final fun PilotResizableRemoteImage-nWU5RSE (Lcom/mirego/pilot/components/PilotResizableRemoteImage;Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function1;Landroidx/compose/ui/Alignment;Landroidx/compose/ui/layout/ContentScale;FLandroidx/compose/ui/graphics/ColorFilter;IZLkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;II)V
77
}
88

components/android/coil/src/main/kotlin/com/mirego/pilot/components/ui/coil/PilotRemoteImage.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ public fun PilotRemoteImage(
2828
colorFilter: ColorFilter? = null,
2929
filterQuality: FilterQuality = DrawScope.DefaultFilterQuality,
3030
allowHardware: Boolean = true,
31+
asyncImageBuilder: ImageRequest.Builder.() -> Unit = {},
3132
) {
3233
AsyncImage(
3334
model = ImageRequest.Builder(LocalContext.current)
3435
.data(pilotRemoteImage.url)
3536
.allowHardware(allowHardware)
37+
.apply(asyncImageBuilder)
3638
.build(),
3739
contentDescription = pilotRemoteImage.contentDescription,
3840
modifier = modifier,
@@ -52,8 +54,8 @@ public fun PilotRemoteImage(
5254
internal fun transformOf(placeholder: Painter): (AsyncImagePainter.State) -> AsyncImagePainter.State =
5355
{ state ->
5456
when (state) {
55-
is AsyncImagePainter.State.Loading -> state.copy(painter = placeholder)
56-
is AsyncImagePainter.State.Error -> state.copy(painter = placeholder)
57+
is AsyncImagePainter.State.Loading -> if (state.painter == null) state.copy(painter = placeholder) else state
58+
is AsyncImagePainter.State.Error -> if (state.painter == null) state.copy(painter = placeholder) else state
5759
else -> state
5860
}
5961
}

components/android/coil/src/main/kotlin/com/mirego/pilot/components/ui/coil/PilotResizableRemoteImage.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public fun PilotResizableRemoteImage(
3030
colorFilter: ColorFilter? = null,
3131
filterQuality: FilterQuality = DrawScope.DefaultFilterQuality,
3232
allowHardware: Boolean = true,
33+
asyncImageBuilder: ImageRequest.Builder.() -> Unit = {},
3334
) {
3435
BoxWithConstraints(modifier) {
3536
with(LocalDensity.current) {
@@ -43,9 +44,10 @@ public fun PilotResizableRemoteImage(
4344
model = ImageRequest.Builder(LocalContext.current)
4445
.data(url)
4546
.allowHardware(allowHardware)
47+
.apply(asyncImageBuilder)
4648
.build(),
4749
contentDescription = pilotRemoteImage.contentDescription,
48-
modifier = modifier,
50+
modifier = Modifier.matchParentSize(),
4951
transform = pilotRemoteImage.placeholder
5052
?.let { transformOf(pilotImageResourcePainter(it)) }
5153
?: AsyncImagePainter.DefaultTransform,

0 commit comments

Comments
 (0)