Files
forkmessager/client-mobile/core/presentation/components/AppMediaLightbox.kt
Халимов Рустам 3310a3c4a4 Правка чата
2026-04-14 11:31:20 +03:00

106 lines
3.6 KiB
Kotlin

package core.presentation.components
import androidx.compose.animation.*
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.gestures.detectTransformGestures
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.Download
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
import coil.compose.AsyncImage
@Composable
fun AppMediaLightbox(
url: String,
type: String = "image",
onClose: () -> Unit
) {
Dialog(
onDismissRequest = onClose,
properties = DialogProperties(
usePlatformDefaultWidth = false,
decorFitsSystemWindows = false
)
) {
var scale by remember { mutableFloatStateOf(1f) }
var offset by remember { mutableStateOf(androidx.compose.ui.geometry.Offset.Zero) }
Box(
modifier = Modifier
.fillMaxSize()
.background(Color.Black)
.pointerInput(Unit) {
detectTransformGestures { _, pan, zoom, _ ->
scale = (scale * zoom).coerceIn(1f, 5f)
offset += pan
}
}
) {
if (type == "video") {
AppVideoPlayer(
url = url,
modifier = Modifier.fillMaxSize(),
useController = true,
autoPlay = true
)
} else {
AsyncImage(
model = url,
contentDescription = null,
modifier = Modifier
.fillMaxSize()
.graphicsLayer(
scaleX = scale,
scaleY = scale,
translationX = offset.x,
translationY = offset.y
),
contentScale = ContentScale.Fit
)
}
// Top Bar
Row(
modifier = Modifier
.fillMaxWidth()
.statusBarsPadding()
.padding(16.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
IconButton(
onClick = onClose,
modifier = Modifier
.clip(CircleShape)
.background(Color.Black.copy(alpha = 0.5f))
) {
Icon(Icons.Default.Close, contentDescription = null, tint = Color.White)
}
IconButton(
onClick = { /* Handle download */ },
modifier = Modifier
.clip(CircleShape)
.background(Color.Black.copy(alpha = 0.5f))
) {
Icon(Icons.Default.Download, contentDescription = null, tint = Color.White)
}
}
}
}
}