You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Looks like AmbientAware composable unnecessarily recreates the whole block that is passed when the isAlwaysScreenOn parameter changes. Instead, it should just do recomposition on this block.
Here's how it looks now:
@Composable
funAmbientAware(
isAlwaysOnScreen:Boolean = true,
block: @Composable (AmbientStateUpdate) ->Unit,
) {
val activity =LocalContext.current.findActivityOrNull()
// Using AmbientAware correctly relies on there being an Activity context. If there isn't, then// gracefully allow the composition of [block], but no ambient-mode functionality is enabled.if (activity !=null&& isAlwaysOnScreen) {
AmbientAwareEnabled(activity, block)
} else {
AmbientAwareDisabled(block)
}
}
Looks like AmbientAware composable unnecessarily recreates the whole block that is passed when the
isAlwaysScreenOn
parameter changes. Instead, it should just do recomposition on this block.Here's how it looks now:
When
isAlwaysOnScreen
changes theblock
Composable is recreated. It's especially not nice when the navigation component is wrapped with AmbientAware.This seems to be against the guidelines here -> https://github.com/androidx/androidx/blob/androidx-main/compose%2Fdocs%2Fcompose-component-api-guidelines.md#lifecycle-expectations-for-slot-parameters
Seems like the if else is not necessary. Here's an alternative solution
With this approach the if is only on adding the observer and not on showing the content. When ambientUpdate changes the block just recomposes.
version 0.5.21
The text was updated successfully, but these errors were encountered: