Thread
#compose
    Prashant Priyadarshi

    Prashant Priyadarshi

    1 year ago
    Hello, I am trying to align a card to center horizontal. But the new align is new working. Can somebody please help me figure out what am I missing/doing wrong.
    @Composable
    fun getSampleDataUI(list : List<SampleData>){
    MaterialTheme {
    LazyColumnFor(modifier = Modifier.fillMaxWidth(),
    items = list) {item ->
    ColumnScope.getSampleDataRow(data = item)
    }
    }
    }
    @Composable
    fun ColumnScope.getSampleDataRow(data: SampleData){
    return Card(modifier = Modifier.padding(15.dp).zIndex(5.0f)
    .align(Alignment.CenterHorizontally)) {
    Column(modifier = Modifier.padding(10.dp))
    {
    CoilImage(data.url, modifier = Modifier.size(50.dp).clip(CircleShape))
    Text(text = data.value)
    Text(text = data.value)
    }
    }
    }
    a

    allan.conda

    1 year ago
    LazyColumnFor does not have ColumnScope
    wrap the item in a Box
    Prashant Priyadarshi

    Prashant Priyadarshi

    1 year ago
    hi @allan.conda , below code also doesn't work.. any other ideas
    LazyColumnFor(modifier = Modifier.fillMaxWidth(),
    items = list) {item ->
    Box() {
    ColumnScope.getSampleDataRow(data = item)
    }
    }
    a

    allan.conda

    1 year ago
    Change ColumnSCope to BoxScope
    and make Box fillMaxSize
    Prashant Priyadarshi

    Prashant Priyadarshi

    1 year ago
    @allan.conda , it worked man.. thanks a lot
    just for reference, final code which worked, is below
    @Composable
    fun getSampleDataUI(list : List<SampleData>){
    MaterialTheme {
    // this is a recycler view , and it already has a scroll
    LazyColumnFor(modifier = Modifier.fillMaxWidth(),
    items = list) {item ->
    Box(modifier = Modifier.fillMaxWidth()) {
    BoxScope.getSampleDataRow(data = item)
    }
    }
    }
    }
    @Composable
    fun BoxScope.getSampleDataRow(data: SampleData){
    return Card(modifier = Modifier.padding(15.dp).zIndex(5.0f)
    .align(Alignment.Center)
    ) {
    Column(modifier = Modifier.padding(10.dp))
    // .apply { with(ColumnScope) {align(Alignment.CenterHorizontally)} })
    {
    //     LogManager.debug(tag = TAG, text = "recomposing ${data.value}")
    CoilImage(data.url, modifier = Modifier.size(50.dp).clip(CircleShape))
    Text(text = data.value)
    Text(text = data.value)
    }
    }
    }
    a

    allan.conda

    1 year ago
    btw you can remove BoxScope from
    BoxScope.getSampleDataRow(data = item)
    Prashant Priyadarshi

    Prashant Priyadarshi

    1 year ago
    yes that works too..