noties / Markwon

Android markdown library (no WebView)
https://noties.io/Markwon/
Apache License 2.0
2.68k stars 298 forks source link

Link focus issue when navigating using D-Pad on AndroidTV #397

Closed shao-tap closed 2 years ago

shao-tap commented 2 years ago
  1. When navigating through a markdown that has a link (using Android TV D-Pad), the link should be focused.
  2. Please specify conditions/steps to reproduce (layout, code, markdown used, etc):

Markdown string to reproduce the bug

## Try the library

Test this [link](https://example.com). Try to focus the link to reproduce the bug.

![test](https://images.pexels.com/photos/41171/brussels-sprouts-sprouts-cabbage-grocery-41171.jpeg)

Code

val markwon = Markwon.builder(this)
            .usePlugin(PicassoImagesPlugin.create(Picasso.get()))
            .usePlugin(object : AbstractMarkwonPlugin() {
                override fun configureConfiguration(builder: MarkwonConfiguration.Builder) {
                    builder.linkResolver { view, link ->
                        Log.i("TEST", "$link intercepted!")
                    }
                }
            })
            .build()

val adapter = MarkwonAdapter.createTextViewIsRoot(R.layout.adapter_default_entry)
        findViewById<RecyclerView>(R.id.recyclerView_main_markwon).apply {
            layoutManager = LinearLayoutManager(this@MainActivity)
            this.adapter = adapter
        }

adapter.setMarkdown(markwon, string)

XML layouts

adapter_default_entry.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/textView_adapter_default_entry"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerView_main_markwon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Additional info

Thanks for your time and for this powerful library!

shao-tap commented 2 years ago

After investigations, we noticed this behavior is already reproducible with a simple RecyclerView with items containing links and without using the Markwon library. To fix it, we used Leanback's VerticalGridView instead of a RecyclerView. Using this approach, there's no need to specify a layoutManager, only the adapter.

As this issue is not related to the library itself, I am now closing it.