My issue is the following : I have a NestedScrollView with Bottomsheetbehavior, inside it, there is a viewpager. The viewpager shows a fragment that contains clickable and non clickable elements. Non clickable elements work perfectly fine. But clickable elements break the nested scroll.
On my project, clickable elements don't push the bottomsheet to the top of the screen. The bottomsheet stays down and the viewpager scrolls into the void
Thank you in advance for your help
Here is my lowest code reproduction :
class NSCClickActivity : AppCompatActivity() {
private var _fragmentAdapter: TestFragmentAdapter? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.nscclick_layout)
_fragmentAdapter = TestFragmentAdapter(this)
findViewById<ViewPager2>(R.id.challenge_list_VP).adapter = _fragmentAdapter
TabLayoutMediator(findViewById(R.id.challenge_action_tabLayout), findViewById(R.id.challenge_list_VP)) { tab, position ->
val tabNames =
listOf(
"ONE",
"TWO"
)
tab.text = tabNames[position]
}.attach()
}
}
class TestFragmentAdapter(fragment: FragmentActivity) : FragmentStateAdapter(fragment) {
override fun getItemCount(): Int = 2
override fun createFragment(position: Int): Fragment = VPFragment()
}
class VPFragment : Fragment(R.layout.vpfragment_layout) {
}
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/challenge_main_fragment_layout"
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">
<ImageView android:id="@+id/title_background"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="?attr/colorPrimary"
app:layout_constraintStart_toStartOf="parent"
android:contentDescription="@null"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<androidx.coordinatorlayout.widget.CoordinatorLayout android:id="@+id/challenge_main_CL"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.core.widget.NestedScrollView android:id="@+id/scroll_SV"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:fillViewport="true"
android:orientation="vertical"
android:overScrollMode="never"
android:scrollbars="none"
app:behavior_hideable="false"
app:layout_behavior="@string/bottom_sheet_behavior">
<androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical">
<TextView android:id="@+id/title_TV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="10.dp"
android:layout_marginStart="10.dp"
android:layout_marginTop="24.dp"
android:text="TITRE"
android:textAppearance="?attr/textAppearanceHeadline1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.viewpager2.widget.ViewPager2 android:id="@+id/challenge_list_VP"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:descendantFocusability="blocksDescendants"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/challenge_action_tabLayout"
android:nestedScrollingEnabled="true"/>
<com.google.android.material.tabs.TabLayout android:id="@+id/challenge_action_tabLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24.dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/title_TV"
app:tabGravity="start"
app:tabIndicatorColor="?attr/colorPrimary"
app:tabMode="fixed"
app:tabSelectedTextColor="?attr/colorPrimary"
app:tabTextAppearance="?attr/textAppearanceHeadline4"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView 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"
android:clipToPadding="false"
android:fillViewport="true"
android:orientation="vertical"
android:overScrollMode="never"
android:scrollbars="none"
app:behavior_hideable="false"
app:layout_behavior="@string/bottom_sheet_behavior">
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="1500dp"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:nestedScrollingEnabled="true"
android:weightSum="2" >
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
android:text="a\n\n\n\n\n\na"
android:id="@+id/text"/>
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/text"
android:text="b\n\n\n\n\n\nb"
android:id="@+id/text2"
android:clickable="true"/>
<SurfaceView android:layout_width="match_parent"
android:layout_height="15000dp"
app:layout_constraintTop_toBottomOf="@id/text2"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>