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でHorizontalPagerを使うときに気をつけること

Last updated at Posted at 2023-04-26

初めに

今回はjetpack composeHorizontalPagerを使うときに自分が詰まったところをを書いていこうと思います

本文

jetpack composeHorizontalPagerを使う時にaccompanistの記事が散見されるため、ページが切り替わったどうかを確認するのにaccompanist

derivedStateOf {
                val offset = calculateCurrentOffsetForPage(page)
                (-1.0f < offset) and (offset < 1.0f)
            }

を使ってる方や使おうとしてる方もいらっしゃると思いますが、実際には公式から既にHorizontalPagerが出ているので下記のものを使うのが正しくなっています

LaunchedEffect(pagerState) {
                snapshotFlow { pagerState.currentPage }.collect { page ->
                   
                }
            }

下記の公式URLからもアナウンスはされてるのですが、accompanist時代の記事を参考に作ろうとすると挙動がおかしくなるので注意しましょう
https://google.github.io/accompanist/pager/#migration

最後に

今回は備忘録としてすぐに自分が確認できるように記事に残しました
どなたかのお役に立てれば幸いです

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?