Skip to content

Instantly share code, notes, and snippets.

@Sottti
Created October 18, 2025 08:52
Show Gist options
  • Select an option

  • Save Sottti/56c8c5692b2d7de3327af152ad5d6a33 to your computer and use it in GitHub Desktop.

Select an option

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.
@Composable
@ReadOnlyComposable
public fun colors(
colorContrast: ResolvedColorContrast,
darkTheme: Boolean,
dynamicColor: ResolvedDynamicColor,
): ColorScheme = when {
dynamicColor.enabled -> dynamicColorScheme(darkTheme)
darkTheme -> colorContrast.darkColorScheme()
else -> colorContrast.lightColorScheme()
}
@Composable
@ReadOnlyComposable
@RequiresApi(api = 31)
internal fun dynamicColorScheme(darkTheme: Boolean): ColorScheme =
when {
darkTheme -> dynamicDarkColorScheme(LocalContext.current)
else -> dynamicLightColorScheme(LocalContext.current)
}
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