Hi, I have a problem in scrolling when using the f...
# compose
b
Hi, I have a problem in scrolling when using the following =
Bottom Sheet ( Android View ( Column/ Lazy Column ) ) )
The Lazy column is not scrollable at all... is this a known issue? Code sample:
Copy code
@OptIn(ExperimentalMaterial3Api::class)
@Preview
@Composable
fun TestScrollable() {

    var isVisible by remember {
        mutableStateOf(false)
    }
    val context = LocalContext.current

    val bottomSheetState = rememberModalBottomSheetState()

    Button(onClick = { isVisible = !isVisible }) {
        Text("Click")
    }

    if (isVisible) {
        ModalBottomSheet(
            onDismissRequest = {
                isVisible = false
            },
            sheetState = bottomSheetState,
            dragHandle = { BottomSheetDefaults.DragHandle() }
        ) {
            AndroidView(
                modifier = Modifier
                    .fillMaxWidth()
                    .fillMaxSize(),
                factory = {
                    val binding = MyBinding.inflate(
                        LayoutInflater.from(context),
                        null,
                        false
                    )

                    binding.composeView.setContent {
                        Column(
                            modifier = Modifier
                                .verticalScroll(rememberScrollState())
                                .padding(16.dp)
                        ) {
                            repeat(400) { index ->
                                Text(
                                    text = "$index"
                                )
                            }
                        }
                    }
                    binding.root
                }
            )
        }
    }
}
XML:
Copy code
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="<http://schemas.android.com/apk/res/android>"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <androidx.compose.ui.platform.ComposeView
        android:id="@+id/composeView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</FrameLayout>
l
That's not a lazy column (it's just a column). Do you have any pictures of how that looks?
b
@Lisandro Di Meo True, I tried both Lazy Column and Normal Column with verticalScroll Both doesn't work
l
I think the issue is that the compose view shouldn't have the
wrap_content
b
Copy code
<?xml version="1.0" encoding="utf-8"?>
<com.android.car.ui.FocusArea xmlns:android="<http://schemas.android.com/apk/res/android>"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <androidx.compose.ui.platform.ComposeView
        android:id="@+id/composeView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</com.android.car.ui.FocusArea>
This doesn't work either
image.png
l
sorry, I think it has to be for the container too
Copy code
<com.android.car.ui.FocusArea xmlns:android="<http://schemas.android.com/apk/res/android>"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.compose.ui.platform.ComposeView
        android:id="@+id/composeView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</com.android.car.ui.FocusArea>
b
also doesn't work when both are set to be match_parent
l
Hmm, weird. Probably it has to be with using composables inside an
AndroidView
. I would avoid that, and use AndroidView only when you need to re-use XML's
probably nesting a ComposeView inside an AndroidView conflicts with the scroll events. If you use the Column that's inside the AndroidView, it works well
b
We needed that pattern for a very specific case 😄 but thx a lot!
l
Sorry 😕 hope you find an answer! I'd try to log the scrollableState (why is not being changed inside the composeview)