This file contains 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.FloatRange | |
import androidx.compose.foundation.Canvas | |
import androidx.compose.foundation.layout.BoxWithConstraints | |
import androidx.compose.foundation.layout.fillMaxSize | |
import androidx.compose.runtime.Composable | |
import androidx.compose.runtime.LaunchedEffect | |
import androidx.compose.runtime.getValue | |
import androidx.compose.runtime.mutableStateOf | |
import androidx.compose.runtime.remember | |
import androidx.compose.runtime.setValue |
This file contains 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
@Preview | |
@Composable | |
private fun ThemeSwapDemo() { | |
var dark by remember { mutableStateOf(false) } | |
Crossfade(targetState = dark) { isDark -> | |
MyMaterialTheme(darkTheme = isDark) { | |
Surface(color = MaterialTheme.myColors.background) { | |
Box(Modifier.fillMaxSize(), Alignment.Center) { | |
Button( | |
onClick = { dark = !dark }, |
This file contains 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
val MaterialTheme.myColors: MyColors | |
@Composable | |
@ReadOnlyComposable | |
get() = LocalColors.current |
This file contains 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
private val LocalColors = staticCompositionLocalOf { LightColorPalette } | |
@Composable | |
fun MyMaterialTheme( | |
darkTheme: Boolean = isSystemInDarkTheme(), | |
content: @Composable () -> Unit, | |
) { | |
val colors = if (darkTheme) { | |
DarkColorPalette | |
} else { |
This file contains 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
data class MyColors( | |
val material: Colors, | |
val warning: Color, | |
val onWarning: Color, | |
) { | |
val primary: Color get() = material.primary | |
val primaryVariant: Color get() = material.primaryVariant | |
val secondary: Color get() = material.secondary | |
val secondaryVariant: Color get() = material.secondaryVariant | |
val background: Color get() = material.background |
This file contains 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
class MyActivity : Activity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
/* ... */ | |
bindData(MyViewModel()) | |
} | |
private fun bindData(viewModel: MyViewModel) { | |
// From views | |
firstName.textChanges() |
This file contains 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
# Shows current working directory, time, the prompt symbol and the current git branch | |
# The color the git branch is displayed in depends on the state of the repository: | |
# | |
# Red = has unstaged changes | |
# Yellow = index matches working tree but is uncommitted | |
# Blue = has untracked files | |
# Green = repository is clean | |
# Purple = has unmerged changes | |
# | |
# |