I have a parent composable that is scrollable and contains a child AndroidView. Inside the AndroidView, there is a NestedScrollView. I expected the child NestedScrollView to be able to scroll before the parent composable, but in reality, it is not able to scroll. Here is my code:
@Composable
fun TestScreen() {
Column(
modifier = Modifier
.fillMaxSize()
.verticalScroll(rememberScrollState())
) {
AndroidView(
factory = {
NestedScrollView(it).apply {
ViewCompat.setNestedScrollingEnabled(this, true)
layoutParams = FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT
)
addView(TextView(it).also { tv ->
tv.layoutParams = ViewGroup.MarginLayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT
)
tv.text = "Inner scrollable"
tv.textSize = 100f
tv.setBackgroundColor(Color.Blue.toArgb())
})
}
}, modifier = Modifier
.fillMaxWidth()
.height(200.dp)
.clipToBounds()
)
Divider(color = Color.Red)
Text(
text = "Outer scrollable", fontSize = 50.sp, modifier = Modifier
.fillMaxWidth()
.height(800.dp)
)
Divider(color = Color.Red)
}
}
I understand that I can add verticalScroll to the AndroidView, but that doesn't meet my expectations because it will make the NestedScrollView larger than the AndroidView. Currently, it's not an issue, but if I were to use a RecyclerView instead of a NestedScrollView, the items within the NestedScrollView wouldn't be recyclable, which would be a significant problem.