From 96e9fbfb3a544dac39677d2e3465fc91b6860edb Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Fri, 16 Oct 2026 14:58:39 -0400 Subject: [PATCH] Android drawer: tag-view tracking in its own composable (#5931) detekt's cyclomatic-complexity limit on BoardScreen. Co-Authored-By: Claude Opus 5.5 --- .../com/fabledsword/inkwell/ui/BoardScreen.kt | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/android/app/src/main/java/com/fabledsword/inkwell/ui/BoardScreen.kt b/android/app/src/main/java/com/fabledsword/inkwell/ui/BoardScreen.kt index 9b303f1..5136441 100644 --- a/android/app/src/main/java/com/fabledsword/inkwell/ui/BoardScreen.kt +++ b/android/app/src/main/java/com/fabledsword/inkwell/ui/BoardScreen.kt @@ -99,15 +99,7 @@ fun BoardScreen( ) { val drawerState = rememberDrawerState(DrawerValue.Closed) val scope = rememberCoroutineScope() - - // Opening a tag's lens counts as using it, however it was opened: from the - // drawer, or a tag on a card (#5931). - val context = LocalContext.current - val tagViews = remember(context) { TagViews(context) } - var views by remember { mutableStateOf(tagViews.all()) } - LaunchedEffect(state.destination) { - (state.destination as? Destination.WithLabel)?.let { views = tagViews.record(it.id) } - } + val views = rememberTagViews(state.destination) val snackbars = remember { SnackbarHostState() } // Held HERE rather than on the card. A card lives in a lazy grid and is disposed @@ -410,6 +402,21 @@ private fun SearchBar( } } +/** + * When each tag's lens was last opened here. Opening one counts as using it, + * however it was opened: from the drawer, or a tag on a card (#5931). + */ +@Composable +private fun rememberTagViews(destination: Destination): Map { + val context = LocalContext.current + val tagViews = remember(context) { TagViews(context) } + var views by remember { mutableStateOf(tagViews.all()) } + LaunchedEffect(destination) { + if (destination is Destination.WithLabel) views = tagViews.record(destination.id) + } + return views +} + @Composable private fun NavigationDrawer( current: Destination,