Bug 1940628 - Add an URL background to BrowserEditToolbar r=android-reviewers,petru

- Adds a customizable URL background color to BrowserEditToolbar

Differential Revision: https://phabricator.services.mozilla.com/D233606
This commit is contained in:
Gabriel Luong
2025-02-19 03:24:28 +00:00
parent bcf1416756
commit 7a79aaa63e
5 changed files with 78 additions and 53 deletions

View File

@@ -4,8 +4,12 @@
package mozilla.components.compose.browser.toolbar package mozilla.components.compose.browser.toolbar
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.requiredSize import androidx.compose.foundation.layout.requiredSize
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardActions import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.Icon import androidx.compose.material.Icon
@@ -13,6 +17,7 @@ import androidx.compose.material.IconButton
import androidx.compose.material.TextField import androidx.compose.material.TextField
import androidx.compose.material.TextFieldDefaults import androidx.compose.material.TextFieldDefaults
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
@@ -24,6 +29,8 @@ import androidx.compose.ui.unit.dp
import mozilla.components.compose.base.theme.AcornTheme import mozilla.components.compose.base.theme.AcornTheme
import mozilla.components.ui.icons.R as iconsR import mozilla.components.ui.icons.R as iconsR
private val ROUNDED_CORNER_SHAPE = RoundedCornerShape(8.dp)
/** /**
* Sub-component of the [BrowserToolbar] responsible for allowing the user to edit the current * Sub-component of the [BrowserToolbar] responsible for allowing the user to edit the current
* URL ("edit mode"). * URL ("edit mode").
@@ -44,14 +51,23 @@ fun BrowserEditToolbar(
onUrlCommitted: (String) -> Unit = {}, onUrlCommitted: (String) -> Unit = {},
editActions: @Composable () -> Unit = {}, editActions: @Composable () -> Unit = {},
) { ) {
Row(
modifier = Modifier
.background(color = colors.background)
.padding(all = 8.dp)
.background(
color = colors.urlBackground,
shape = ROUNDED_CORNER_SHAPE,
),
verticalAlignment = Alignment.CenterVertically,
) {
TextField( TextField(
url, value = url,
onValueChange = { value -> onValueChange = { value ->
onUrlEdit(value) onUrlEdit(value)
}, },
colors = TextFieldDefaults.textFieldColors( colors = TextFieldDefaults.textFieldColors(
textColor = colors.text, textColor = colors.text,
backgroundColor = colors.background,
focusedIndicatorColor = Color.Transparent, focusedIndicatorColor = Color.Transparent,
unfocusedIndicatorColor = Color.Transparent, unfocusedIndicatorColor = Color.Transparent,
disabledIndicatorColor = Color.Transparent, disabledIndicatorColor = Color.Transparent,
@@ -66,6 +82,7 @@ fun BrowserEditToolbar(
onGo = { onUrlCommitted(url) }, onGo = { onUrlCommitted(url) },
), ),
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
shape = ROUNDED_CORNER_SHAPE,
trailingIcon = { trailingIcon = {
editActions() editActions()
@@ -77,6 +94,7 @@ fun BrowserEditToolbar(
} }
}, },
) )
}
} }
/** /**

View File

@@ -32,11 +32,13 @@ data class BrowserDisplayToolbarColors(
* Represents the colors used by the browser edit toolbar. * Represents the colors used by the browser edit toolbar.
* *
* @property background Background color of the toolbar. * @property background Background color of the toolbar.
* @property urlBackground Background color of the URL text field.
* @property text Text color of the URL. * @property text Text color of the URL.
* @property clearButton Color tint for the icon shown when the URL is empty. * @property clearButton Color tint for the icon shown when the URL is empty.
*/ */
data class BrowserEditToolbarColors( data class BrowserEditToolbarColors(
val background: Color, val background: Color,
val urlBackground: Color,
val text: Color, val text: Color,
val clearButton: Color, val clearButton: Color,
) )

View File

@@ -25,6 +25,7 @@ object BrowserToolbarDefaults {
), ),
editToolbarColors: BrowserEditToolbarColors = BrowserEditToolbarColors( editToolbarColors: BrowserEditToolbarColors = BrowserEditToolbarColors(
background = AcornTheme.colors.layer1, background = AcornTheme.colors.layer1,
urlBackground = AcornTheme.colors.layer3,
text = AcornTheme.colors.textPrimary, text = AcornTheme.colors.textPrimary,
clearButton = AcornTheme.colors.iconPrimary, clearButton = AcornTheme.colors.iconPrimary,
), ),

View File

@@ -45,6 +45,7 @@ dependencies {
implementation project(':browser-menu2') implementation project(':browser-menu2')
implementation project(':browser-domains') implementation project(':browser-domains')
implementation project(':browser-state') implementation project(':browser-state')
implementation project(':compose-base')
implementation project(':compose-browser-toolbar') implementation project(':compose-browser-toolbar')
implementation project(':ui-colors') implementation project(':ui-colors')

View File

@@ -39,6 +39,7 @@ import mozilla.components.browser.menu.item.SimpleBrowserMenuItem
import mozilla.components.browser.menu2.BrowserMenuController import mozilla.components.browser.menu2.BrowserMenuController
import mozilla.components.browser.toolbar.BrowserToolbar import mozilla.components.browser.toolbar.BrowserToolbar
import mozilla.components.browser.toolbar.display.DisplayToolbar import mozilla.components.browser.toolbar.display.DisplayToolbar
import mozilla.components.compose.base.theme.AcornTheme
import mozilla.components.compose.browser.toolbar.store.BrowserEditToolbarAction import mozilla.components.compose.browser.toolbar.store.BrowserEditToolbarAction
import mozilla.components.compose.browser.toolbar.store.BrowserToolbarAction import mozilla.components.compose.browser.toolbar.store.BrowserToolbarAction
import mozilla.components.compose.browser.toolbar.store.BrowserToolbarStore import mozilla.components.compose.browser.toolbar.store.BrowserToolbarStore
@@ -489,6 +490,7 @@ class ToolbarActivity : AppCompatActivity() {
showToolbar(isCompose = true) showToolbar(isCompose = true)
binding.composeToolbar.setContent { binding.composeToolbar.setContent {
AcornTheme {
val store = remember { val store = remember {
BrowserToolbarStore() BrowserToolbarStore()
} }
@@ -513,6 +515,7 @@ class ToolbarActivity : AppCompatActivity() {
) )
} }
} }
}
private fun showToolbar(isCompose: Boolean = false) { private fun showToolbar(isCompose: Boolean = false) {
binding.toolbar.isVisible = !isCompose binding.toolbar.isVisible = !isCompose