Skip to main content

Jetpack Composeで調べたこと その3

Jetpack Composeで調べたこと その2
の続編

Jetpack Composeを本番アプリに本格導入始めました
そのなかで不明点をまとめる


UI
・CircularProgressIndicator
ローディング
https://techbooster.org/android/ui/18545/

・Loading Dialog
Dialogの中にCircularProgressIndicatorを入れる
https://stackoverflow.com/questions/67546275/progressdialog-in-jetpack-compose

・wrapContentHeight
https://qiita.com/bu-ka/items/43e9854761de9fe51188

・modifier.height(IntrinsicSize.Min)
この高さを最小になるようにする
https://developer.android.com/jetpack/compose/layouts/intrinsic-measurements?hl=ja

 

Jetpack ComposeでAndroid
・MutableListにaddする
updateして中でaddする
https://stackoverflow.com/questions/70905480/mutablestateflow-not-working-with-mutablelist

val songList: MutableStateFlow<MutableList<Song>> = MutableStateFlow(emptyList())

fun add(song: Song) {
    songList.update {
        songList.value.toMutableList().apply { this.add(song) }
    }
}

・Context
val context = LocalContext.current
https://zenn.dev/shogo/articles/90f3a73af9e613

 

非同期
・SharedFlowとChannel
全員に通知がSharedFlow
ひとりに通知され、状態が保持されるChannel
https://qiita.com/kazakago/items/fba61beba05f5297d951

・rememberCoroutineScope
ComposeからCoroutineを呼ぶ
https://qiita.com/KimKo/items/a0d5ea39ef2622b5b6d9

・LaunchedEffect
値を監視して変化したらcoroutineを呼ぶ
https://qiita.com/KimKo/items/a0d5ea39ef2622b5b6d9

・ページング
末尾にComposeの要素をつけて、呼ばれたらリクエストを実施する
https://qiita.com/yasukotelin/items/e23248d4fb3962dc194f

 

エラー
・TypeVariable(T)’ has no method ‘getValue
以下を入れる
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
https://dalomo.net/blog/2021/04/03/1342/

・Vertically scrollable component was measured with an infinity maximum height constraints
以下のエラーが出たら
lazycolumnの中にlazycolumn入れたのが原因
java.lang.IllegalStateException: Vertically scrollable component was measured with an infinity maximum height constraints, which is disallowed. One of the common reasons is nesting layouts like LazyColumn and Column(Modifier.verticalScroll()). If you want to add a header before the list of items please add a header as a separate item() before the main items() inside the LazyColumn scope. There are could be other reasons for this to happen: your ComposeView was added into a LinearLayout with some weight, you applied Modifier.wrapContentSize(unbounded = true) or wrote a custom layout. Please try to remove the source of infinite constraints in the hierarchy above the scrolling container.

 

関連記事:

Pocket