Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

123
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda