panpf / sketch

Sketch is an image loading library designed for Compose Multiplatform and Android View. It is powerful and rich in functions. In addition to basic functions, it also supports GIF, SVG, video thumbnails, Exif Orientation, etc.
Apache License 2.0
2k stars 307 forks source link

AnimatedVectorDrawable in placeholder or error state is not working, even call start() before state change #178

Closed vickyleu closed 1 year ago

vickyleu commented 1 year ago

DisplayRequest builder like this

  val placeholderDrawable = ContextCompat.getDrawable(this@with,R.drawable.animated_placeholder)
                                                as AnimatedVectorDrawable
  val errorDrawable = ContextCompat.getDrawable(this@with,R.drawable.animated_error)
                                                as AnimatedVectorDrawable

  this.placeholder(placeholderDrawable)
                                            .error(errorDrawable)
                                            .transformations(BlurTransformation())
                                            .crossfade()

adding a state listener

 this.listener(onCancel = {
     println("result.drawable::Cancel")
 }, onError = {_,error->
     println("result.drawable::Error ${error.drawable}")
     (error.drawable as SketchStateAnimatableDrawable).autoPlay()
       placeholderDrawable.reset()
       errorDrawable.autoPlay()
 }, onStart = {
     println("result.drawable::Start :")
       placeholderDrawable.autoPlay()
 }, onSuccess = {_,result->
     println("result.drawable::Success :${result.drawable}")
       .autoPlay()
 })
panpf commented 1 year ago

是否开启了 resizeApplyToDrawable(),目前这个功能有些 bug

panpf commented 1 year ago

现在最新的 3.2.1-beta03 版本在 ImageVie 上应该可以无障碍的播放 AnimatedVectorDrawable 了,

但在 compose 上,已知 api29 以上依然无法播放,测试代码如下:

val context = LocalContext.current
val painter = remember {
      val drawable = ContextCompat.getDrawable(context, R.drawable.animated_placeholder) as AnimatedVectorDrawable
    DrawablePainter(drawable!!)
}
Image(
    painter = painter,
    contentDescription = "",
    contentScale = ContentScale.Crop,
    modifier = Modifier.fillMaxSize()
)

这段代码没有涉及到 sketch,所以这个 bug 只能等 compose 团队去解决