Skip to content

Add Compose Foundation Style snippets#817

Draft
riggaroo wants to merge 3 commits intomainfrom
feature/styles
Draft

Add Compose Foundation Style snippets#817
riggaroo wants to merge 3 commits intomainfrom
feature/styles

Conversation

@riggaroo
Copy link
Collaborator

  • 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.

* 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`.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 Style Snippets: Added several new Kotlin files (BasicComponents.kt, StylesBasics.kt, StyleDosDonts.kt, StylesExamples.kt, StylesStates.kt, StylesThemes.kt) to showcase various aspects of Compose Foundation Style, including basic components, style merging, best practices, advanced UI patterns, interaction states, and theme integration.
  • Dependency Updates: Updated the androidx.compose.foundation library to version 1.11.0-alpha06 and the Compose BOM to 2026.02.01 to support the new style features.
  • Basic Component Examples: Introduced BaseButton, BaseText, and BaseCheckbox examples in BasicComponents.kt demonstrating the use of the styleable modifier.
  • Style Usage and Best Practices: Provided examples in StylesBasics.kt for style merging, property overwriting, standalone style definitions, and parent-child styling inheritance, along with best practices in StyleDosDonts.kt for exposing style parameters and replacing visual parameters.
  • Advanced UI Patterns and States: Showcased advanced UI patterns like hover effects, depth-pressed animations, and glowing gradients in StylesExamples.kt, and demonstrated interaction-driven styles (hovered, pressed, focused), property animations, and custom style state keys in StylesStates.kt.
  • Theme Integration: Illustrated how to integrate Style objects within a custom theme using CompositionLocal in StylesThemes.kt.

🧠 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
  • compose/snippets/build.gradle.kts
    • Added implementation(libs.androidx.compose.foundation) dependency.
  • compose/snippets/src/main/java/com/example/compose/snippets/styles/BasicComponents.kt
    • Added BasicComponents.kt containing examples for BaseButton, BaseText, and BaseCheckbox using the styleable modifier.
  • compose/snippets/src/main/java/com/example/compose/snippets/styles/StyleDosDonts.kt
    • Added StyleDosDonts.kt outlining best practices for exposing style parameters and replacing visual-based parameters in design systems.
  • compose/snippets/src/main/java/com/example/compose/snippets/styles/StylesBasics.kt
    • Added StylesBasics.kt covering style merging, property overwriting, standalone style definitions, and parent-child styling inheritance.
  • compose/snippets/src/main/java/com/example/compose/snippets/styles/StylesExamples.kt
    • Added StylesExamples.kt containing advanced UI patterns like hover effects, depth-pressed animations, and glowing gradients using StyleScope.
  • compose/snippets/src/main/java/com/example/compose/snippets/styles/StylesStates.kt
    • Added StylesStates.kt demonstrating interaction-driven styles (hovered, pressed, focused), property animations, and custom style state keys.
  • compose/snippets/src/main/java/com/example/compose/snippets/styles/StylesThemes.kt
    • Added StylesThemes.kt showing integration of Style objects within a custom theme using CompositionLocal.
  • gradle/libs.versions.toml
    • Updated androidx-compose-bom version from 2026.01.01 to 2026.02.01.
    • Updated androidx-compose-foundation version from compose-latest to 1.11.0-alpha06.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
state: PlayerState = remember { PlayerState.Paused }
state: PlayerState = PlayerState.Paused

Comment on lines +283 to +309
@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
)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The toUpperCase() function is deprecated. You should use uppercase() instead for string transformations to ensure future compatibility and adhere to best practices.

Suggested change
"Button 19".toUpperCase(Locale.current),
"Button 19".uppercase(Locale.current),

Comment on lines +265 to +266
// Set equal to incoming state to link the two together
styleState.playerState = state
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant