This commit is contained in:
2024-08-03 15:58:19 +08:00
parent b17ac76005
commit 2dc0ee3307
9 changed files with 269 additions and 16 deletions

View File

@@ -0,0 +1,11 @@
package com.aiosman.riderpro.ui.imageviewer
object ImageViewerViewModel {
var imageList = mutableListOf<String>()
var initialIndex = 0
fun asNew(images: List<String>, index: Int = 0) {
imageList.clear()
imageList.addAll(images)
initialIndex = index
}
}

View File

@@ -0,0 +1,74 @@
import androidx.compose.animation.ExperimentalSharedTransitionApi
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import coil.compose.AsyncImage
import com.aiosman.riderpro.LocalAnimatedContentScope
import com.aiosman.riderpro.LocalNavController
import com.aiosman.riderpro.LocalSharedTransitionScope
import com.aiosman.riderpro.ui.composables.StatusBarMaskLayout
import com.aiosman.riderpro.ui.imageviewer.ImageViewerViewModel
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import net.engawapg.lib.zoomable.rememberZoomState
import net.engawapg.lib.zoomable.zoomable
@OptIn(ExperimentalFoundationApi::class, ExperimentalSharedTransitionApi::class)
@Composable
fun ImageViewer() {
val model = ImageViewerViewModel
val images = model.imageList
val pagerState = rememberPagerState(pageCount = { images.size }, initialPage = model.initialIndex)
val systemUiController = rememberSystemUiController()
val navController = LocalNavController.current
val sharedTransitionScope = LocalSharedTransitionScope.current
val animatedVisibilityScope = LocalAnimatedContentScope.current
LaunchedEffect(Unit) {
systemUiController.setStatusBarColor(Color.Black)
systemUiController.setNavigationBarColor(Color.Black)
}
StatusBarMaskLayout(
modifier = Modifier.background(Color.Black),
) {
Box(
modifier = Modifier
.fillMaxSize()
.background(Color.Black)
) {
HorizontalPager(
state = pagerState,
modifier = Modifier.fillMaxSize()
) { page ->
val zoomState = rememberZoomState()
with(sharedTransitionScope) {
AsyncImage(
images[page],
contentDescription = null,
modifier = Modifier.sharedElement(
rememberSharedContentState(key = images[page]),
animatedVisibilityScope = animatedVisibilityScope
)
.fillMaxSize()
.zoomable(
zoomState = zoomState,
onTap = {
navController.popBackStack()
}
),
contentScale = ContentScale.Fit,
)
}
}
}
}
}