Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ざっくり Jetpack Compose / Cookpad.apk #3

ざっくり Jetpack Compose / Cookpad.apk #3

star_zero

July 23, 2019
Tweet

More Decks by star_zero

Other Decks in Programming

Transcript

  1. レイアウト MaterialTheme { Container( padding = EdgeInsets(16.dp), alignment = Alignment.TopLeft,

    width = 240.dp, height = 120.dp ) { Text(text = "Hello World") } }
  2. レイアウト MaterialTheme { Column { Row { Text(text = "123")

    Text(text = "456") } Row { Text(text = "abc") Text(text = "def") } } }
  3. レイアウト MaterialTheme { Table { for (i in 0 until

    20) { tableRow { for (j in 0 until 2) { Padding(16.dp) { Text(text = "Cell $i - $j") } } } } } }
  4. ステート Column { val counter = +state { 0 }

    Text(text = "count = ${counter.value}") Button( text = "Button", onClick = { counter.value++ } ) }
  5. ステート Column { val flag = +state { false }

    if (flag.value) { Text(text = "Jepack") } else { Text(text = "Compose") } Button( text = "Button", onClick = { flag.value = !flag.value } ) }
  6. Commit Scope Column { +onActive { } // 最初の1回 +onCommit

    { // 描画されるたび onDispose { } // 破棄されるとき } val flag = +state { false } if (flag.value) { Container { +onCommit { onDispose { } } } } else { // ... } }