-
Notifications
You must be signed in to change notification settings - Fork 1
/
ContentVisibility.kt
34 lines (31 loc) · 1.1 KB
/
ContentVisibility.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2024 Soil Contributors
// SPDX-License-Identifier: Apache-2.0
package soil.query.compose.runtime
import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.semantics.clearAndSetSemantics
import androidx.compose.ui.semantics.invisibleToUser
// NOTE: Visibility must be treated similarly to Android View's invisible because it needs to receive the loading state from Await placed as a child.
// (If AnimatedVisibility's visible=false, the content isn't called while it's hidden, so Await won't function)
@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun ContentVisibility(
hidden: Boolean,
modifier: Modifier = Modifier,
content: @Composable () -> Unit
) {
Box(
modifier = modifier
.alpha(if (hidden) 0f else 1f)
.clearAndSetSemantics {
if (hidden) {
invisibleToUser()
}
}
) {
content()
}
}