forked from mozilla-mobile/fenix
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For mozilla-mobile#11862 - Add swipe to show tab tray gesture for bot…
…tom toolbar. - Create a new gestures package for classes that implement gestures that work on multiple screens - Move SwipeGestureLayout to the gestures package - Rename ToolbarGestureHandler to SwitchTabsGestureListener - Gate swipe to show tab tray behind the same feature flag as swipe to switch tabs - Update home fragment snackbars to explicitly pass a CoordinatorLayout as the view to attach them to - Extract common gesture function into utility file.
- Loading branch information
Showing
8 changed files
with
148 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
app/src/main/java/org/mozilla/fenix/gestures/GestureUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* 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.gestures | ||
|
||
import android.graphics.PointF | ||
import android.view.View | ||
import androidx.core.graphics.contains | ||
import androidx.core.graphics.toPoint | ||
import org.mozilla.fenix.ext.getRectWithScreenLocation | ||
import org.mozilla.fenix.ext.getWindowInsets | ||
import org.mozilla.fenix.ext.settings | ||
|
||
/** | ||
* Checks if a point is within the bounds of a toolbar view. This accounts for the overlap | ||
* between the bottom toolbar and the system gesture area. | ||
*/ | ||
fun PointF.isInToolbar(toolbar: View): Boolean { | ||
val toolbarLocation = toolbar.getRectWithScreenLocation() | ||
// In Android 10, the system gesture touch area overlaps the bottom of the toolbar, so | ||
// lets make our swipe area taller by that amount | ||
toolbar.getWindowInsets()?.let { insets -> | ||
if (toolbar.context.settings().shouldUseBottomToolbar) { | ||
toolbarLocation.top -= (insets.mandatorySystemGestureInsets.bottom - insets.stableInsetBottom) | ||
} | ||
} | ||
return toolbarLocation.contains(toPoint()) | ||
} |
45 changes: 45 additions & 0 deletions
45
app/src/main/java/org/mozilla/fenix/gestures/ShowTabTrayGestureListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* 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.gestures | ||
|
||
import android.app.Activity | ||
import android.graphics.PointF | ||
import android.view.View | ||
import android.view.ViewConfiguration | ||
import org.mozilla.fenix.components.toolbar.ToolbarPosition | ||
import org.mozilla.fenix.ext.components | ||
import org.mozilla.fenix.ext.isKeyboardVisible | ||
import kotlin.math.abs | ||
|
||
class ShowTabTrayGestureListener( | ||
private val activity: Activity, | ||
private val toolbarLayout: View, | ||
private val showTabTray: () -> Unit | ||
) : SwipeGestureListener { | ||
|
||
private val touchSlop = ViewConfiguration.get(activity).scaledTouchSlop | ||
private val minimumFlingVelocity = ViewConfiguration.get(activity).scaledMinimumFlingVelocity | ||
|
||
override fun onSwipeStarted(start: PointF, next: PointF): Boolean { | ||
val dx = next.x - start.x | ||
// negative dy = swiping up | ||
val dy = next.y - start.y | ||
|
||
return activity.components.settings.toolbarPosition == ToolbarPosition.BOTTOM && | ||
!toolbarLayout.isKeyboardVisible() && start.isInToolbar(toolbarLayout) && | ||
-dy >= touchSlop && abs(dx) < abs(dy) | ||
} | ||
|
||
override fun onSwipeUpdate(distanceX: Float, distanceY: Float) { | ||
// Do nothing | ||
} | ||
|
||
override fun onSwipeFinished(velocityX: Float, velocityY: Float) { | ||
// Negative velocityY = swiping up | ||
if (-velocityY >= minimumFlingVelocity) { | ||
showTabTray.invoke() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- 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/. --> | ||
<org.mozilla.fenix.gestures.SwipeGestureLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/gestureLayout" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<include layout="@layout/fragment_browser" /> | ||
|
||
<org.mozilla.fenix.browser.TabPreview | ||
android:id="@+id/tabPreview" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:clickable="false" | ||
android:focusable="false" | ||
android:visibility="gone" /> | ||
</org.mozilla.fenix.gestures.SwipeGestureLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- 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/. --> | ||
|
||
<org.mozilla.fenix.gestures.SwipeGestureLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/gestureLayout" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<include layout="@layout/fragment_home" /> | ||
</org.mozilla.fenix.gestures.SwipeGestureLayout> |