2
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でconstraintLayout実装時に気をつけたいこと

Posted at

初めに

今回は、JetpackCompose実装時にConstraintLayoutを使う時に個人的に気をつけた方がいいなと感じたことを紹介していこうと思います

本文

Constraint Layoutを使いすぎない

基本的にはComposeで書いている時によほど複雑でない場合はConstraintLayoutを使ってるプロジェクトでもConstraintLayoutを使いすぎないということです。
これは、単にComposeで書いているのにConstraintLayoutを使ってしまうと変にコードが複雑になり、可読性が下がってしまいCompose本来の使い道と合ってないように感じるからです

Dimensionを適宜設定する

ComposeConstraintLayoutを使って実装したことある方は分かると思いますが、従来のXMLでの実装同様の規約を持たせるにはDimensionを適宜設定しないと自分が想定した通りの表示にならないことが多いです。
せっかくConstraintLayoutを使うのであれば、しっかりと設定をして想定通りの実装ができるように気をつけましょう

createRefsの命名をわかりやすくする

これも一つ目同様可読性に関わってくるものですが、複雑なViewになっているからこそConstraintLayoutを使ってるのでどの部品がどういった役割を持っているのかなどを命名のみで分かるように意識をすることで他者や後日自分が見たときの理解のスピードに直結します

最後に

今回は自分がCompose実装時にConstraintLayoutを使っていて感じたことをまとめてみました
どなたかのお役に立てれば幸いです

2
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
2
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?