Hello all. I have two fragments and each fragment ...
# compose
n
Hello all. I have two fragments and each fragment hosts a composable. I have a Composable defined as seen below
c
@Ngenge Senior can you put your code in this thread please?
@Ngenge Senior put your code in the thread and remove it from the main message. 😄
n
Copy code
@Composable
fun JobItemView(modifier: Modifier = Modifier,job: Job ){
Card(modifier = Modifier
    .height(100.dp)
    ,elevation = 4.dp) {
    Row(modifier = Modifier.padding(horizontal = 8.dp),verticalAlignment = Alignment.CenterVertically) {

        when(job.company_logo){
            is String -> {
                CoilImage(modifier = Modifier
                    .size(60.dp)
                    .padding(2.dp) ,
                    data = job.company_logo as String,
                    contentDescription = "An image",
                    loading = {
                        Box(Modifier.matchParentSize()){
                            CircularProgressIndicator(Modifier.align(
                                Alignment.Center))
                        }
                    },error = {

                    })
            } else -> {
                Image(modifier = Modifier.size(60.dp).padding(2.dp) ,
                    painter = painterResource(id = R.drawable.ic_launcher_background), contentDescription = "Content" )
            }

        }


        Column(verticalArrangement = Arrangement.Center) {
            Text(text = job.title,fontWeight = FontWeight.Bold)
            Text(text = job.company)

        }
        
        Spacer(modifier = Modifier.weight(1f))
        Text(text = job.type)

    }

}

}
for the list item and
Copy code
setContent {
                val jobs:List<Job> by viewModel.jobs.observeAsState(listOf())

                LazyColumn{
                    items(jobs,key ={ it.id} ){ job ->
                        JobItemView(job = job,modifier = Modifier.clickable(onClick = {
                            Log.d(TAG, "onCreateView: $job")
                            findNavController().navigate(HomeFragmentDirections.actionHomeFragmentToDetailsFragment(job))
                        }))


                    }
                }
            }
@Colton Idle have I done it correctly now?
💯 1
The clickable does not work and I can’t explain why that is the case. It is better annotated as seen below and the navigation does not work
s
Looks like you’re passing modifier into JobItemView without actually using it anywhere. The code is correct, you just have to apply the passed in modifier to a Composable inside your JobItemView
👍 2
n
I did that an it works. Thanks
👍 1