Bug 1927778 - Adjust margins for display toolbar. r=android-reviewers,jonalmeida, a=dmeehan

Differential Revision: https://phabricator.services.mozilla.com/D227319
This commit is contained in:
mcarare 2024-10-30 15:48:11 +00:00
parent 1efd4dc45a
commit e9ba0468a3
4 changed files with 56 additions and 0 deletions

View File

@ -142,6 +142,17 @@ class DisplayToolbar internal constructor(
BOTTOM,
}
/**
* Data class holding the customizable margins for views in "display mode".
*
* @property goneStartMargin The start margin to be applied when the constraint target is gone.
* @property goneEndMargin The end margin to be applied when the constraint target is gone.
*/
data class DisplayMargins(
val goneStartMargin: Int?,
val goneEndMargin: Int?,
)
internal val views = DisplayToolbarViews(
browserActions = rootView.findViewById(R.id.mozac_browser_toolbar_browser_actions),
pageActions = rootView.findViewById(R.id.mozac_browser_toolbar_page_actions),
@ -309,6 +320,24 @@ class DisplayToolbar internal constructor(
views.background.setImageDrawable(background)
}
/**
* Sets the margins for the background view using the provided DisplayMargins.
*
* @param margins The DisplayMargins containing the start and end margins to be applied.
*/
fun setUrlBackgroundMargins(margins: DisplayMargins) {
val layoutParams = views.background.layoutParams as? ConstraintLayout.LayoutParams
layoutParams?.let {
margins.goneStartMargin?.let { goneStartMargin ->
it.goneStartMargin = goneStartMargin
}
margins.goneEndMargin?.let { goneEndMargin ->
it.goneEndMargin = goneEndMargin
}
}
}
/**
* Whether the progress bar should be drawn at the top or bottom of the toolbar.
*/

View File

@ -7,6 +7,7 @@ package mozilla.components.browser.toolbar.display
import android.graphics.Color
import android.os.Build
import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat
import androidx.core.view.isGone
import androidx.core.view.isVisible
@ -570,6 +571,22 @@ class DisplayToolbarTest {
assertNull(displayToolbar.views.background.drawable)
}
@Test
fun `setUrlBackgroundMargins sets the correct margins`() {
val (_, displayToolbar) = createDisplayToolbar()
val margins = DisplayToolbar.DisplayMargins(
goneStartMargin = 16,
goneEndMargin = 8,
)
displayToolbar.setUrlBackgroundMargins(margins)
val layoutParams = displayToolbar.views.background.layoutParams as? ConstraintLayout.LayoutParams
assertNotNull(layoutParams)
assertEquals(margins.goneStartMargin, layoutParams?.goneStartMargin)
assertEquals(margins.goneEndMargin, layoutParams?.goneEndMargin)
}
@Test
fun `titleView does not display when there is no title text`() {
val (_, displayToolbar) = createDisplayToolbar()

View File

@ -22,6 +22,10 @@ permalink: /changelog/
* **ui-widgets**
* 🆕 New `mozac_material_ripple_minimum_interaction_size` drawable for a 48dp ripple to be used when `selectableItemBackgroundBorderless` is too big and `selectableItemBackground` is too small. [Bug 1920554](https://bugzilla.mozilla.org/show_bug.cgi?id=1920554).
* **browser-toolbar**
* Added internal data class `DisplayMargins` in `DisplayToolbar` class that can be used to specify margins for `DisplayToolbar`'s views
* Added `setUrlBackgroundMargins` method in `DisplayToolbar` class that client apps can use to specify custom `DisplayMargins` for the `background` view. [Bug 1927778](https://bugzilla.mozilla.org/show_bug.cgi?id=1927778)
# 132.0
* **feature-awesomebar**
* The `onCancelEditing` now returns a result based on the `onStartEditing` and `onStopEditing` callback. [Bug 1917496](https://bugzilla.mozilla.org/show_bug.cgi?id=1917496)

View File

@ -18,12 +18,14 @@ import kotlinx.coroutines.flow.mapNotNull
import mozilla.components.browser.domains.autocomplete.CustomDomainsProvider
import mozilla.components.browser.domains.autocomplete.ShippedDomainsProvider
import mozilla.components.browser.toolbar.BrowserToolbar
import mozilla.components.browser.toolbar.display.DisplayToolbar.DisplayMargins
import mozilla.components.compose.cfr.CFRPopup
import mozilla.components.compose.cfr.CFRPopupProperties
import mozilla.components.concept.toolbar.AutocompleteResult
import mozilla.components.concept.toolbar.Toolbar
import mozilla.components.lib.state.ext.flowScoped
import mozilla.components.support.base.feature.LifecycleAwareFeature
import mozilla.components.support.ktx.android.util.dpToPx
import org.mozilla.focus.R
import org.mozilla.focus.ext.components
import org.mozilla.focus.ext.settings
@ -118,6 +120,10 @@ class InputToolbarIntegration(
)
toolbar.display.setUrlBackground(urlBackground)
toolbar.display.setUrlBackgroundMargins(
DisplayMargins(8.dpToPx(toolbar.resources.displayMetrics), 0),
)
toolbar.edit.setUrlBackground(urlBackground)
}