Skip to content

Commit

Permalink
#10 - Switches and checkboxes
Browse files Browse the repository at this point in the history
  • Loading branch information
jhg3410 committed Feb 26, 2023
1 parent 7e59070 commit d8b3ffb
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ package com.example.jetnews.ui.interests

import android.content.res.Configuration.UI_MODE_NIGHT_YES
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.selection.toggleable
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Checkbox
import androidx.compose.material.Divider
Expand All @@ -43,6 +45,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.tooling.preview.Devices
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -158,6 +161,11 @@ private fun TopicItem(itemTitle: String, selected: Boolean, onToggle: () -> Unit
val image = painterResource(R.drawable.placeholder_1_1)
Row(
modifier = Modifier
.toggleable(
value = selected,
onValueChange = { _ -> onToggle() },
role = Role.Checkbox
)
.padding(horizontal = 16.dp, vertical = 8.dp)
) {
Image(
Expand All @@ -178,7 +186,7 @@ private fun TopicItem(itemTitle: String, selected: Boolean, onToggle: () -> Unit
Spacer(Modifier.weight(1f))
Checkbox(
checked = selected,
onCheckedChange = { onToggle() },
onCheckedChange = null,
modifier = Modifier.align(Alignment.CenterVertically)
)
}
Expand Down

0 comments on commit d8b3ffb

Please sign in to comment.