I have two AndroidView. And I need change place and state in one AndroidView but not recompose another. Then state change ChangableAndroidView NotChangableAndroidView recompose too.
How to prevent recompose NotChangableAndroidView then ChangableAndroidView change her state?
@Composable
fun TwoAndroidView(){
Column{
if(isFirst){
NotChangableAndroidView()
ChangableAndroidView()
}else{
ChangableAndroidView
NotChangableAndroidView
}
}
}
There is a function called
keyand it could be used for your case:This approach uses the
keycomposable function to help Compose track and optimize the recompositions ofNotChangableAndroidViewandChangableAndroidViewbased on their keys. If the composables are identical in structure and only their data or state changes, Compose can optimize the recomposition process more effectively. However, changing the order of composables still involves recomposition to reflect the updated UI accurately.