Skip to content

Commit

Permalink
Fix shared elements animation for albums
Browse files Browse the repository at this point in the history
Signed-off-by: IacobIonut01 <paulionut2003@gmail.com>
  • Loading branch information
IacobIonut01 committed Feb 14, 2025
1 parent 1a42883 commit 6d6c87c
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ android {
applicationId = "com.dot.gallery"
minSdk = 30
targetSdk = 35
versionCode = 31208
versionCode = 31209
versionName = "3.1.2"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ data class Album(
) : Parcelable {

val key: String
get() = "{$id, $pathToThumbnail, $timestamp}"
get() = "{$id, $uri, $timestamp}"

val idLessKey: String
get() = "{$uri, $timestamp}"

@IgnoredOnParcel
@Stable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import android.webkit.MimeTypeMap
import androidx.room.Entity
import com.dot.gallery.core.Constants
import com.dot.gallery.feature_node.domain.util.UriSerializer
import com.dot.gallery.feature_node.domain.util.getUri
import com.dot.gallery.feature_node.presentation.util.getDate
import kotlinx.parcelize.Parcelize
import kotlinx.serialization.Serializable
Expand Down Expand Up @@ -50,7 +51,10 @@ sealed class Media : Parcelable, java.io.Serializable {
}

val key: String
get() = "{$id, $path, $definedTimestamp}"
get() = "{$id, ${try { getUri() } catch (_: Exception) { path} }, $definedTimestamp}"

val idLessKey: String
get() = "{${try { getUri() } catch (_: Exception) { path} }, $definedTimestamp}"

@Serializable
@Parcelize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ fun AlbumsScreen(
AlbumComponent(
modifier = Modifier
.pinchItem(key = item.toString())
.animateItem(),
thumbnailModifier = Modifier
.mediaSharedElement(
album = item,
animatedVisibilityScope = animatedContentScope
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import kotlinx.coroutines.launch
@Composable
fun AlbumComponent(
modifier: Modifier = Modifier,
thumbnailModifier: Modifier = Modifier,
album: Album,
isEnabled: Boolean = true,
onItemClick: (Album) -> Unit,
Expand Down Expand Up @@ -172,6 +173,7 @@ fun AlbumComponent(
.aspectRatio(1f)
) {
AlbumImage(
modifier = thumbnailModifier,
album = album,
isEnabled = isEnabled,
onItemClick = onItemClick,
Expand Down Expand Up @@ -227,6 +229,7 @@ fun AlbumComponent(
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun AlbumImage(
modifier: Modifier = Modifier,
album: Album,
isEnabled: Boolean,
onItemClick: (Album) -> Unit,
Expand All @@ -242,7 +245,7 @@ fun AlbumImage(
imageVector = Icons.Outlined.AddCircleOutline,
contentDescription = null,
tint = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier
modifier = modifier
.fillMaxSize()
.border(
width = 1.dp,
Expand All @@ -267,7 +270,7 @@ fun AlbumImage(
)
} else {
AsyncImage(
modifier = Modifier
modifier = modifier
.fillMaxSize()
.border(
width = 1.dp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ context(SharedTransitionScope)
fun <T: Media> Modifier.mediaSharedElement(
media: T,
animatedVisibilityScope: AnimatedVisibilityScope
): Modifier = mediaSharedElement(key = media.key, animatedVisibilityScope = animatedVisibilityScope)
): Modifier = mediaSharedElement(key = media.idLessKey, animatedVisibilityScope = animatedVisibilityScope)

context(SharedTransitionScope)
@Composable
@OptIn(ExperimentalSharedTransitionApi::class)
fun Modifier.mediaSharedElement(
album: Album,
animatedVisibilityScope: AnimatedVisibilityScope
): Modifier = mediaSharedElement(key = album.key, animatedVisibilityScope = animatedVisibilityScope)
): Modifier = mediaSharedElement(key = album.idLessKey, animatedVisibilityScope = animatedVisibilityScope)

context(SharedTransitionScope)
@Composable
Expand Down

0 comments on commit 6d6c87c

Please sign in to comment.