Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

300
Views
How to use findNavController() in Compose

I am currently doing code refactoring for a current Kotlin application. I would like to move to a different fragment by pressing a button from the Compose view. I know that Compose has own navigator, but can I somehow use findNavController() in Compose files? I tried sending a function to Compose files but I still get the error:

java.lang.UnsupportedOperationException: Cannot add views to ComposeView; only Compose content is supported

Current code:

Code in fragment:

binding.composeProgram.setContent {
        MdcTheme {
            ProgramContent(
                viewModel = viewModel,
                navigationController = {
                    findNavController().navigate(
                        R.id.exercise_details,
                        ExerciseDetailFragmentArgs(396).toBundle(),
                        null,
                        null
                    )
                }
            )
        }
    }

Compose file:

@Composable
fun ProgramContent(
    viewModel: ProgramFragmentViewModel,
    navigationController:  () -> (Unit)
) {
    Button(onClick = {
        navigationController()
    }){}
}

SOLVED: I had to add to xmlns file one line:

android:transitionGroup="true"

So in xmlns file it will looks like this:

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    style="@style/AppTheme.Fragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:transitionGroup="true"
    >

<androidx.compose.ui.platform.ComposeView
        android:id="@+id/compose_program"
        android:layout_width="match_parent"
        android:layout_height="0.dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        />
...
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!