Hi folks, are 2 instances of function references n...
# compose
a
Hi folks, are 2 instances of function references not same ? I am calling below Composable
Copy code
PermissionsScreen(
    Modifier.padding(innerPadding),
    uiState,
    viewModel::onAction,
)
I see that whenever recomposition happens because of changing uiState, the function reference is also a different instance from previous one which causes more recomposition for Composable which should not be recomposed.
z
Afaik, this happens because your function references the viewmodel, which is considered unstable. You could test adding @Stable to your viewmodel to verify what Im saying, Im pretty sure it wouldnt result in new functions everytime that way.
👍 1
a
@Zoltan Demant I marked viewModel as stable but the issue persists, the only way seems to be to wrap the fun ref in a remember 😕 .
sad panda 1
o
I used to store the function references before entering the Compose world (before
setContent
) and then pass these variables down to my screens to solve this.
Copy code
class Activity... {
  private val viewModel by viewModels()
  fun onCreate(...) {
    val foo = viewModel::foo
    setContent {
      MyTheme {
        Surface {
          MyScreen(viewModel, foo)
        }
      }
    }
  }
}
👀 1