处理下标越界和防抖

This commit is contained in:
weber
2025-08-06 18:47:24 +08:00
parent b837c704e5
commit 38759eb3e4
2 changed files with 13 additions and 3 deletions

View File

@@ -315,6 +315,9 @@ fun NewPostTopBar(onSendClick: () -> Unit = {}) {
val AppColors = LocalAppTheme.current val AppColors = LocalAppTheme.current
var uploading by remember { mutableStateOf(false) } var uploading by remember { mutableStateOf(false) }
var lastBackClickTime by remember { mutableStateOf(0L) }
var lastSendClickTime by remember { mutableStateOf(0L) }
val debounceTime = 500L // 500毫秒防抖时间
// 上传进度 // 上传进度
if (uploading) { if (uploading) {
BasicAlertDialog( BasicAlertDialog(
@@ -353,7 +356,12 @@ fun NewPostTopBar(onSendClick: () -> Unit = {}) {
modifier = Modifier modifier = Modifier
.size(24.dp) .size(24.dp)
.noRippleClickable { .noRippleClickable {
navController.popBackStack() // 添加防抖逻辑
val currentTime = System.currentTimeMillis()
if (currentTime - lastSendClickTime > debounceTime) {
lastSendClickTime = currentTime
navController.popBackStack()
}
}, },
colorFilter = ColorFilter.tint(AppColors.text) colorFilter = ColorFilter.tint(AppColors.text)
) )

View File

@@ -193,8 +193,10 @@ object NewPostViewModel : ViewModel() {
} }
fun deleteImage(index: Int) { fun deleteImage(index: Int) {
imageList = imageList.toMutableList().apply { if (index >= 0 && index < imageList.size) {
removeAt(index) imageList = imageList.toMutableList().apply {
removeAt(index)
}
} }
} }
} }