Skip to content

Commit

Permalink
implement isloaded for android
Browse files Browse the repository at this point in the history
  • Loading branch information
haileyok committed Apr 22, 2024
1 parent cca236c commit d0a139b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@ import android.graphics.Canvas
import android.graphics.drawable.Animatable
import androidx.appcompat.widget.AppCompatImageView

class AppCompatImageViewExtended(context: Context, val parent: GifView): AppCompatImageView(context) {
class AppCompatImageViewExtended(context: Context, private val parent: GifView): AppCompatImageView(context) {
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
if (!parent.isPlaying) {
this.pause()

if (this.drawable is Animatable) {
if (!parent.isLoaded) {
parent.isLoaded = true
parent.firePlayerStateChange()
}

if (!parent.isPlaying) {
this.pause()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class GifView(context: Context, appContext: AppContext) : ExpoView(context, appC
private val glide = Glide.with(activity)
val imageView = AppCompatImageViewExtended(context, this)
var isPlaying = true
private var isLoaded = false
var isLoaded = false

// Requests
private var placeholderRequest: Target<Drawable>? = null
Expand Down Expand Up @@ -93,11 +93,6 @@ class GifView(context: Context, appContext: AppContext) : ExpoView(context, appC
if (placeholderRequest != null) {
glide.clear(placeholderRequest)
}
isLoaded = true

// On don't want to call this in `onDraw()` because `onDraw()` will get called after
// an app background -> foreground, resulting in a useless event being fired
firePlayerStateChange()
return false
}

Expand Down Expand Up @@ -174,7 +169,7 @@ class GifView(context: Context, appContext: AppContext) : ExpoView(context, appC

//<editor-fold desc="Util">

private fun firePlayerStateChange() {
fun firePlayerStateChange() {
onPlayerStateChange(mapOf(
"isPlaying" to this.isPlaying,
"isLoaded" to this.isLoaded,
Expand Down

0 comments on commit d0a139b

Please sign in to comment.