Skip to content

Commit

Permalink
Update Material 3 Library to RC01 and Improve UI components
Browse files Browse the repository at this point in the history
  • Loading branch information
jeluchu committed Jan 30, 2024
1 parent 8b29681 commit 0b055cc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ androidx-compose-foundation = { module = "androidx.compose.foundation:foundation
androidx-compose-foundation-foundation-layout = { module = "androidx.compose.foundation:foundation-layout", version.ref = "androidx-compose-foundation" }
androidx-compose-material = { module = "androidx.compose.material:material", version.ref = "androidx-compose-material" }
androidx-compose-material-material-icons-extended = { module = "androidx.compose.material:material-icons-extended", version.ref = "androidx-compose-material" }
androidx-compose-material3 = "androidx.compose.material3:material3:1.1.2"
androidx-compose-material3 = "androidx.compose.material3:material3:1.2.0-rc01"
androidx-compose-runtime = { module = "androidx.compose.runtime:runtime", version.ref = "androidx-compose-runtime" }
androidx-compose-ui = { module = "androidx.compose.ui:ui", version.ref = "androidx-compose-ui" }
androidx-compose-ui-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "androidx-compose-ui" }
Expand All @@ -36,7 +36,7 @@ androidx-lifecycle-lifecycle-livedata-core-ktx = { module = "androidx.lifecycle:
androidx-lifecycle-lifecycle-viewmodel-ktx = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "androidx-lifecycle" }
androidx-navigation-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "androidx-navigation" }
androidx-preference = "androidx.preference:preference-ktx:1.2.1"
com-android-tools-build-gradle = "com.android.tools.build:gradle:8.2.1"
com-android-tools-build-gradle = "com.android.tools.build:gradle:8.2.2"
com-google-accompanist-accompanist-systemuicontroller = { module = "com.google.accompanist:accompanist-systemuicontroller", version.ref = "com-google-accompanist" }
com-google-android-gms-play-services-base = "com.google.android.gms:play-services-base:18.3.0"
com-google-code-gson = "com.google.code.gson:gson:2.10.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,37 @@ import androidx.compose.material3.RadioButtonDefaults
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.semantics.clearAndSetSemantics
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.jeluchu.jchucomponents.ui.themes.artichoke
import com.jeluchu.jchucomponents.ui.extensions.modifier.cornerRadius

@Composable
fun PreferenceSingleChoiceItem(
modifier: Modifier = Modifier,
text: String,
color: Color = MaterialTheme.colorScheme.onSurface,
style: TextStyle = MaterialTheme.typography.titleLarge,
selected: Boolean,
radioButtonColor: Color = artichoke,
shape: Shape = 15.cornerRadius(),
style: TextStyle = MaterialTheme.typography.titleLarge,
colors: PreferenceChoiceColors = PreferenceChoiceColors(),
contentPadding: PaddingValues = PaddingValues(horizontal = 8.dp, vertical = 18.dp),
onClick: () -> Unit
) = Surface(
modifier = Modifier.selectable(
selected = selected,
onClick = onClick
)
),
shape = shape,
contentColor = colors.contentColor,
color = colors.containerColor
) {
Row(
modifier = modifier
Expand All @@ -54,16 +59,15 @@ fun PreferenceSingleChoiceItem(
text = text,
maxLines = 1,
style = style.copy(fontSize = 16.sp),
color = color,
overflow = TextOverflow.Ellipsis
)
}
RadioButton(
selected = selected,
onClick = onClick,
colors = RadioButtonDefaults.colors(
selectedColor = radioButtonColor,
unselectedColor = radioButtonColor
selectedColor = colors.selectedRadioColor,
unselectedColor = colors.unselectedRadioColor
),
modifier = Modifier
.padding()
Expand All @@ -72,6 +76,15 @@ fun PreferenceSingleChoiceItem(
}
}

@Immutable
class PreferenceChoiceColors(
val selectedRadioColor: Color = Color.DarkGray,
val unselectedRadioColor: Color = Color.DarkGray,
val containerColor: Color = Color.White,
val contentColor: Color = Color.DarkGray
)


@Preview
@Composable
fun PreferenceSingleChoiceItemPreview() = PreferenceSingleChoiceItem(
Expand Down

0 comments on commit 0b055cc

Please sign in to comment.