0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

「Jetpack Compose の基本」のメモ#7 ~状態ホイスティング、遅延リスト~

0
Last updated at Posted at 2024-07-08

8. 状態ホイスティング

  • 状態ホイスティングとは、複数のコンポーザブル関数で更新される状態変数を、それらの関数を内包(ラップ)する(親要素)に移動させること
  • 状態変数を定義するということは、MutableStateというオブジェクトを定義すること
  • しかしby キーワードを使用することで、MutableState オブジェクトをあたかも通常の変数のように扱えるようにする
  • つまり、.valueを付けなくても値を参照できる

MyAppコンポーザブルでボタンを含む関数を呼び出す時のクリック動作

  • 呼び出される関数の引数にクリック時の動作を渡せるように、onContinueClicked: () -> Unitを定義する
  • これにより、呼び出し元からクリック動作を指定することができる
  • Unitは値を返さないことを示す型
  • :() -> Unitは、「onContinueClickedには、引数を取らず、値を返さないラムダ式」という型指定を表す

9. 効率の良い遅延リストを作成する

names: List<String> = List(1000) { "$it" }

val names: List<String> = List(1000) { index -> index.toString() } 
  • {}カッコ内はは初期化処理が記述されている
  • Column
    • 画面に収まらないものも含めて、すべてのListをレンダリングする
  • LazyColumn
    • 画面に表示されているアイテムのみをレンダリングする
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?