improvements

This commit is contained in:
2025-06-23 20:49:14 +03:00
parent c14ee45d53
commit c1e76e1c60
2 changed files with 21 additions and 9 deletions
@@ -2,9 +2,12 @@ package dev.meloda.fast.messageshistory.presentation.attachments
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.Stable
import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import dev.meloda.fast.model.api.data.AttachmentType import dev.meloda.fast.model.api.data.AttachmentType
import dev.meloda.fast.model.api.domain.VkAttachment import dev.meloda.fast.model.api.domain.VkAttachment
@@ -28,6 +31,9 @@ fun Attachments(
onClick: (VkAttachment) -> Unit = {}, onClick: (VkAttachment) -> Unit = {},
onLongClick: (VkAttachment) -> Unit = {} onLongClick: (VkAttachment) -> Unit = {}
) { ) {
val currentOnClick by rememberUpdatedState(onClick)
val currentOnLongClick by rememberUpdatedState(onLongClick)
Column(modifier = modifier) { Column(modifier = modifier) {
if (attachments.isEmpty()) return if (attachments.isEmpty()) return
@@ -51,10 +57,10 @@ fun Attachments(
.map(VkAttachment::asUiPhoto) .map(VkAttachment::asUiPhoto)
.toImmutableList(), .toImmutableList(),
onClick = { index -> onClick = { index ->
onClick(previewAttachments[index]) currentOnClick(previewAttachments[index])
}, },
onLongClick = { index -> onLongClick = { index ->
onLongClick(previewAttachments[index]) currentOnLongClick(previewAttachments[index])
} }
) )
} }
@@ -72,8 +78,8 @@ fun Attachments(
File( File(
item = attachment as VkFileDomain, item = attachment as VkFileDomain,
modifier = Modifier, modifier = Modifier,
onClick = { onClick(attachment) }, onClick = { currentOnClick(attachment) },
onLongClick = { onLongClick(attachment) } onLongClick = { currentOnLongClick(attachment) }
) )
} }
@@ -81,8 +87,8 @@ fun Attachments(
Link( Link(
item = attachment as VkLinkDomain, item = attachment as VkLinkDomain,
modifier = Modifier, modifier = Modifier,
onClick = { onClick(attachment) }, onClick = { currentOnClick(attachment) },
onLongClick = { onLongClick(attachment) } onLongClick = { currentOnLongClick(attachment) }
) )
} }
@@ -156,6 +162,7 @@ fun VkAttachment.asUiPhoto(): UiPreview {
} }
} }
@Immutable
data class UiPreview( data class UiPreview(
val id: Long, val id: Long,
val url: String, val url: String,
@@ -18,6 +18,8 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.PlayArrow import androidx.compose.material.icons.rounded.PlayArrow
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
@@ -54,6 +56,9 @@ fun DynamicPreviewGrid(
onClick: (index: Int) -> Unit = {}, onClick: (index: Int) -> Unit = {},
onLongClick: (index: Int) -> Unit = {} onLongClick: (index: Int) -> Unit = {}
) { ) {
val currentOnClick by rememberUpdatedState(onClick)
val currentOnLongClick by rememberUpdatedState(onLongClick)
val spacing = 2.dp val spacing = 2.dp
val shape = RoundedCornerShape(8.dp) val shape = RoundedCornerShape(8.dp)
@@ -90,14 +95,14 @@ fun DynamicPreviewGrid(
.height(heightDp) .height(heightDp)
.clip(shape) .clip(shape)
.combinedClickable( .combinedClickable(
onLongClick = { onLongClick(index) }, onLongClick = { currentOnLongClick(index) },
onClick = { onClick(index) } onClick = { currentOnClick(index) }
) )
) )
if (preview.isVideo) { if (preview.isVideo) {
IconButton( IconButton(
onClick = { onClick(index) }, onClick = { currentOnClick(index) },
modifier = Modifier modifier = Modifier
.size(36.dp) .size(36.dp)
.clip(CircleShape) .clip(CircleShape)