Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RecyclerView click event getting blocked #233

Closed
gbhaumikkumar14 opened this issue Apr 15, 2020 · 24 comments
Closed

RecyclerView click event getting blocked #233

gbhaumikkumar14 opened this issue Apr 15, 2020 · 24 comments

Comments

@gbhaumikkumar14
Copy link

gbhaumikkumar14 commented Apr 15, 2020

  • Markwon version: 4.3.1

When i set any text using below code, parent recyclerview item view click is not working.

Markwon markwon = Markwon.builder(aViewHolder.mContext)
                    .usePlugin(StrikethroughPlugin.create())
                    .usePlugin(new AbstractMarkwonPlugin() {
                        @Override
                        public void configureParser(@NonNull Parser.Builder builder) {
                            builder.inlineParserFactory(inlineParserFactory);
                        }
                    })
                    .build();

final TextView lTextview = findViewById(R.id.textview);
markwon.setMarkdown(lTextview, aMessage);

final ConstraintLayout parent = findViewById(R.id.parent);
parent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(getApplicationContext(), "Clicked on TextView", Toast.LENGTH_SHORT).show();
            }
        });

Toast is not coming.
But when i set individual click listener on textview than it's working normal.

@noties
Copy link
Owner

noties commented Apr 15, 2020

Hello @gbhaumikkumar14 !

Markwon is not applying any touch/click listeners. How do you initialize click listener for the parent recyclerview item view?

@gbhaumikkumar14 gbhaumikkumar14 changed the title Parent view click blocking Parent view's click event getting blocked Apr 15, 2020
@gbhaumikkumar14
Copy link
Author

I have updated the comment you can check on any parent view if you set click listener and touch textview it's not working.

@gbhaumikkumar14
Copy link
Author

Hello @gbhaumikkumar14 !

Markwon is not applying any touch/click listeners. How do you initialize click listener for the parent recyclerview item view?

I have done like this.

lViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(getApplicationContext(), "Clicked on TextView", Toast.LENGTH_SHORT).show();
            }
        });

@noties
Copy link
Owner

noties commented Apr 15, 2020

Can you confirm that it is Markwon issue by not using it? Instead apply your raw text on the TextView and see if it is be clickable?

@gbhaumikkumar14
Copy link
Author

Can you confirm that it is Markwon issue by not using it? Instead apply your raw text on the TextView and see if it is be clickable?

Yes i confirmed, after applying markdown only that is happening. If i remove setMarkdown and simple use setText than it's working.

@noties
Copy link
Owner

noties commented Apr 15, 2020

Can you try calling:

textView.setMovementMethod(LinkMovementMethod.getInstance());

before applying markdown?

@gbhaumikkumar14
Copy link
Author

Can you try calling:

textView.setMovementMethod(LinkMovementMethod.getInstance());

before applying markdown?

No Change in behavior. Still blocking click event.

@noties
Copy link
Owner

noties commented Apr 15, 2020

There is some weirdness around it. There are similar reports (this for example). And for me it doesn't work even if raw text is set (not markdown). I suggest you set your click listener on the TextView directly, especially if you are planning to have parts of that TextView clickable (links)

@gbhaumikkumar14
Copy link
Author

Can you try without recyclerview ?
Just create one ConstraintLayout and put textview under ConstraintLayout.
Now set Click listener on ConstraintLayout and put Toast in it..
Run and check weather you are getting toast or not ?

@noties
Copy link
Owner

noties commented Apr 15, 2020

I'm really on a tight schedule right now 😅 . But if you wish to have click listener for both parent (it has some other views) and TextView - you can apply the same listener for both of them

@gbhaumikkumar14
Copy link
Author

I'm really on a tight schedule right now 😅 . But if you wish to have click listener for both parent (it has some other views) and TextView - you can apply the same listener for both of them

Yeah that's last option. I have put some workaround it.

@berendn
Copy link

berendn commented Apr 25, 2020

I'm experiencing the same issue.

@noties
Copy link
Owner

noties commented Apr 28, 2020

Unfortunately I do not know what can be done on our side, it seems to be a RecyclerView issue

