1

I am trying to build the following component.

enter image description here

Following is my code,

    @Composable
    fun View(modifier: Modifier = Modifier){

        Row(modifier = Modifier
          .fillMaxWidth()
          .padding(16.dp),
        horizontalArrangement = Arrangement.spacedBy(10.dp),
        verticalAlignment = Alignment.CenterVertically) {

        IconButton(onClick = { /*TODO*/ },
            modifier = Modifier
                .background(shape = roundShape, color = Color.Blue)
                .size(40.dp)) {
            Icon(
                painter = painterResource(id = R.drawable.ic_microphone_2),
                contentDescription = null,
                tint = Color.White
            )
        }

        BasicTextField(
            value = "",
            onValueChange = {  },
            modifier=Modifier
                .height(40.dp)
                .fillMaxWidth()
                .border(1.dp,Color.Gray,roundShape)
        )
    }

The content of the IconButton is no longer centered after switching the LayoutDirection to Rtl.

CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Rtl) {
            View()
} 

this is the result of my code.

enter image description here

1 Answers1

0
@Composable
fun IconView(modifier: Modifier = Modifier) {

Row(
    modifier = Modifier
        .fillMaxWidth()
        .padding(16.dp),
    horizontalArrangement = Arrangement.spacedBy(10.dp),
    verticalAlignment = Alignment.CenterVertically
) {

    Box(modifier =  Modifier
        .background(shape = RoundedCornerShape(20.dp), color = Color.Blue)
        .size(50.dp).clickable {


        }
    ){
        Icon(
            modifier = Modifier.align(alignment = Center),
            painter = painterResource(id = android.R.drawable.ic_menu_call),
            contentDescription = null,
            tint = Color.White
        )
    }


    BasicTextField(
        value = "",
        onValueChange = { },
        modifier = Modifier
            .height(40.dp)
            .fillMaxWidth()
            .border(1.dp, Color.Gray, RoundedCornerShape(20.dp))
    )
  }

}

Don't use iconButton as parent use Box and align child Icon to center. I Hope it will help you. Cheers

Syed Ibrahim
  • 356
  • 2
  • 6