For #8080: Dismiss menu when swiping away from its anchor.
parent
b961fdcf02
commit
a056e86e4f
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue