处理下标越界和防抖
This commit is contained in:
@@ -315,6 +315,9 @@ fun NewPostTopBar(onSendClick: () -> Unit = {}) {
|
||||
val AppColors = LocalAppTheme.current
|
||||
|
||||
var uploading by remember { mutableStateOf(false) }
|
||||
var lastBackClickTime by remember { mutableStateOf(0L) }
|
||||
var lastSendClickTime by remember { mutableStateOf(0L) }
|
||||
val debounceTime = 500L // 500毫秒防抖时间
|
||||
// 上传进度
|
||||
if (uploading) {
|
||||
BasicAlertDialog(
|
||||
@@ -353,7 +356,12 @@ fun NewPostTopBar(onSendClick: () -> Unit = {}) {
|
||||
modifier = Modifier
|
||||
.size(24.dp)
|
||||
.noRippleClickable {
|
||||
navController.popBackStack()
|
||||
// 添加防抖逻辑
|
||||
val currentTime = System.currentTimeMillis()
|
||||
if (currentTime - lastSendClickTime > debounceTime) {
|
||||
lastSendClickTime = currentTime
|
||||
navController.popBackStack()
|
||||
}
|
||||
},
|
||||
colorFilter = ColorFilter.tint(AppColors.text)
|
||||
)
|
||||
|
||||
@@ -193,8 +193,10 @@ object NewPostViewModel : ViewModel() {
|
||||
}
|
||||
|
||||
fun deleteImage(index: Int) {
|
||||
imageList = imageList.toMutableList().apply {
|
||||
removeAt(index)
|
||||
if (index >= 0 && index < imageList.size) {
|
||||
imageList = imageList.toMutableList().apply {
|
||||
removeAt(index)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user