Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Adds swipe to delete tab (#10355)
Browse files Browse the repository at this point in the history
* No Issue - Increases tap area of close button

* For #10331 - Adds swipe to delete to the tab tray
  • Loading branch information
boek authored May 1, 2020
1 parent 3dcd52e commit 94cd195
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.mozilla.fenix.ext.requireComponents
import androidx.navigation.fragment.findNavController
import mozilla.components.browser.session.Session
import mozilla.components.browser.session.SessionManager
import mozilla.components.browser.tabstray.BrowserTabsTray
import mozilla.components.concept.tabstray.Tab
import mozilla.components.concept.tabstray.TabsTray
import org.mozilla.fenix.BrowserDirection
Expand Down Expand Up @@ -51,6 +52,10 @@ class TabTrayFragment : Fragment(R.layout.fragment_tab_tray), TabsTray.Observer,
showToolbar(getString(R.string.tab_tray_title))
onTabsChanged()

(tabsTray as? BrowserTabsTray)?.also { tray ->
TabsTouchHelper(tray.tabsAdapter).attachToRecyclerView(tray)
}

sessionManager.register(observer = object : SessionManager.Observer {
override fun onSessionAdded(session: Session) {
onTabsChanged()
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/java/org/mozilla/fenix/tabtray/TabsTouchHelper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.fenix.tabtray

import androidx.recyclerview.widget.ItemTouchHelper
import mozilla.components.browser.tabstray.TabTouchCallback
import mozilla.components.concept.tabstray.TabsTray
import mozilla.components.support.base.observer.Observable

class TabsTouchHelper(observable: Observable<TabsTray.Observer>) :
ItemTouchHelper(object : TabTouchCallback(observable) {
override fun alphaForItemSwipe(dX: Float, distanceToAlphaMin: Int): Float {
return 1f - 2f * Math.abs(dX) / distanceToAlphaMin
}
})
8 changes: 2 additions & 6 deletions app/src/main/res/layout/tab_tray_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
android:textSize="16sp"
android:paddingTop="22dp"
android:paddingStart="16dp"
android:layout_marginEnd="20dp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintEnd_toStartOf="@id/mozac_browser_tabstray_close"
app:layout_constraintStart_toEndOf="@id/mozac_browser_tabstray_card"
Expand All @@ -59,18 +58,15 @@
android:lines="1"
android:textSize="14sp"
android:paddingStart="16dp"
android:layout_marginEnd="20dp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintEnd_toStartOf="@id/mozac_browser_tabstray_close"
app:layout_constraintStart_toEndOf="@id/mozac_browser_tabstray_card"
app:layout_constraintTop_toBottomOf="@id/mozac_browser_tabstray_title" />

<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/mozac_browser_tabstray_close"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="16dp"
android:layout_width="56dp"
android:layout_height="match_parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
Expand Down

0 comments on commit 94cd195

Please sign in to comment.