Modern Apps git

← Modern-Apps.git

web: move toolbar to bottom by default, add setting to move it up

Commit
eedd7a5b964140f98bf2166c084bdb627b4cf112
Author
vayun-mathur <[email protected]>
When
2026-08-27 16:34 UTC (3 months ago)
Parents
d92b64c

Diff

web/src/main/java/com/vayunmathur/web/platform/WebViewModel.kt
diff --git a/web/src/main/java/com/vayunmathur/web/platform/WebViewModel.kt b/web/src/main/java/com/vayunmathur/web/platform/WebViewModel.ktindex 7468306ce8..ce1edbc007 100644--- a/web/src/main/java/com/vayunmathur/web/platform/WebViewModel.kt+++ b/web/src/main/java/com/vayunmathur/web/platform/WebViewModel.kt@@ -51,6 +51,7 @@ private const val P_SHIELD_COSMETIC = "web_shield_cosmetic" private const val P_SHIELD_FINGERPRINT = "web_shield_fingerprint" private const val P_SHIELD_HTTPS = "web_shield_https" private const val P_LOCAL_NETWORK_DENIED = "web_local_network_denied"+private const val P_SEARCH_BAR_BOTTOM = "web_search_bar_bottom"  data class PermissionPrompt(     val id: String = Uuid.random().toString(),@@ -105,6 +106,9 @@ class WebViewModel(     var blockThirdPartyCookies by mutableStateOf(false)     var desktopMode by mutableStateOf(false) +    /** Toolbar edge. Defaults to the bottom, within thumb reach on a phone. */+    var searchBarAtBottom by mutableStateOf(true)+     /** Global Brave Shields defaults; per-site overrides live in [shieldSettings]. */     var shields by mutableStateOf(ShieldsSettings.AGGRESSIVE_DEFAULTS)         private set@@ -196,6 +200,7 @@ class WebViewModel(                     val blockThird = sp.getBoolean(P_BLOCK_THIRD_PARTY, false)                     val desktop = sp.getBoolean(P_DESKTOP_MODE, false)                     val lanDenied = sp.getBoolean(P_LOCAL_NETWORK_DENIED, false)+                    val barAtBottom = sp.getBoolean(P_SEARCH_BAR_BOTTOM, true)                     val defaults = ShieldsSettings.AGGRESSIVE_DEFAULTS                     val savedShields = ShieldsSettings(                         level = sp.getString(P_SHIELD_LEVEL, null)@@ -214,6 +219,7 @@ class WebViewModel(                         blockThirdPartyCookies = blockThird                         desktopMode = desktop                         localNetworkDenied = lanDenied+                        searchBarAtBottom = barAtBottom                          // Capture any tabs that were already created (e.g., from an external intent arriving before restore finishes)                         val preExisting = tabs.toList()@@ -577,6 +583,11 @@ class WebViewModel(         persistPrefs()     } +    fun updateSearchBarAtBottom(atBottom: Boolean) {+        searchBarAtBottom = atBottom+        persistPrefs()+    }+     // ---- PWA / Installed sites ----     fun installAsPwa(         tabId: String,@@ -849,6 +860,7 @@ class WebViewModel(                     .putBoolean(P_JS_ENABLED, jsEnabled)                     .putBoolean(P_BLOCK_THIRD_PARTY, blockThirdPartyCookies)                     .putBoolean(P_DESKTOP_MODE, desktopMode)+                    .putBoolean(P_SEARCH_BAR_BOTTOM, searchBarAtBottom)                     .putString(P_SHIELD_LEVEL, shields.level?.name)                     .putBoolean(P_SHIELD_TRACKERS, shields.blockTrackers != false)                     .putBoolean(P_SHIELD_COSMETIC, shields.cosmeticFiltering != false)
web/src/main/java/com/vayunmathur/web/ui/BrowserPage.kt
diff --git a/web/src/main/java/com/vayunmathur/web/ui/BrowserPage.kt b/web/src/main/java/com/vayunmathur/web/ui/BrowserPage.ktindex 91a01625bb..7cb29eb2a4 100644--- a/web/src/main/java/com/vayunmathur/web/ui/BrowserPage.kt+++ b/web/src/main/java/com/vayunmathur/web/ui/BrowserPage.kt@@ -15,11 +15,15 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer+import androidx.compose.foundation.layout.WindowInsets+import androidx.compose.foundation.layout.consumeWindowInsets import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height+import androidx.compose.foundation.layout.navigationBarsPadding import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size+import androidx.compose.foundation.layout.statusBars import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items@@ -169,47 +173,55 @@ fun BrowserPage(      Box(Modifier.fillMaxSize()) {         if (viewModel.omniboxFocused) {-            AppScaffold(-                title = {-                    OutlinedTextField(-                        value = viewModel.searchDraft,-                        onValueChange = { viewModel.searchDraft = it },-                        modifier = Modifier-                            .fillMaxWidth()-                            .focusRequester(searchFocusRequester),-                        placeholder = { Text(stringResource(R.string.search_or_enter_address)) },-                        leadingIcon = { IconSearch() },-                        trailingIcon = if (viewModel.searchDraft.isNotEmpty()) {-                            {-                                IconButton(onClick = { viewModel.searchDraft = "" }) { IconClose() }-                            }-                        } else null,-                        shape = RoundedCornerShape(28.dp),-                        singleLine = true,-                        keyboardOptions = KeyboardOptions(imeAction = ImeAction.Search),-                        keyboardActions = KeyboardActions(onSearch = {-                            if (viewModel.searchDraft.isNotBlank()) {-                                viewModel.navigateActiveTab(viewModel.searchDraft)-                                focusManager.clearFocus()-                                viewModel.omniboxFocused = false-                            }-                        })-                    )-                },-                navigationIcon = {-                    IconButton(onClick = {-                        focusManager.clearFocus()-                        viewModel.omniboxFocused = false-                    }) { IconBack() }-                },-                scrollBehavior = appBarScrollBehavior(),-            ) { paddingValues ->+            val omniboxField: @Composable (Modifier) -> Unit = { fieldModifier ->+                OutlinedTextField(+                    value = viewModel.searchDraft,+                    onValueChange = { viewModel.searchDraft = it },+                    modifier = fieldModifier.focusRequester(searchFocusRequester),+                    placeholder = { Text(stringResource(R.string.search_or_enter_address)) },+                    leadingIcon = { IconSearch() },+                    trailingIcon = if (viewModel.searchDraft.isNotEmpty()) {+                        {+                            IconButton(onClick = { viewModel.searchDraft = "" }) { IconClose() }+                        }+                    } else null,+                    shape = RoundedCornerShape(28.dp),+                    singleLine = true,+                    keyboardOptions = KeyboardOptions(imeAction = ImeAction.Search),+                    keyboardActions = KeyboardActions(onSearch = {+                        if (viewModel.searchDraft.isNotBlank()) {+                            viewModel.navigateActiveTab(viewModel.searchDraft)+                            focusManager.clearFocus()+                            viewModel.omniboxFocused = false+                        }+                    })+                )+            }+            val dismissOmnibox: @Composable () -> Unit = {+                IconButton(onClick = {+                    focusManager.clearFocus()+                    viewModel.omniboxFocused = false+                }) { IconBack() }+            }+            val suggestions: @Composable (PaddingValues) -> Unit = { paddingValues ->                 LazyColumn(                     modifier = Modifier                         .fillMaxSize()                         .padding(paddingValues),-                    verticalArrangement = Arrangement.spacedBy(2.dp),-                    contentPadding = PaddingValues(top = 8.dp, bottom = 24.dp)+                    // Anchored to the omnibox, so a short list stacks up from the field+                    // instead of hanging off the far edge of the screen. Note this is not+                    // reverseLayout: the section headers are separate items that have to+                    // stay above the rows they label.+                    verticalArrangement = if (viewModel.searchBarAtBottom) {+                        Arrangement.spacedBy(2.dp, Alignment.Bottom)+                    } else {+                        Arrangement.spacedBy(2.dp)+                    },+                    contentPadding = if (viewModel.searchBarAtBottom) {+                        PaddingValues(top = 24.dp, bottom = 8.dp)+                    } else {+                        PaddingValues(top = 8.dp, bottom = 24.dp)+                    }                 ) {                     if (currentDraft.isNotBlank()) {                         item {@@ -314,6 +326,33 @@ fun BrowserPage(                     }                 }             }+            if (viewModel.searchBarAtBottom) {+                // RAW SCAFFOLD EXCEPTION: with the toolbar at the bottom the editing+                // omnibox has no top bar at all, which AppScaffold cannot express - its+                // top bar is mandatory and would leave an empty bar hanging above the+                // suggestions.+                Scaffold(+                    bottomBar = {+                        Surface(Modifier.fillMaxWidth()) {+                            Row(+                                modifier = Modifier+                                    .navigationBarsPadding()+                                    .padding(start = 4.dp, end = 12.dp, top = 4.dp, bottom = 4.dp),+                                verticalAlignment = Alignment.CenterVertically,+                            ) {+                                dismissOmnibox()+                                omniboxField(Modifier.weight(1f))+                            }+                        }+                    },+                ) { paddingValues -> suggestions(paddingValues) }+            } else {+                AppScaffold(+                    title = { omniboxField(Modifier.fillMaxWidth()) },+                    navigationIcon = dismissOmnibox,+                    scrollBehavior = appBarScrollBehavior(),+                ) { paddingValues -> suggestions(paddingValues) }+            }         } else {             BrowserChrome(                 omniboxText = viewModel.omniboxText,@@ -321,6 +360,7 @@ fun BrowserPage(                 canGoBack = canGoBack,                 canGoForward = canGoForward,                 progress = if (activeTab != null && !isNewTabActive) progress else 0f,+                atBottom = viewModel.searchBarAtBottom,                 onBack = { if (canGoBack) activeTab?.let { webViewPool[it.id]?.goBack() } },                 onForward = { if (canGoForward) activeTab?.let { webViewPool[it.id]?.goForward() } },                 onOmniboxClick = {@@ -622,6 +662,7 @@ private fun BrowserChrome(     canGoBack: Boolean = false,     canGoForward: Boolean = false,     progress: Float = 0f,+    atBottom: Boolean = false,     onBack: () -> Unit = {},     onForward: () -> Unit = {},     onOmniboxClick: () -> Unit = {},@@ -633,62 +674,89 @@ private fun BrowserChrome(     menu: @Composable () -> Unit = {},     content: @Composable (PaddingValues) -> Unit, ) {-    // RAW SCAFFOLD EXCEPTION: bespoke browser toolbar chrome. The top bar is a+    // RAW SCAFFOLD EXCEPTION: bespoke browser toolbar chrome. The bar is a     // Column of a custom TopAppBar (back/forward nav row, a tappable read-only     // address pill as the title, and shield + tab-count + overflow-menu actions     // on a surface-colored bar) with a page LinearProgressIndicator drawn-    // underneath it. That composite bar has no equivalent in the shared-    // scaffolds, and the content is the full-bleed WebView.-    Scaffold(-        topBar = {-            Column {-                TopAppBar(-                    navigationIcon = {-                        Row(verticalAlignment = Alignment.CenterVertically) {-                            IconButton(onClick = onBack, enabled = canGoBack) { IconBack() }-                            IconButton(onClick = onForward, enabled = canGoForward) { IconArrowForward() }-                        }-                    },-                    title = {-                        DisplayOnlyAddressPill(-                            fullUrl = omniboxText,-                            onClick = onOmniboxClick,-                            modifier = Modifier.fillMaxWidth()-                        )-                    },-                    actions = {-                        if (shieldHost != null) {-                            ShieldChip(blockedCount = blockedCount, onClick = onShieldClick)-                            Spacer(Modifier.width(4.dp))-                        }-                        Surface(-                            shape = RoundedCornerShape(20.dp),-                            color = MaterialTheme.colorScheme.secondaryContainer,-                            modifier = Modifier-                                .clip(RoundedCornerShape(20.dp))-                                .clickable(onClick = onTabSwitcherClick)-                        ) {-                            Text(-                                text = tabCount.toString(),-                                style = MaterialTheme.typography.labelLarge,-                                modifier = Modifier.padding(horizontal = 14.dp, vertical = 8.dp)-                            )-                        }+    // alongside it, and it can sit in either the top or the bottom slot. That+    // composite bar has no equivalent in the shared scaffolds, and the content+    // is the full-bleed WebView.+    val bar: @Composable () -> Unit = {+        // At the bottom, TopAppBar's hardcoded top inset would be a status bar's+        // height of dead space, and nothing else applies the navigation bar inset.+        // The bar's own container color stops at the padding, so the surface is+        // painted here instead to reach the screen edge. The IME inset is left alone+        // on purpose: MainNavigation already owns it, and navigationBarsPadding+        // resolves to zero once the keyboard has consumed more than a navigation+        // bar's height.+        val barModifier = if (atBottom) {+            Modifier+                .background(MaterialTheme.colorScheme.surface)+                .navigationBarsPadding()+                .consumeWindowInsets(WindowInsets.statusBars)+        } else {+            Modifier+        }+        Column(barModifier) {+            // The progress bar belongs against the web content, so it moves to the+            // far side of the toolbar when the toolbar moves to the bottom.+            if (atBottom) PageProgress(progress)+            TopAppBar(+                navigationIcon = {+                    Row(verticalAlignment = Alignment.CenterVertically) {+                        IconButton(onClick = onBack, enabled = canGoBack) { IconBack() }+                        IconButton(onClick = onForward, enabled = canGoForward) { IconArrowForward() }+                    }+                },+                title = {+                    DisplayOnlyAddressPill(+                        fullUrl = omniboxText,+                        onClick = onOmniboxClick,+                        modifier = Modifier.fillMaxWidth()+                    )+                },+                actions = {+                    if (shieldHost != null) {+                        ShieldChip(blockedCount = blockedCount, onClick = onShieldClick)                         Spacer(Modifier.width(4.dp))-                        IconButton(onClick = onMenuClick) { IconMoreVert() }-                        menu()-                    },-                    colors = TopAppBarDefaults.topAppBarColors(containerColor = MaterialTheme.colorScheme.surface)-                )-                if (progress in 0.01f..0.99f) {-                    LinearProgressIndicator(progress = { progress }, modifier = Modifier.fillMaxWidth().height(2.dp))-                }-            }-        },+                    }+                    Surface(+                        shape = RoundedCornerShape(20.dp),+                        color = MaterialTheme.colorScheme.secondaryContainer,+                        modifier = Modifier+                            .clip(RoundedCornerShape(20.dp))+                            .clickable(onClick = onTabSwitcherClick)+                    ) {+                        Text(+                            text = tabCount.toString(),+                            style = MaterialTheme.typography.labelLarge,+                            modifier = Modifier.padding(horizontal = 14.dp, vertical = 8.dp)+                        )+                    }+                    Spacer(Modifier.width(4.dp))+                    IconButton(onClick = onMenuClick) { IconMoreVert() }+                    menu()+                },+                colors = TopAppBarDefaults.topAppBarColors(containerColor = MaterialTheme.colorScheme.surface)+            )+            if (!atBottom) PageProgress(progress)+        }+    }+    Scaffold(+        topBar = { if (!atBottom) bar() },+        bottomBar = { if (atBottom) bar() },         content = content,     ) } +/** The page load indicator, drawn only while a load is actually in flight. */+@Composable+private fun PageProgress(progress: Float) {+    if (progress in 0.01f..0.99f) {+        LinearProgressIndicator(progress = { progress }, modifier = Modifier.fillMaxWidth().height(2.dp))+    }+}+ /**  * Toolbar shield. Shows the number of requests blocked on the current page, which is the  * only feedback the user gets that shields are doing anything.
web/src/main/java/com/vayunmathur/web/ui/SettingsPage.kt
diff --git a/web/src/main/java/com/vayunmathur/web/ui/SettingsPage.kt b/web/src/main/java/com/vayunmathur/web/ui/SettingsPage.ktindex e0c2f8e488..6af292011d 100644--- a/web/src/main/java/com/vayunmathur/web/ui/SettingsPage.kt+++ b/web/src/main/java/com/vayunmathur/web/ui/SettingsPage.kt@@ -93,6 +93,16 @@ fun SettingsPage(                 )             } +            item {+                ListItem(+                    headlineContent = { Text(stringResource(R.string.toolbar_at_bottom)) },+                    supportingContent = { Text(stringResource(R.string.keeps_the_address_bar_within_thumb_reach)) },+                    trailingContent = {+                        Switch(checked = viewModel.searchBarAtBottom, onCheckedChange = { viewModel.updateSearchBarAtBottom(it) })+                    }+                )+            }+             item {                 ListItem(                     headlineContent = { Text(stringResource(R.string.javascript)) },
web/src/main/res/values/strings.xml
diff --git a/web/src/main/res/values/strings.xml b/web/src/main/res/values/strings.xmlindex 38c4eb0fdb..910ce40422 100644--- a/web/src/main/res/values/strings.xml+++ b/web/src/main/res/values/strings.xml@@ -25,6 +25,8 @@     <string name="may_break_logins">May break logins</string>     <string name="desktop_mode">Desktop mode</string>     <string name="request_desktop_site">Request desktop site</string>+    <string name="toolbar_at_bottom">Toolbar at bottom</string>+    <string name="keeps_the_address_bar_within_thumb_reach">Keeps the address bar within thumb reach</string>     <string name="ad_tracker_blocking">Ad-tracker blocking</string>     <string name="blocks_doubleclick_googletagmanager_anal">Blocks doubleclick, googletagmanager, analytics</string>     <string name="privacy_data">Privacy &amp; data</string>