-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebugModule.kt
More file actions
65 lines (60 loc) · 1.99 KB
/
Copy pathDebugModule.kt
File metadata and controls
65 lines (60 loc) · 1.99 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package band.effective.drawer_base
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTag
import androidx.compose.ui.unit.dp
@Composable
fun DebugDrawerModule(
modifier: Modifier = Modifier,
expanded: Boolean = false,
icon: @Composable (() -> Unit)? = null,
title: String,
contentModifier: Modifier = Modifier,
showBadge: Boolean = false,
content: @Composable ColumnScope.() -> Unit,
) {
var expandedState by rememberSaveable { mutableStateOf(expanded) }
val semanticsModifier = Modifier.semantics {
testTag = "Module $title"
}
Column(
modifier = Modifier
.fillMaxWidth()
.then(if (expandedState) modifier else Modifier)
.then(semanticsModifier),
) {
DrawerModuleHeader(
icon = icon,
title = title,
showBadge = showBadge,
expandedState = expandedState,
onClick = {
expandedState = !expandedState
},
)
val contentSemanticsModifier = Modifier.semantics {
testTag = "Module content $title"
}
AnimatedVisibility(visible = expandedState) {
Column(
modifier = Modifier
.fillMaxWidth()
.padding(8.dp)
.then(contentModifier)
.then(contentSemanticsModifier),
) {
content()
}
}
}
}