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
// create properties | |
data class SharedToolbarProps( | |
val title: String, | |
val subtitle: String, | |
val isMenuIconVisible: Boolean, | |
val onMenuIconClicked: () -> Unit | |
) { | |
companion object { | |
val default: SharedToolbarProps = SharedToolbarProps( | |
title = "Lorem Title", |
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
/* | |
* MIT License | |
* | |
* Copyright (c) 2022 Albert Chang | |
* | |
* Permission is hereby granted, free of charge, to any person obtaining a copy | |
* of this software and associated documentation files (the "Software"), to deal | |
* in the Software without restriction, including without limitation the rights | |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
* copies of the Software, and to permit persons to whom the Software is |
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 | |
fun Foo() { | |
val countState = remember { mutableStateOf(0) } | |
Button(onClick = { | |
val count = countState.value //👈 count is 0 | |
val setCount = { lastestCount: Int -> | |
countState.value = lastestCount |
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
// Create a counter state | |
var count by remember { | |
mutableStateOf(value = 0) | |
} | |
Column( | |
modifier = Modifier | |
.fillMaxSize() | |
.background(Color.White), | |
verticalArrangement = Arrangement.Center, | |
horizontalAlignment = Alignment.CenterHorizontally |
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
Button( | |
onClick = { | |
// thing that is happening is : | |
setCount(count + 1) //👉 0 + 1 | |
setCount(count + 1) //👉 0 + 1 | |
} | |
) { | |
Text(text = "Increment by 2") | |
} // button end |
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
// Create a counter state | |
val(count, setCount) = remember { | |
mutableStateOf(0) | |
} | |
Column( | |
modifier = Modifier | |
.fillMaxSize() | |
.background(Color.White), | |
verticalArrangement = Arrangement.Center, | |
horizontalAlignment = Alignment.CenterHorizontally |
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
// Create a counter state | |
val(count, setCount) = remember { | |
mutableStateOf(0) | |
} | |
Column( | |
modifier = Modifier | |
.fillMaxSize() | |
.background(Color.White), | |
verticalArrangement = Arrangement.Center, | |
horizontalAlignment = Alignment.CenterHorizontally |
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
val(isChecked, setChecked) = remember { | |
mutableStateOf(value = false) | |
} | |
Checkbox( | |
checked = isChecked, | |
onCheckedChange = setChecked | |
) | |
// vs |
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
// dont forget these imports | |
import androidx.compose.runtime.getValue | |
import androidx.compose.runtime.setValue | |
// for read only from state | |
val count by mutableStateOf(0) | |
// for read and write on state | |
var count by mutableStateOf(0) |
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
inline operator fun <T> State<T>.getValue(thisObj: Any?, property: KProperty<*>): T = value | |
inline operator fun <T> MutableState<T>.setValue(thisObj: Any?, property: KProperty<*>, value: T) { | |
this.value = value | |
} |
NewerOlder