Conversation
* Add `BasicComponents.kt` with `BaseButton`, `BaseText`, and `BaseCheckbox` examples using the `styleable` modifier. * Add `StylesBasics.kt` covering style merging, property overwriting, standalone style definitions, and parent-child styling inheritance. * Add `StyleDosDonts.kt` outlining best practices for exposing style parameters and replacing visual-based parameters in design systems. * Add `StylesExamples.kt` containing advanced UI patterns like hover effects, depth-pressed animations, and glowing gradients using `StyleScope`. * Add `StylesStates.kt` demonstrating interaction-driven styles (hovered, pressed, focused), property animations, and custom style state keys. * Add `StylesThemes.kt` showing integration of `Style` objects within a custom theme using `CompositionLocal`. * Update `androidx.compose.foundation` to `1.11.0-alpha06` and BOM to `2026.02.01`.
Summary of ChangesHello @riggaroo, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly expands the Compose snippets by introducing a comprehensive set of examples for the new Compose Foundation Style API. It covers everything from basic component styling and best practices to advanced UI effects, interactive states, and seamless integration with custom theming. The changes aim to provide developers with clear, practical demonstrations of how to leverage the new styling capabilities effectively. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a comprehensive set of snippets for the new Compose Foundation Style APIs. The examples cover basic usage, advanced patterns, state handling, and theming integration. The code is well-structured and provides a good overview of the new features. I've identified a few areas for improvement, mainly related to handling side-effects in composables and correcting some logic in the example snippets to make them clearer and more robust.
| url: String, | ||
| modifier: Modifier = Modifier, | ||
| style: Style = Style, | ||
| state: PlayerState = remember { PlayerState.Paused } |
There was a problem hiding this comment.
Using remember as a default parameter value is an anti-pattern. Default parameters are evaluated at the call site, and remember should only be used within a @Composable function's body. This can lead to unexpected behavior. The default value should be a constant, and the caller should be responsible for managing and remembering the state if necessary.
| state: PlayerState = remember { PlayerState.Paused } | |
| state: PlayerState = PlayerState.Paused |
| @Preview | ||
| @Composable | ||
| fun StyleStateKeySample() { | ||
| // Using the extension function to change the border color to green while playing | ||
| val style = Style { | ||
| borderColor(Color.Gray) | ||
| playerPlaying { | ||
| animate { | ||
| borderColor(Color.Green) | ||
| } | ||
| } | ||
| playerPaused { | ||
| animate { | ||
| borderColor(Color.Blue) | ||
| } | ||
| } | ||
| } | ||
| val styleState = remember { MutableStyleState(null) } | ||
| styleState[playerStateKey] = PlayerState.Playing | ||
|
|
||
| // Using the style in a composable that sets the state -> notice if you change the state parameter, the style changes. You can link this up to an ViewModel and change the state from there too. | ||
| MediaPlayer( | ||
| url = "https://example.com/media/video", | ||
| style = style, | ||
| state = PlayerState.Stopped | ||
| ) | ||
| } |
There was a problem hiding this comment.
The current implementation of StyleStateKeySample is confusing and contains incorrect logic. It performs a side-effect by mutating styleState directly in the composable body, and this styleState is never actually used. Furthermore, it calls MediaPlayer with a Stopped state, which doesn't demonstrate the playerPlaying style.
This revised version simplifies the example to correctly and clearly demonstrate how a custom style state is applied.
@Preview
@Composable
fun StyleStateKeySample() {
// Using the extension function to change the border color to green while playing
val style = Style {
borderColor(Color.Gray)
playerPlaying {
animate {
borderColor(Color.Green)
}
}
playerPaused {
animate {
borderColor(Color.Blue)
}
}
}
// Using the style in a composable that sets the state -> notice if you change the state parameter, the style changes. You can link this up to an ViewModel and change the state from there too.
MediaPlayer(
url = "https://example.com/media/video",
style = style,
state = PlayerState.Playing // Set to Playing to demonstrate the 'playerPlaying' style
)
}| val styleState = remember(interactionSource) { | ||
| MutableStyleState(interactionSource) | ||
| } | ||
| styleState.isEnabled = enabled |
There was a problem hiding this comment.
Mutating state like styleState.isEnabled directly within the body of a composable is a side-effect and can lead to unpredictable behavior. This mutation should be performed within a LaunchedEffect to ensure it happens in a controlled manner only when the enabled value changes.
LaunchedEffect(enabled) {
styleState.isEnabled = enabled
}| contentAlignment = Alignment.Center | ||
| ) { | ||
| BaseText( | ||
| "Button 19".toUpperCase(Locale.current), |
There was a problem hiding this comment.
| // Set equal to incoming state to link the two together | ||
| styleState.playerState = state |
There was a problem hiding this comment.
Mutating state like styleState.playerState directly within the body of a composable is a side-effect. This should be wrapped in a LaunchedEffect(state) to ensure it's executed only when the state value changes.
// Set equal to incoming state to link the two together
LaunchedEffect(state) {
styleState.playerState = state
}
BasicComponents.ktwithBaseButton,BaseText, andBaseCheckboxexamples using thestyleablemodifier.StylesBasics.ktcovering style merging, property overwriting, standalone style definitions, and parent-child styling inheritance.StyleDosDonts.ktoutlining best practices for exposing style parameters and replacing visual-based parameters in design systems.StylesExamples.ktcontaining advanced UI patterns like hover effects, depth-pressed animations, and glowing gradients usingStyleScope.StylesStates.ktdemonstrating interaction-driven styles (hovered, pressed, focused), property animations, and custom style state keys.StylesThemes.ktshowing integration ofStyleobjects within a custom theme usingCompositionLocal.androidx.compose.foundationto1.11.0-alpha06and BOM to2026.02.01.