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

117
Vistas
Why state update not reflected on AndroidView

In Jetpack Compose, I have an AndroidView with a listener that reads the state passed like this:

@Composable
fun Scanner(
    state: ScannerState,
    modifier: Modifier = Modifier,
) {
    AndroidView(
        modifier = modifier,
        factory = { context ->
            ScannerView(context).apply {
                onButtonClicked = {
                    if (state.isLoading) <-- HERE I READ THE STATE   
                        ...
                    }
                }
            }
        },

The problem comes when the state is updated and the view recomposed. If the onButtonClicked callback is invoked again after that, it holds the initial state, and it's not reading the last updated state that this function received.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

factory is getting called only once, when the view is created. That's why the lambda captures only the initial state.

To pass an updated state, you need to use update argument, like this:

AndroidView(
    modifier = modifier,
    factory = { context ->
        ScannerView(context)
    },
    update = { view 
        view.onButtonClicked = {
            if (state.isLoading) {
                ...
            }
        }
    },
)
over 4 years ago · Santiago Trujillo Denunciar
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