2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-19 09:25:34 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/8080: Dismiss menu when swiping away from its anchor.

This commit is contained in:
mcarare 2020-06-24 15:21:50 +03:00 committed by Emily Kager
parent a4b2acd0cd
commit 37f9964f1c

View File

@ -4,8 +4,11 @@
package org.mozilla.fenix.home.sessioncontrol.viewholders.topsites package org.mozilla.fenix.home.sessioncontrol.viewholders.topsites
import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.view.MotionEvent
import android.view.View import android.view.View
import android.widget.PopupWindow
import kotlinx.android.synthetic.main.top_site_item.* import kotlinx.android.synthetic.main.top_site_item.*
import kotlinx.android.synthetic.main.top_site_item.view.* import kotlinx.android.synthetic.main.top_site_item.view.*
import mozilla.components.browser.menu.BrowserMenuBuilder import mozilla.components.browser.menu.BrowserMenuBuilder
@ -40,7 +43,10 @@ class TopSiteItemViewHolder(
} }
top_site_item.setOnLongClickListener() { top_site_item.setOnLongClickListener() {
topSiteMenu.menuBuilder.build(view.context).show(anchor = it.top_site_title) val menu = topSiteMenu.menuBuilder.build(view.context).show(anchor = it.top_site_title)
it.setOnTouchListener @SuppressLint("ClickableViewAccessibility") { v, event ->
onTouchEvent(v, event, menu)
}
return@setOnLongClickListener true return@setOnLongClickListener true
} }
} }
@ -58,6 +64,17 @@ class TopSiteItemViewHolder(
} }
} }
private fun onTouchEvent(
v: View,
event: MotionEvent,
menu: PopupWindow
): Boolean {
if (event.action == MotionEvent.ACTION_CANCEL) {
menu.dismiss()
}
return v.onTouchEvent(event)
}
companion object { companion object {
const val LAYOUT_ID = R.layout.top_site_item const val LAYOUT_ID = R.layout.top_site_item
} }