Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

293
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda