pgreze / android-reactions

Facebook like reaction picker for Android
Apache License 2.0
158 stars 46 forks source link

Delegate Touch Event Without lifting the finger #35

Open lazy-coder-10 opened 3 years ago

lazy-coder-10 commented 3 years ago

How can I select an item without lifting the finger on a long press? I have implemented the long-press but unable to select items I have to release my finger than only I am able to select the items. Would be great if you can help me.

TalverseZaidi commented 2 years ago

You can use the below mentioned code in the block of setReactions function, this is the only way to do achieve long press without lifting a finger. reactionBtutton.setOnTouchListener(popup) reactionBtutton.setOnTouchListener { arg0, arg1 -> when (arg1.action) { MotionEvent.ACTION_DOWN -> { timer = Timer() timer.schedule(object : TimerTask() { override fun run() { CoroutineScope( Dispatchers.Main ).launch { popup.onTouch(arg0, arg1) } } }, 300) //time out 1/2s } MotionEvent.ACTION_UP -> { timer.cancel() } else -> false } false }