@noties noties closed this as completed Apr 28, 2020
@gbhaumikkumar14
Copy link
Author

No, i have checked it's notrecyclerview problem. Because when i use normal setText that time everything seems normal. But when i put markwon.setMarkdown, problem is coming.

@noties
Copy link
Owner

noties commented May 2, 2020

I guess you would be surprised to know that internally Markwon is also just calling textView.setText ? 😉

@Kashish-Sharma
Copy link

Kashish-Sharma commented May 9, 2020

Same issue here also, without Markwon, it works perfectly but with it, clicks are getting blocked!
Setting the same clickListener on the view using Markwon works, but then again if we're having a ripple or other animations on the whole view, those wont show now.

@yeduRaghav
Copy link

I face the same issue

@abalta
Copy link

abalta commented May 27, 2020

I have same issue. See the following code.

` inner class ViewHolder(private val binding: ItemFastingBinding) :
RecyclerView.ViewHolder(binding.root) {

    private val markwon = Markwon.builder(binding.root.context).usePlugin(SoftBreakAddsNewLinePlugin.create()).build()

    fun bindView(item: Protocol) {
        binding.apply {
            markwon.setMarkdown(titleFasting, item.explanation?.en?.title?.breakLine().orEmpty())
            descFasting.text = item.explanation?.en?.desc?.breakLine().orEmpty()
            setDifficulty(item.difficulty)
            itemView.click {
                fastingItemClick(item, binding)
            }
        }
    }`

When I touch "titleFasting" view click method not trigger. But, I touch "descFasting" view click method is trigger normally.

And also, why this issue closed?

@berendn
Copy link

berendn commented May 28, 2020

Maybe Markwon creates a clickable span or link span that consumes the click on the textview?

@Kashish-Sharma
Copy link

In my case, click event does work but the ripple animations etc, don't.

@noties
Copy link
Owner

noties commented May 28, 2020

@berendn, Markwon won't add link spans if there are no links in markdown, but it will apply the LinkMovementMethod if it is missing. Which actually is stealing parent touch events. So, if we do not have links in our markdown (@abalta), we can safely remove the movement method and everything will be ok:

markwon.setMarkdown(titleFasting, item.explanation?.en?.title?.breakLine().orEmpty())
titleFasting.movementMethod = null

This might be not optimal solution as modifying movement method rebuilds TextView display cache. I find it an oversight from Markwon to always apply LinkMovementMethod, so starting with the next version this can be controlled by using:

  • configure CorePlugin#hasExplicitMovementMethodPlugin method (set true to disable implicit movement method)
  • use plugin MovementMethodPlugin#none() factory method (which internally does the same as the first point)

This is all if your markdown doesn't have links. If you have - it seems that you will need to additionally apply click listener on the TextView itself (the same listener can be used for both itemView and textView). @Kashish-Sharma I believe this is what you are doing. But there is an issue with a touch feedback (ripple animation, etc). This also could be addressed by manually triggering parents background update. I've added TriggerParentHotspot in the sample application (develop branch) you can take a look.

Using this approach would allow both widgets to be clickable (TextView can also have links) and visual feedback will still be present and consistent. It can be used like this:

final View.OnClickListener listener = new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        // clicked! 
    }
};

holder.itemView.setOnClickListener(listener);
holder.textView.setOnClickListener(listener);

// this would require for parent to have background
TriggerParentHotspot.init(holder.itemView, holder.textView);

@noties noties changed the title Parent view's click event getting blocked RecyclerView click event getting blocked Jun 2, 2020
@noties noties pinned this issue Jun 2, 2020
@premacck
Copy link

I was also facing the same issue, but I wasn't using any clickables in the text, just other forms of formatting, so I just passed the touch events from the textView to the parent like this:

text_view.setOnTouchListener { _, event -> parent_view.onTouchEvent(event) }

This way it is also giving the ripple effect from the parent click

@Shunaylov
Copy link

Shunaylov commented Nov 4, 2020

@noties I can't find TriggerParentHotspot anymore, the url is not available now

@noties
Copy link
Owner

noties commented Nov 5, 2020

Hello @Shunaylov ,

it was lost during sample migration, but you still can find it in history

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants