Skip to content

Commit

Permalink
#3 - Remember in Composition (exist explanation code)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhg3410 committed Jan 30, 2023
1 parent a591afe commit 346fb61
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package jik.compose.basicstatecodelab

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Button
import androidx.compose.material.Text
Expand All @@ -14,10 +15,30 @@ fun WaterCounter(modifier: Modifier = Modifier) {
var count by remember { mutableStateOf(0) }

if (count > 0) {
var showTask by remember { mutableStateOf(true) }
if (showTask) {
WellnessTaskItem(
taskName = "Have you taken your 15 minute walk today?",
onClose = { showTask = false }
)
}
Text(text = "You've had $count glasses")
}
Button(onClick = { count++ }, modifier = Modifier.padding(top = 8.dp), enabled = count < 10) {
Text(text = "Add one")

Row(modifier = Modifier.padding(top = 8.dp)) {
Button(
onClick = { count++ },
enabled = count < 10
) {
Text(text = "Add one")
}

Button(
onClick = { count = 0 },
modifier = Modifier.padding(start = 8.dp)
) {
Text(text = "Clear water count")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package jik.compose.basicstatecodelab

import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

@Composable
fun WellnessTaskItem(
taskName: String,
onClose: () -> Unit,
modifier: Modifier = Modifier
) {
Row(
modifier = modifier,
verticalAlignment = Alignment.CenterVertically
) {
Text(
modifier = Modifier
.weight(1f)
.padding(start = 16.dp),
text = taskName
)
IconButton(onClick = onClose) {
Icon(
imageVector = Icons.Filled.Close,
contentDescription = null
)
}
}
}

0 comments on commit 346fb61

Please sign in to comment.