From 1151106cdf23740f25f935b886c0770550e61498 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 15 May 2026 22:02:15 +0000 Subject: [PATCH] fix(bottom-bar-settings): stop reverting newly-pinned icons on drag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace `remember(pinned)` with a single `remember`, so the local `items` MutableState isn't recreated each time the StateFlow emits. Previously, when the user toggled an item ON, the resulting recomposition swapped the local items state to a new MutableState backed by `initialRows(newPinned)`. Drag-gesture callbacks captured in earlier compositions kept writing to the old MutableState, and on drag end they re-emitted a `pinned` list computed from that stale state — dropping the just-pinned item. Initialize once from `bottomBarItems.value` (already correct at first composition) and let toggle / drag / restore-default be the only writers. This makes the screen self-contained and removes the position-vs-state race entirely. --- .../loggedIn/settings/BottomBarSettingsScreen.kt | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/settings/BottomBarSettingsScreen.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/settings/BottomBarSettingsScreen.kt index 351a4d2b4..953296ba0 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/settings/BottomBarSettingsScreen.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/settings/BottomBarSettingsScreen.kt @@ -58,7 +58,6 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.zIndex -import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.commons.icons.symbols.Icon import com.vitorpamplona.amethyst.commons.icons.symbols.MaterialSymbols @@ -104,16 +103,12 @@ fun BottomBarSettingsScreen( @Composable fun BottomBarSettingsContent(accountViewModel: AccountViewModel) { - val pinned by accountViewModel.settings.uiSettingsFlow.bottomBarItems - .collectAsStateWithLifecycle() - - var items by remember(pinned) { - mutableStateOf(initialRows(pinned)) - } + val bottomBarItemsFlow = accountViewModel.settings.uiSettingsFlow.bottomBarItems + var items by remember { mutableStateOf(initialRows(bottomBarItemsFlow.value)) } fun save(newItems: List) { items = newItems - accountViewModel.settings.uiSettingsFlow.bottomBarItems.tryEmit( + bottomBarItemsFlow.tryEmit( newItems.filter { it.pinned }.map { it.item }, ) }