pavi2410
10/23/2019, 7:46 PM1 👁️ | @Composable
2 | fun Greeting(name: String = "Android") {
3 | Text (text = "Hello $name!")
4 | }
George Mount
10/23/2019, 7:47 PMLuca Nicoletti
10/23/2019, 7:49 PMFudge
10/23/2019, 7:51 PMromainguy
10/23/2019, 8:02 PMLuca Nicoletti
10/23/2019, 8:07 PMFudge
10/23/2019, 8:07 PM@Preview
and going to the preview screen.romainguy
10/23/2019, 8:16 PMFudge
10/23/2019, 8:17 PM@Preview
annotation is pointless 🤔romainguy
10/23/2019, 8:18 PMFudge
10/23/2019, 8:20 PM@Preview
annotation. Haven't seen that yet.romainguy
10/23/2019, 8:26 PMPhotoCard()
composable, but my preview will be:@Preview
fun PhotoCardPreviewDark() {
val testData = ...
MaterialTheme(darkTheme) {
PhotoCard(testData)
}
}
Fudge
10/23/2019, 8:44 PMPhotoCardPreviewDark
would be useful.romainguy
10/23/2019, 8:49 PMFudge
10/23/2019, 8:51 PMromainguy
10/23/2019, 8:51 PMFudge
10/23/2019, 8:57 PM@Composable fun MyButton(size : Int) = /**/
And generates this
@Preview
fun MyButtonPreview(){
MaterialTheme( <--- cursor goes here first with a default value of lightTheme){
MyButton( <--- cursor then goes here)
}
}
Cody Engel
10/23/2019, 8:58 PM@Preview
more than a run button. Seeing all of the previews is nice. I think it’s a bit confusing with how it is presented though…
I think my assumption was I’d just add @Preview
to the component I’d use in production, that doesn’t seem to be the use-case though.Fudge
10/23/2019, 8:58 PMromainguy
10/23/2019, 9:00 PMCody Engel
10/23/2019, 9:01 PMromainguy
10/23/2019, 9:02 PMFudge
10/23/2019, 9:02 PMCody Engel
10/23/2019, 9:03 PM@Model
class Name(var name: String)
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
HelloForm()
}
}
}
@Composable
fun HelloForm(name: Name = Name("Android")) = MaterialTheme {
val name = Name("Android")
Column {
Greeting(name = name.name)
Button(text = "New Name", onClick = { name.name = "Cody" } )
}
}
@Composable
fun Greeting(name: String) {
Text(text = "Hello $name!")
}
ComposePreviews
Kotlin file with this:
@Preview
@Composable
fun HelloFormNormal() {
HelloForm(Name("Test"))
}
Which is probably fine, it’s a little weird that anyone could call HelloFormNormal
though, it feels more like documentation to me than something I’d want others to actually callromainguy
10/23/2019, 9:07 PMCody Engel
10/23/2019, 9:08 PMromainguy
10/23/2019, 9:08 PMCody Engel
10/23/2019, 9:09 PMZach Klippenstein (he/him) [MOD]
10/25/2019, 12:43 PMromainguy
10/25/2019, 1:44 PMCody Engel
10/25/2019, 3:13 PM