diff --git a/components/browser/tabstray/src/main/java/mozilla/components/browser/tabstray/BrowserTabsTray.kt b/components/browser/tabstray/src/main/java/mozilla/components/browser/tabstray/BrowserTabsTray.kt index f8f4b31f5d1..6d54cdc0843 100644 --- a/components/browser/tabstray/src/main/java/mozilla/components/browser/tabstray/BrowserTabsTray.kt +++ b/components/browser/tabstray/src/main/java/mozilla/components/browser/tabstray/BrowserTabsTray.kt @@ -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 @@ -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 { @@ -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( diff --git a/components/browser/tabstray/src/test/java/mozilla/components/browser/tabstray/BrowserTabsTrayTest.kt b/components/browser/tabstray/src/test/java/mozilla/components/browser/tabstray/BrowserTabsTrayTest.kt index f197162c7a4..8fdfed392cf 100644 --- a/components/browser/tabstray/src/test/java/mozilla/components/browser/tabstray/BrowserTabsTrayTest.kt +++ b/components/browser/tabstray/src/test/java/mozilla/components/browser/tabstray/BrowserTabsTrayTest.kt @@ -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 @@ -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)) + } } diff --git a/docs/changelog.md b/docs/changelog.md index 72f6f9e283c..d3560d6c83a 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -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)