Ngenge Senior

    Ngenge Senior

    1 year ago
    Hello all. I have two fragments and each fragment hosts a composable. I have a Composable defined as seen below
    Colton Idle

    Colton Idle

    1 year ago
    @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. 😄
    Ngenge Senior

    Ngenge Senior

    1 year ago
    @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
    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?
    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
    steelahhh

    steelahhh

    1 year ago
    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
    Ngenge Senior

    Ngenge Senior

    1 year ago
    I did that an it works. Thanks