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

122
Views
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 answers
Answer question

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 Report
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!