Skip to content

Instantly share code, notes, and snippets.

@hvisser
hvisser / init.gradle
Last active February 7, 2021 15:32
Init script to load additional properties from gradle.local.properties
gradle.projectsLoaded { gradle ->
def file = rootProject.file("gradle.local.properties")
if (file.exists()) {
def properties = new Properties()
file.withInputStream { properties.load(it) }
// set the loaded properties for all projects
gradle.beforeProject { project ->
properties.entrySet().forEach { prop ->
@hvisser
hvisser / MaterialConversions.kt
Last active May 15, 2024 09:16
Using both Material 3 and material components in Compose within the same theme
// conversions based on https://material.io/blog/migrating-material-3, deprecated colors set to Colors.Red
@Composable
fun fromMaterial3Theme(isLight: Boolean): Colors {
val scheme = MaterialTheme.colorScheme
return Colors(
primary = scheme.primary,
primaryVariant = Color.Red,
secondary = scheme.secondary,
secondaryVariant = Color.Red,
background = scheme.background,
@hvisser
hvisser / KeepScreenOn.kt
Created January 21, 2022 09:16
LocalView.current can be useful if you need to tap into a view function like keepScreenOn or haptics from Compose
@Composable
fun KeepScreenOn() {
val currentView = LocalView.current
DisposableEffect(Unit) {
currentView.keepScreenOn = true
onDispose {
currentView.keepScreenOn = false
}
}