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

Commit

Permalink
Merge #6896
Browse files Browse the repository at this point in the history
6896: For #6895: Add optional itemDecoration in browser tabs tray. r=psymoon a=mcarare



Co-authored-by: mcarare <[email protected]>
  • Loading branch information
MozLando and mcarare committed May 7, 2020
2 parents bfdf33e + 63b71a0 commit 9adccaa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package mozilla.components.browser.tabstray
import android.content.Context
import android.util.AttributeSet
import android.view.View
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import mozilla.components.concept.tabstray.TabsTray
Expand All @@ -24,7 +25,8 @@ class BrowserTabsTray @JvmOverloads constructor(
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
val tabsAdapter: TabsAdapter = TabsAdapter(),
layout: LayoutManager = GridLayoutManager(context, 2)
layout: LayoutManager = GridLayoutManager(context, 2),
itemDecoration: DividerItemDecoration? = null
) : RecyclerView(context, attrs, defStyleAttr),
TabsTray by tabsAdapter {

Expand All @@ -35,6 +37,7 @@ class BrowserTabsTray @JvmOverloads constructor(

layoutManager = layout
adapter = tabsAdapter
itemDecoration?.let { addItemDecoration(it) }

val attr = context.obtainStyledAttributes(attrs, R.styleable.BrowserTabsTray, defStyleAttr, 0)
styling = TabsTrayStyling(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package mozilla.components.browser.tabstray

import androidx.recyclerview.widget.DividerItemDecoration
import androidx.test.ext.junit.runners.AndroidJUnit4
import mozilla.components.concept.tabstray.Tabs
import mozilla.components.support.test.mock
Expand Down Expand Up @@ -46,4 +47,17 @@ class BrowserTabsTrayTest {

assertEquals(tabsTray, adapter.tabsTray)
}

@Test
fun `itemDecoration is set on recycler`() {
val adapter = TabsAdapter()
val decoration = DividerItemDecoration(
testContext,
DividerItemDecoration.VERTICAL
)
val tabsTray = BrowserTabsTray(testContext, tabsAdapter = adapter, itemDecoration = decoration)

assertEquals(decoration, tabsTray.getItemDecorationAt(0))
assertEquals(decoration, adapter.tabsTray.getItemDecorationAt(0))
}
}
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ permalink: /changelog/
* **browser-menu**
* BrowserMenu will now support dynamic width based on two new attributes: `mozac_browser_menu_width_min` and `mozac_browser_menu_width_max`.

* **browser-tabstray**
* Added optional `itemDecoration` DividerItemDecoration parameter to `BrowserTabsTray` constructor to allow the clients to add their own dividers. This is used to ensure setting divider item decoration after setAdapter() is called.

# 40.0.0

* [Commits](https://github.com/mozilla-mobile/android-components/compare/v39.0.0...v40.0.0)
Expand Down

0 comments on commit 9adccaa

Please sign in to comment.