处理下标越界和防抖
This commit is contained in:
@@ -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 {
|
||||||
|
// 添加防抖逻辑
|
||||||
|
val currentTime = System.currentTimeMillis()
|
||||||
|
if (currentTime - lastSendClickTime > debounceTime) {
|
||||||
|
lastSendClickTime = currentTime
|
||||||
navController.popBackStack()
|
navController.popBackStack()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
colorFilter = ColorFilter.tint(AppColors.text)
|
colorFilter = ColorFilter.tint(AppColors.text)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -193,8 +193,10 @@ object NewPostViewModel : ViewModel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun deleteImage(index: Int) {
|
fun deleteImage(index: Int) {
|
||||||
|
if (index >= 0 && index < imageList.size) {
|
||||||
imageList = imageList.toMutableList().apply {
|
imageList = imageList.toMutableList().apply {
|
||||||
removeAt(index)
|
removeAt(index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user