Skip to content

Commit 372d677

Browse files
ashnohealexvanyo
andauthored
Update SystemBarProtectionSnippets.kt
Retrieve WindowInsets and Density in Composition. Calculate status bar height within lambda. Allows for height to be calculated when lambda is called. As a result, reduces number of recompositions. Co-authored-by: Alex Vanyo <[email protected]>
1 parent 20a05c9 commit 372d677

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

compose/snippets/src/main/java/com/example/compose/snippets/layouts/SystemBarProtectionSnippets.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@ private fun StatusBarProtection(
101101

102102
@Composable
103103
fun calculateGradientHeight(): () -> Float {
104-
val topInsets = WindowInsets.statusBars.getTop(LocalDensity.current).times(1.2F)
105-
return { topInsets }
104+
val statusBars = WindowInsets.statusBars
105+
val density = LocalDensity.current
106+
return { statusBars.getTop(density).times(1.2f) }
106107
}
107108
// [END android_compose_system_bar_protection]
108109

0 commit comments

Comments
 (0)