5
1

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 5 years have passed since last update.

react nativeのScrollViewで最下部までスクロールしたときに処理を実行する方法

Posted at

react nativeのScrollViewはscrollToEnd()があるけど、手動で最後までスクロールしたい時のpropsがない。

今回はscrollViewのonMomentumScrollEndをつかって、この処理を実行する。
onMomentumScrollEndは一回のスクロールが終わった時、何か処理をするprops

  <ScrollView
    onMomentumScrollEnd={this._scrollPosition.bind(this)}
  >
  </ScrollView>

  _scrollPosition (e: any) {
    let offsetY = e.nativeEvent.contentOffset.y // スクロール距離
    let contentSizeHeight = e.nativeEvent.contentSize.height // scrollView contentSizeの高さ
    let scrollViewHeight = e.nativeEvent.layoutMeasurement.height // scrollViewの高さ

    if (offsetY + scrollViewHeight >= contentSizeHeight) {
      console.log('ここで処理を実行する')
    }
  }
5
1
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
5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?