chore: 参数调整

This commit is contained in:
lisonge 2023-10-25 21:58:07 +08:00
parent ce3ca5a2aa
commit 3439e9527a
3 changed files with 16 additions and 8 deletions

View File

@ -3,8 +3,8 @@ package li.songe.gkd.ui.component
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.KeyboardArrowRight import androidx.compose.material.icons.filled.KeyboardArrowRight
@ -30,7 +30,7 @@ fun SettingItem(
) )
.fillMaxWidth() .fillMaxWidth()
.padding(10.dp, 10.dp) .padding(10.dp, 10.dp)
.height(30.dp), .defaultMinSize(minHeight = 30.dp),
horizontalArrangement = Arrangement.SpaceBetween, horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
) { ) {

View File

@ -10,15 +10,12 @@ import com.ramcosta.composedestinations.spec.Direction
val LocalNavController = val LocalNavController =
compositionLocalOf<NavHostController> { error("not found DestinationsNavigator") } compositionLocalOf<NavHostController> { error("not found DestinationsNavigator") }
private var lastNavigateTime = -1L private val navThrottle = useThrottle()
fun NavController.navigate( fun NavController.navigate(
direction: Direction, direction: Direction,
navOptionsBuilder: NavOptionsBuilder.() -> Unit = {}, navOptionsBuilder: NavOptionsBuilder.() -> Unit = {},
) { ) {
val t = System.currentTimeMillis() navThrottle {
if (t - lastNavigateTime < 1000) { navigate(direction.route, navOptionsBuilder)
return
} }
lastNavigateTime = t
navigate(direction.route, navOptionsBuilder)
} }

View File

@ -34,4 +34,15 @@ fun Long.format(formatStr: String): String {
formatDateMap[formatStr] = df formatDateMap[formatStr] = df
} }
return df.format(this) return df.format(this)
}
fun useThrottle(interval: Long = 1000L): (fn: () -> Unit) -> Unit {
var lastTriggerTime = 0L
return { fn ->
val t = System.currentTimeMillis()
if (t - lastTriggerTime > interval) {
lastTriggerTime = t
fn()
}
}
} }