Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Closes #2392 - Add ability for progress bar to be displayed on top of… #2393

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions components/browser/toolbar/README.md
Expand Up @@ -26,6 +26,7 @@ implementation "org.mozilla.components:browser-toolbar:{latest-version}"
| browserToolbarSuggestionBackgroundColor | color | Background color of the autocomplete suggestion. |
| browserToolbarSuggestionForegroundColor | color | Foreground (text) color of the autocomplete suggestion. |
| browserToolbarFadingEdgeSize | dimension | Size of the fading edge shown when the URL is too long. |
| topProgressBar | boolean | Boolean for progress bar to be at the top of toolbar. |

## Facts

Expand Down
Expand Up @@ -181,6 +181,15 @@ class BrowserToolbar @JvmOverloads constructor(
editToolbar.urlView.setHintTextColor(value)
}

/**
* Set progress bar to be at the top of the toolbar. It's on bottom by default.
*/
var topProgressBar: Boolean
get() = displayToolbar.topProgressBar
set(value) {
displayToolbar.topProgressBar = value
}

/**
* Sets the colour of the text for the URL/search term displayed in the toolbar.
*/
Expand Down Expand Up @@ -281,6 +290,10 @@ class BrowserToolbar @JvmOverloads constructor(
init {
context.obtainStyledAttributes(attrs, R.styleable.BrowserToolbar, defStyleAttr, 0).run {
attrs?.let {
topProgressBar = getBoolean(
R.styleable.BrowserToolbar_topProgressBar,
false
)
hintColor = getColor(
R.styleable.BrowserToolbar_browserToolbarHintColor,
hintColor
Expand Down
Expand Up @@ -139,6 +139,9 @@ internal class DisplayToolbar(
// Margin between browser actions.
internal var browserActionMargin = 0

// Set if progress bar should be at the top of the toolbar
internal var topProgressBar = false

// Horizontal margin of URL Box (surrounding URL and page actions).
internal var urlBoxMargin = 0

Expand Down Expand Up @@ -344,6 +347,7 @@ internal class DisplayToolbar(
}

// We layout the toolbar ourselves to avoid the overhead from using complex ViewGroup implementations
@Suppress("ComplexMethod")
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
// First we layout the navigation actions if there are any:
// +-------------+------------------------------------------------+
Expand Down Expand Up @@ -434,9 +438,11 @@ internal class DisplayToolbar(
val urlLeft = navigationActionsWidth + iconWidth + urlBoxMargin
urlView.layout(urlLeft, 0, urlLeft + urlView.measuredWidth, measuredHeight)

// The progress bar is going to be drawn at the bottom of the toolbar:
// The progress bar by default is going to be drawn at the bottom of the toolbar, top if defined:

progressView.layout(0, measuredHeight - progressView.measuredHeight, measuredWidth, measuredHeight)
progressView.layout(0, if (topProgressBar) 0 else measuredHeight - progressView.measuredHeight,
measuredWidth, if (topProgressBar) progressView.measuredHeight else measuredHeight
)

// The URL box view (if exists) is positioned behind the icon, the url and page actions:

Expand Down
Expand Up @@ -15,5 +15,6 @@
<attr name="browserToolbarSuggestionForegroundColor" format="color" />
<attr name="browserToolbarClearColor" format="color"/>
<attr name="browserToolbarFadingEdgeSize" format="dimension" />
<attr name="topProgressBar" format="boolean" />
</declare-styleable>
</resources>
Expand Up @@ -108,6 +108,21 @@ class DisplayToolbarTest {
assertEquals(3, progressView.measuredHeight)
}

@Test
fun `progress view changes with topProgressBar`() {
val toolbar = mock(BrowserToolbar::class.java)
val displayToolbar = DisplayToolbar(context, toolbar)
val progressView = extractProgressView(displayToolbar)

displayToolbar.topProgressBar = true
assertEquals(true, displayToolbar.topProgressBar)
assertEquals(progressView.measuredHeight, progressView.bottom)

displayToolbar.topProgressBar = false
assertEquals(false, displayToolbar.topProgressBar)
assertEquals(toolbar.measuredHeight, progressView.bottom)
}

@Test
fun `menu view is gone by default`() {
val toolbar = mock(BrowserToolbar::class.java)
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.md
Expand Up @@ -23,6 +23,7 @@ permalink: /changelog/
* Adds `onCancelEditing` to `onEditListener` in `BrowserToolbar` which is fired when a back button press occurs while the keyboard is displayed.
This is especially useful if you want to call `activity.onBackPressed()` to navigate away rather than just dismiss the keyboard.
Its return value is used to determine if `displayMode` will switch from edit to view.
* Adds `topProgressBar` `Boolean` attr to give option for progress bar to be displayed at top of the toolbar.

* **concept-sync**
* 🆕 New component which describes sync-related interfaces, such as SyncManager, SyncableStore, SyncStatusObserver and others.
Expand Down