-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.kt
57 lines (54 loc) · 2 KB
/
App.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material.Button
import androidx.compose.material.Checkbox
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.material.TextField
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import dev.burnoo.compose.remembersetting.rememberBooleanSetting
import dev.burnoo.compose.remembersetting.rememberIntSetting
import dev.burnoo.compose.remembersetting.rememberStringSetting
import org.jetbrains.compose.ui.tooling.preview.Preview
@Composable
@Preview
fun App() {
MaterialTheme {
var text by rememberStringSetting("stringKey", "Hello world!")
val (checked, setChecked) = rememberBooleanSetting("booleanKey", false)
Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
Text("The below states will be saved persistently:")
TextField(text, onValueChange = { text = it })
Checkbox(checked, setChecked)
Counter()
}
}
}
@Composable
private fun Counter() {
var counter by rememberIntSetting("intKey", 0)
Row(verticalAlignment = Alignment.CenterVertically) {
Button(onClick = { counter-- }) { Text("-") }
Text(
counter.toString(),
style = MaterialTheme.typography.h3.copy(textAlign = TextAlign.Center),
modifier = Modifier.defaultMinSize(minWidth = 120.dp),
)
Button(onClick = { counter++ }) { Text("+") }
}
}
@Preview
@Composable
private fun PreviewCounter() {
ComposeRememberSettingPreview("intKey" to 21) {
Counter()
}
}