https://kotlinlang.org logo
#compose
Title
# compose
c

camkadev

01/30/2020, 10:19 AM
Copy code
Functions which invoke @Composable functions must be marked with the @Composable annotation
any workaround to change data (outside Composable) placed inside state?
i

Ian Warwick

01/30/2020, 10:36 AM
not seen this one, got an example of code causing this?
z

zhuinden

01/30/2020, 10:40 AM
You shouldn't need to be in a
@Composable
context to update either a
@Model
nor a
state {
👍 1
c

camkadev

01/30/2020, 10:45 AM
Copy code
/* TODO here i got: Functions which invoke @Composable functions must be marked with the @Composable annotation*/
@Composable
private val showDialog = state {
    false
}

@Composable
fun SomeComposable(){
    Button(
        "Sign In",
        onClick =
        /* TODO here i got: Functions which invoke @Composable functions must be marked with the @Composable annotation*/
        {
            showDialog.value = false
        }
    )
}
i

Ian Warwick

01/30/2020, 10:53 AM
I don't think you need the annotation
@Composable
on that
showDialog
state variable
also can you use property delegate for
showDialog
such as private
val showDialog by state { false }
? not sure if it works in all contexts but it works for inline variables and means you don't need to
showDialog.value = false
can simply use
showDialog = false
👍🏻 1
c

camkadev

01/30/2020, 11:06 AM
i will try
yes
var showDialog by state { false }
is works, looks like i missed
by
explanation when reading
i

Ian Warwick

01/30/2020, 11:18 AM
nice 👍
Just checking docs I am not sure we should be using property delegates though 🤔
Copy code
import androidx.compose.state
import androidx.ui.core.Text
import androidx.ui.material.Button

val count = state { 0 }

Text(text = "You clicked ${count.value} times")
Button(text = "Click me", onClick = { count.value++ })
aha my apologies those docs show 3 different approaches, quite cool
👍 1
395 Views