All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.com.softartdev.themepref.PreferableMaterialTheme.kt Maven / Gradle / Ivy

Go to download

Kotlin Multiplatform library for easy switching Dark/Light Material themes on Compose.

There is a newer version: 0.5.5
Show newest version
package com.softartdev.themepref

import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.runtime.staticCompositionLocalOf

val LocalThemePrefs = staticCompositionLocalOf {
    error("CompositionLocal LocalThemePrefs not present")
}

@Composable
fun PreferableMaterialTheme(
    content: @Composable PreferableMaterialTheme.() -> Unit
) {
    val themePrefs = rememberThemePrefs()
    CompositionLocalProvider(
        LocalThemePrefs provides themePrefs,
    ) {
        MaterialTheme(
            colors = themePrefs.colors,
            content = { PreferableMaterialTheme.content() }
        )
    }
}

object PreferableMaterialTheme {

    val themePrefs: ThemePrefs
        @Composable
        @ReadOnlyComposable
        get() = LocalThemePrefs.current
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy