LoginSignup
0
0

More than 1 year has passed since last update.

jetpack composeでdrawableEndCompatを実装したい

Posted at

初めに

今回は、jetpack composeでまだサポートしてないdrawableEndCompatを実装していきたいと思います。

実装

まず、初めにお話ししたようにjetpack composeではまだdrawableEndCompatの実装をサポートしてません(そもそもするようになるのかは不安ですが...)
なので自作していこうと思います。
composeに少し触れてる人ならこれかなぁと予想はついてると思います。
では早速書いていきます

ConstraintLayout() {
    val (content, image) = createRefs()
    Box(
        Modifier.constrainAs(content) {
            end.linkTo(image.start)
        }
    ) {
        Text(
            text = "Text",
            modifier = Modifier
                .width(IntrinsicSize.Max)
                .wrapContentHeight(),
        )
    }
    Image(
        painter = painterResource(id = R.drawable.image_resource),
        contentDescription = null,
        Modifier
            .constrainAs(image) {
                top.linkTo(content.top)
                bottom.linkTo(content.bottom)
                start.linkTo(content.end)
            }
    )
}

上記だけで実装できます。
付けたい場所によって下記の中身を変えてあげるだけで大丈夫です。

Modifier
    .constrainAs(image) {
        top.linkTo(content.top)
        bottom.linkTo(content.bottom)
        start.linkTo(content.end)
    }

また、共通化しておくことで、画像やつける対象、つける場所を選択できるようになるので便利かもしれませんね

最後に

自分がjetpack composeに本格的に触り始めて実装も進めているので、備忘録兼誰かのお役に立てればと思います。
まだまだ新しい技術なので需要はあると思うので、今後jetpack composeに関する記事が増やしていこうかなと思っています。

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