Michal Bacik
10/30/2019, 7:59 PM@Model
class for this scenario.
@Composable
fun MyRect(){
var color = +memo{ Color.Green }
Clickable(onClick = {
color = Color.Red
}) {
ColoredRect(brush = SolidColor(color), height = 100.dp)
}
}
Luca Nicoletti
10/30/2019, 8:01 PMval color = +state{ Color.Green }
workscolor.value
when neededGrigorii Yurkov
10/30/2019, 8:02 PMvar color by +state { Color.Green }
Luca Nicoletti
10/30/2019, 8:02 PMval*
Michal Bacik
10/30/2019, 8:03 PMmemo
somewhere, but that's probably for different thing.Grigorii Yurkov
10/30/2019, 8:03 PMLuca Nicoletti
10/30/2019, 8:03 PMcolor.value
Michal Bacik
10/30/2019, 8:03 PMval
actually. you change its value
.Luca Nicoletti
10/30/2019, 8:03 PMcolor
itselfGrigorii Yurkov
10/30/2019, 8:04 PMby
, not =
Michal Bacik
10/30/2019, 8:05 PMvar color by +state{ Color.Green }
looks nicer, it doesn't require the .value
thing.Grigorii Yurkov
10/30/2019, 8:06 PMLuca Nicoletti
10/30/2019, 8:07 PM+
Michal Bacik
10/30/2019, 8:08 PMmemo
? 🤔Luca Nicoletti
10/30/2019, 8:09 PMEffect
Leland Richardson [G]
10/30/2019, 8:11 PMval color = +state { ... }
and var color by +state { ... }
will work.var
in a composable function that is not introduced by a property delegate. not sure yet thoughvar color by ...
version for a couple of reasons, but some people might consider that more magic, so up to youLuca Nicoletti
10/30/2019, 8:12 PMFudge
10/30/2019, 8:24 PMMichal Bacik
10/30/2019, 8:27 PMvar ... by
. You're interested in your variable, not the delegate that is behind providing its value.Fudge
10/30/2019, 8:29 PMLeland Richardson [G]
10/30/2019, 8:35 PMval x = a
val y = x.first
val z = x.second
vs
val (y, z) = a
Luca Nicoletti
10/30/2019, 8:38 PMFudge
10/31/2019, 9:23 AMby
syntax and to only use the by
syntax in official examples.Luca Nicoletti
10/31/2019, 9:24 AMState
object?Fudge
10/31/2019, 9:25 AMState
object?Luca Nicoletti
10/31/2019, 9:29 AMcomponent1
and component2
Fudge
10/31/2019, 9:29 AMLuca Nicoletti
10/31/2019, 9:30 AMcompoent1
and component2
of State
by
solution looks cleaner and I’d use that, but as @Leland Richardson [G] said it’s hard to know where to force somethingFudge
10/31/2019, 9:31 AM(someState,setSomeState)
Luca Nicoletti
10/31/2019, 9:31 AMFudge
10/31/2019, 9:31 AMby
?Grigorii Yurkov
10/31/2019, 9:32 AMval state = +state { false }
Checkbox(checked = state.value, onCheckedChange = state.component2())
var checked by state
Fudge
10/31/2019, 9:32 AMvar state by state { false }
Checkbox(checked = state.value, onCheckedChange = {state = it})
val (state,setState) = state { false }
Checkbox(checked = state.value, onCheckedChange = setState)
Luca Nicoletti
10/31/2019, 9:38 AMFudge
10/31/2019, 9:40 AMval (value,setValue) = state { false }
2)
val value = state {false}
3)
var value by state { false }
Luca Nicoletti
10/31/2019, 9:40 AM= +state{}
could be used for 1.
, by
could not. Maybe that’s the reason for having both of them 🙂andrew
11/07/2019, 12:19 AMLuca Nicoletti
11/07/2019, 4:01 AM