From d0a139b7d544f07d7bac0a1d70c10920f296c9cd Mon Sep 17 00:00:00 2001 From: Hailey Date: Sun, 21 Apr 2024 21:02:08 -0700 Subject: [PATCH] implement isloaded for android --- .../blueskygifview/AppCompatImageViewExtended.kt | 14 +++++++++++--- .../java/expo/modules/blueskygifview/GifView.kt | 9 ++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/modules/expo-bluesky-gif-view/android/src/main/java/expo/modules/blueskygifview/AppCompatImageViewExtended.kt b/modules/expo-bluesky-gif-view/android/src/main/java/expo/modules/blueskygifview/AppCompatImageViewExtended.kt index 0efdc9044c..5d20848453 100644 --- a/modules/expo-bluesky-gif-view/android/src/main/java/expo/modules/blueskygifview/AppCompatImageViewExtended.kt +++ b/modules/expo-bluesky-gif-view/android/src/main/java/expo/modules/blueskygifview/AppCompatImageViewExtended.kt @@ -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() + } } } diff --git a/modules/expo-bluesky-gif-view/android/src/main/java/expo/modules/blueskygifview/GifView.kt b/modules/expo-bluesky-gif-view/android/src/main/java/expo/modules/blueskygifview/GifView.kt index 919c24a4a2..eabb664076 100644 --- a/modules/expo-bluesky-gif-view/android/src/main/java/expo/modules/blueskygifview/GifView.kt +++ b/modules/expo-bluesky-gif-view/android/src/main/java/expo/modules/blueskygifview/GifView.kt @@ -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? = null @@ -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 } @@ -174,7 +169,7 @@ class GifView(context: Context, appContext: AppContext) : ExpoView(context, appC // - private fun firePlayerStateChange() { + fun firePlayerStateChange() { onPlayerStateChange(mapOf( "isPlaying" to this.isPlaying, "isLoaded" to this.isLoaded,