UI: hide share fab after clearing all benchmark results

This commit is contained in:
Han Yin 2025-08-29 16:58:43 -07:00
parent c848005d11
commit b75377676f
5 changed files with 14 additions and 2 deletions

View File

@ -259,6 +259,7 @@ fun AppContent(
// Benchmark screen
currentRoute.startsWith(AppDestinations.BENCHMARK_ROUTE) -> {
val showShareFab by benchmarkViewModel.showShareFab.collectAsState()
val showModelCard by benchmarkViewModel.showModelCard.collectAsState()
ScaffoldConfig(
@ -272,6 +273,7 @@ fun AppContent(
),
bottomBarConfig = BottomBarConfig.Benchmark(
engineIdle = !engineState.isUninterruptible,
showShareFab = showShareFab,
onShare = { benchmarkViewModel.shareResult(handleScaffoldEvent) },
onRerun = { benchmarkViewModel.rerunBenchmark(handleScaffoldEvent) },
onClear = { benchmarkViewModel.clearResults(handleScaffoldEvent) },

View File

@ -104,6 +104,7 @@ fun AppScaffold(
is BottomBarConfig.Benchmark -> {
BenchmarkBottomBar(
showShareFab = config.showShareFab,
engineIdle = config.engineIdle,
onShare = config.onShare,
onRerun = config.onRerun,

View File

@ -21,6 +21,7 @@ import androidx.compose.runtime.Composable
@Composable
fun BenchmarkBottomBar(
engineIdle: Boolean,
showShareFab: Boolean,
onShare: () -> Unit,
onRerun: () -> Unit,
onClear: () -> Unit,
@ -59,7 +60,7 @@ fun BenchmarkBottomBar(
floatingActionButton = {
// Only show FAB if the benchmark result is ready
AnimatedVisibility(
visible = engineIdle,
visible = showShareFab,
enter = scaleIn() + fadeIn(),
exit = scaleOut() + fadeOut()
) {

View File

@ -87,6 +87,7 @@ sealed class BottomBarConfig {
}
data class Benchmark(
val showShareFab: Boolean,
val engineIdle: Boolean,
val onShare: () -> Unit,
val onRerun: () -> Unit,

View File

@ -30,7 +30,7 @@ class BenchmarkViewModel @Inject constructor(
private val _benchmarkResults = MutableStateFlow<List<BenchmarkResult>>(emptyList())
val benchmarkResults: StateFlow<List<BenchmarkResult>> = _benchmarkResults.asStateFlow()
// UI state: Model card
// UI state: Model card
private val _showModelCard = MutableStateFlow(false)
val showModelCard = _showModelCard.asStateFlow()
@ -38,6 +38,10 @@ class BenchmarkViewModel @Inject constructor(
_showModelCard.value = show
}
// UI state: Share FAB
private val _showShareFab = MutableStateFlow(false)
val showShareFab = _showShareFab.asStateFlow()
init {
viewModelScope.launch {
benchmarkService.benchmarkResults
@ -61,10 +65,12 @@ class BenchmarkViewModel @Inject constructor(
}
viewModelScope.launch {
_showShareFab.value = false
val benchmarkStartTs = System.currentTimeMillis()
benchmarkService.benchmark(pp, tg, pl, nr)
val benchmarkEndTs = System.currentTimeMillis()
_benchmarkDuration.emit(benchmarkEndTs - benchmarkStartTs)
_showShareFab.value = true
}
return true
}
@ -76,6 +82,7 @@ class BenchmarkViewModel @Inject constructor(
false
} else {
_benchmarkResults.value = emptyList()
_showShareFab.value = false
onScaffoldEvent?.invoke(ScaffoldEvent.ShowSnackbar(
message = "All benchmark results cleared."
))