Created
October 18, 2025 08:52
-
-
Save Sottti/56c8c5692b2d7de3327af152ad5d6a33 to your computer and use it in GitHub Desktop.
Tired of if (Build.VERSION.SDK_INT >= ...) checks cluttering your code? π€ The @ChecksSdkIntAtLeast annotation is a lifesaver! It tells the lint tool that a boolean property is your version check.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Composable | |
| @ReadOnlyComposable | |
| public fun colors( | |
| colorContrast: ResolvedColorContrast, | |
| darkTheme: Boolean, | |
| dynamicColor: ResolvedDynamicColor, | |
| ): ColorScheme = when { | |
| dynamicColor.enabled -> dynamicColorScheme(darkTheme) | |
| darkTheme -> colorContrast.darkColorScheme() | |
| else -> colorContrast.lightColorScheme() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Composable | |
| @ReadOnlyComposable | |
| @RequiresApi(api = 31) | |
| internal fun dynamicColorScheme(darkTheme: Boolean): ColorScheme = | |
| when { | |
| darkTheme -> dynamicDarkColorScheme(LocalContext.current) | |
| else -> dynamicLightColorScheme(LocalContext.current) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import androidx.annotation.ChecksSdkIntAtLeast | |
| public data class ResolvedDynamicColor( | |
| @ChecksSdkIntAtLeast(api = 31) val enabled: Boolean, | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment