Skip to content

Commit

Permalink
Implement animated gifs when clicking on an image (#580)
Browse files Browse the repository at this point in the history
Co-authored-by: Dessalines <[email protected]>
  • Loading branch information
beatgammit and dessalines authored Jun 13, 2023
1 parent 5b8bc23 commit 13abc80
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ dependencies {
implementation 'androidx.compose.runtime:runtime-livedata:1.4.3'
implementation "androidx.lifecycle:lifecycle-runtime-compose:2.6.1"

// gif support
implementation "io.coil-kt:coil-gif:2.4.0"

// To use Kotlin annotation processing tool
ksp "androidx.room:room-compiler:2.5.1"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.jerboa.ui.components.common

import android.content.Context
import android.net.Uri
import android.os.Build.VERSION.SDK_INT
import android.webkit.MimeTypeMap
import android.widget.Toast
import androidx.compose.animation.animateColorAsState
Expand Down Expand Up @@ -38,7 +39,10 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
import coil.ImageLoader
import coil.compose.rememberAsyncImagePainter
import coil.decode.GifDecoder
import coil.decode.ImageDecoderDecoder
import com.jerboa.saveBitmap
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -85,6 +89,16 @@ fun ImageViewerDialog(url: String, onBackRequest: () -> Unit) {
val context = LocalContext.current
val coroutineScope = rememberCoroutineScope()

val imageLoader = ImageLoader.Builder(LocalContext.current)
.components {
if (SDK_INT >= 28) {
add(ImageDecoderDecoder.Factory())
} else {
add(GifDecoder.Factory())
}
}
.build()

Dialog(
onDismissRequest = onBackRequest,
properties = DialogProperties(
Expand All @@ -95,7 +109,7 @@ fun ImageViewerDialog(url: String, onBackRequest: () -> Unit) {
) {
Box(Modifier.background(backgroundColor.value)) {
Image(
painter = rememberAsyncImagePainter(url),
painter = rememberAsyncImagePainter(url, imageLoader = imageLoader),
contentDescription = null,
modifier = Modifier
.fillMaxSize()
Expand Down

0 comments on commit 13abc80

Please sign in to comment.