/
BoxWithConstraintsExample.kt
41 lines (36 loc) · 1.37 KB
/
BoxWithConstraintsExample.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
35
36
37
38
39
40
41
package de.jensklingenberg.jetpackcomposeplayground.mysamples.github.foundation.layout
import androidx.compose.foundation.layout.*
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
@Composable
fun BoxWithConstraintsDemo() {
Column {
Column {
MyBoxWithConstraintsDemo()
}
Text("Here we set the size to 150.dp", modifier = Modifier.padding(top = 20.dp))
Column(modifier = Modifier.size(150.dp)) {
MyBoxWithConstraintsDemo()
}
}
}
@Composable
private fun MyBoxWithConstraintsDemo() {
BoxWithConstraints {
val boxWithConstraintsScope = this
//You can use this scope to get the minWidth, maxWidth, minHeight, maxHeight in dp and constraints
Column {
if (boxWithConstraintsScope.maxHeight >= 200.dp) {
Text(
"This is only visible when the maxHeight is >= 200.dp",
style = TextStyle(fontSize = 20.sp)
)
}
Text("minHeight: ${boxWithConstraintsScope.minHeight}, maxHeight: ${boxWithConstraintsScope.maxHeight}, minWidth: ${boxWithConstraintsScope.minWidth} maxWidth: ${boxWithConstraintsScope.maxWidth}")
}
}
}