Hello all, I've question regarding AndroidView upd...
# compose
c
Hello all, I've question regarding AndroidView update field. Assuming I put a mutableState.value lambda inside update field, and assuming I set a textListener ( say EditText) inside update, does the text listener stay intact when mutableState lamdba changes? I assume it does but not sure.
j
question is bit hard to understand
c
I'm asking whether the update with searchboxLambda needs to stay for the entirity of views lifetime or does it stay permanent when once called, just like setting it in the init layout of the fragment. If it resets to factory or default when lambda changes to empty lambda {}, I should compose lambda with multiple lambdas.
Copy code
searchBoxSubLambda1 = remember { mutableStateOf<(SearchBoxView)->Unit>({})
    searchBoxSubLambda2= remember { mutableStateOf<(SearchBoxView)->Unit>({})

    val searchBoxLambda = remember { mutableStateOf<(SearchBoxView)->Unit>({
        searchBoxSubLambda1()
        searchBoxSubLambda2()
    }) }

AndroidView(
    modifier = Modifier ...
    factory = { it ->
        SearchBoxView(it).apply {
            onTextChange { searchBoxText.value = it }... // text listener
        }
    } ,
    update = { searchBox ->
        searchBoxText.value?.let { searchBox.setSearch(it) }
        searchBoxLambda.value(searchBox)
    }
)
z
I’m not sure if this is what you're asking, but the
update
parameter to
AndroidView
is not memoized - if you pass a different
update
function on a subsequent recomposition, the new function will be used to perform updates.