Skip to content

Commit

Permalink
fix: automatic backup options overflow (closes #377)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bnyro committed Apr 15, 2024
1 parent f5ebcb5 commit a39ca3a
Showing 1 changed file with 44 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.bnyro.contacts.ui.components.prefs

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.MaterialTheme
Expand All @@ -25,58 +26,57 @@ fun BlockPreference(
entries: List<String>,
onSelectionChange: (Int) -> Unit = {}
) {
Column(
val state = rememberScrollState()

Row(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 8.dp)
.horizontalScroll(state)
) {
Row(
modifier = Modifier
.fillMaxWidth()
) {
val cornerRadius = 20.dp
val cornerRadius = 20.dp

var selectedItem by rememberPreference(key = preferenceKey, defaultValue = 0)
var selectedItem by rememberPreference(key = preferenceKey, defaultValue = 0)

entries.forEachIndexed { index, entry ->
val startRadius = if (index != 0) 0.dp else cornerRadius
val endRadius = if (index == entries.size - 1) cornerRadius else 0.dp
entries.forEachIndexed { index, entry ->
val startRadius = if (index != 0) 0.dp else cornerRadius
val endRadius = if (index == entries.size - 1) cornerRadius else 0.dp

OutlinedButton(
onClick = {
selectedItem = index
onSelectionChange.invoke(index)
},
modifier = Modifier
.offset(if (index == 0) 0.dp else (-1 * index).dp, 0.dp)
.zIndex(if (selectedItem == index) 1f else 0f),
shape = RoundedCornerShape(
topStart = startRadius,
topEnd = endRadius,
bottomStart = startRadius,
bottomEnd = endRadius
),
border = BorderStroke(
1.dp,
if (selectedItem == index) {
MaterialTheme.colorScheme.primary
} else {
MaterialTheme.colorScheme.primary.copy(alpha = 0.75f)
}
),
colors = if (selectedItem == index) {
ButtonDefaults.outlinedButtonColors(
containerColor = MaterialTheme.colorScheme.primary.copy(alpha = 0.2f),
contentColor = MaterialTheme.colorScheme.primary
)
OutlinedButton(
onClick = {
selectedItem = index
onSelectionChange.invoke(index)
},
modifier = Modifier
.offset(if (index == 0) 0.dp else (-1 * index).dp, 0.dp)
.zIndex(if (selectedItem == index) 1f else 0f),
shape = RoundedCornerShape(
topStart = startRadius,
topEnd = endRadius,
bottomStart = startRadius,
bottomEnd = endRadius
),
border = BorderStroke(
1.dp,
if (selectedItem == index) {
MaterialTheme.colorScheme.primary
} else {
ButtonDefaults.outlinedButtonColors(
containerColor = MaterialTheme.colorScheme.surface,
contentColor = MaterialTheme.colorScheme.onSurface
)
MaterialTheme.colorScheme.primary.copy(alpha = 0.75f)
}
) {
Text(entry)
),
colors = if (selectedItem == index) {
ButtonDefaults.outlinedButtonColors(
containerColor = MaterialTheme.colorScheme.primary.copy(alpha = 0.2f),
contentColor = MaterialTheme.colorScheme.primary
)
} else {
ButtonDefaults.outlinedButtonColors(
containerColor = MaterialTheme.colorScheme.surface,
contentColor = MaterialTheme.colorScheme.onSurface
)
}
) {
Text(entry)
}
}
}
Expand Down

0 comments on commit a39ca3a

Please sign in to comment.