1
0
Fork 0

For #8080: Dismiss menu when swiping away from its anchor.

master
mcarare 2020-06-24 15:21:50 +03:00 committed by Emily Kager
parent b961fdcf02
commit a056e86e4f
1 changed files with 18 additions and 1 deletions

View File

@ -4,8 +4,11 @@
package org.mozilla.fenix.home.sessioncontrol.viewholders.topsites
import android.annotation.SuppressLint
import android.content.Context
import android.view.MotionEvent
import android.view.View
import android.widget.PopupWindow
import kotlinx.android.synthetic.main.top_site_item.*
import kotlinx.android.synthetic.main.top_site_item.view.*
import mozilla.components.browser.menu.BrowserMenuBuilder
@ -40,7 +43,10 @@ class TopSiteItemViewHolder(
}
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
}
}
@ -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 {
const val LAYOUT_ID = R.layout.top_site_item
}