Как использовать ImageRequest.Builder.target в новой версии катушки в компоновке реактивного ранца?Android

Форум для тех, кто программирует под Android
Ответить Пред. темаСлед. тема
Гость
 Как использовать ImageRequest.Builder.target в новой версии катушки в компоновке реактивного ранца?

Сообщение Гость »

My Gradle

Код: Выделить всё

// Coil
implementation "io.coil-kt:coil-compose:1.4.0"
Problem Description
Previously I used the coil together with Google's

Код: Выделить всё

accompanist
, but when I migrate to the new version of the coil as the documentation suggests I'm having problems with the method:

Код: Выделить всё

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.pokedex, PID: 13502
java.lang.IllegalArgumentException: request.target must be null.
at coil.compose.ImagePainterKt.rememberImagePainter(ImagePainter.kt:94)
...
Coil Implementation
When browsing the internal code of

Код: Выделить всё

ImagePainter
(coil class) you can see that the method really needs to be null for some reason:

Код: Выделить всё

@Composable
fun rememberImagePainter(
request: ImageRequest,
imageLoader: ImageLoader,
onExecute: ExecuteCallback = ExecuteCallback.Default,
): ImagePainter {
requireSupportedData(request.data)
require(request.target == null) { "request.target must be null." }
...
My Code
Here's my component in jetpack compose (the image component is inside a column):

Код: Выделить всё

Image(
modifier = Modifier
.size(120.dp)
.align(Alignment.CenterHorizontally),
painter = rememberImagePainter(
data = entry.imageUrl,
builder = {
crossfade(true)
target {
viewModel.calcDominantColor(it) { color ->
dominantColor = color
}
}
transformations(CircleCropTransformation())
},
),
contentDescription = entry.pokemonName
)
I need the target method to do internal operations on my

Код: Выделить всё

viewModel
based on the

Код: Выделить всё

drawable
it passes as a parameter. Can someone help me?


Источник: https://stackoverflow.com/questions/698 ... tpack-comp
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Android»