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.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.Stable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.ui.Modifier
import dev.meloda.fast.model.api.data.AttachmentType
import dev.meloda.fast.model.api.domain.VkAttachment
@@ -28,6 +31,9 @@ fun Attachments(
onClick: (VkAttachment) -> Unit = {},
onLongClick: (VkAttachment) -> Unit = {}
) {
val currentOnClick by rememberUpdatedState(onClick)
val currentOnLongClick by rememberUpdatedState(onLongClick)
Column(modifier = modifier) {
if (attachments.isEmpty()) return
@@ -51,10 +57,10 @@ fun Attachments(
.map(VkAttachment::asUiPhoto)
.toImmutableList(),
onClick = { index ->
onClick(previewAttachments[index])
currentOnClick(previewAttachments[index])
},
onLongClick = { index ->
onLongClick(previewAttachments[index])
currentOnLongClick(previewAttachments[index])
}
)
}
@@ -72,8 +78,8 @@ fun Attachments(
File(
item = attachment as VkFileDomain,
modifier = Modifier,
onClick = { onClick(attachment) },
onLongClick = { onLongClick(attachment) }
onClick = { currentOnClick(attachment) },
onLongClick = { currentOnLongClick(attachment) }
)
}
@@ -81,8 +87,8 @@ fun Attachments(
Link(
item = attachment as VkLinkDomain,
modifier = Modifier,
onClick = { onClick(attachment) },
onLongClick = { onLongClick(attachment) }
onClick = { currentOnClick(attachment) },
onLongClick = { currentOnLongClick(attachment) }
)
}
@@ -156,6 +162,7 @@ fun VkAttachment.asUiPhoto(): UiPreview {
}
}
@Immutable
data class UiPreview(
val id: Long,
val url: String,
@@ -18,6 +18,8 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.PlayArrow
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
@@ -54,6 +56,9 @@ fun DynamicPreviewGrid(
onClick: (index: Int) -> Unit = {},
onLongClick: (index: Int) -> Unit = {}
) {
val currentOnClick by rememberUpdatedState(onClick)
val currentOnLongClick by rememberUpdatedState(onLongClick)
val spacing = 2.dp
val shape = RoundedCornerShape(8.dp)
@@ -90,14 +95,14 @@ fun DynamicPreviewGrid(
.height(heightDp)
.clip(shape)
.combinedClickable(
onLongClick = { onLongClick(index) },
onClick = { onClick(index) }
onLongClick = { currentOnLongClick(index) },
onClick = { currentOnClick(index) }
)
)
if (preview.isVideo) {
IconButton(
onClick = { onClick(index) },
onClick = { currentOnClick(index) },
modifier = Modifier
.size(36.dp)
.clip(CircleShape)