import React from 'react'
import PropTypes from 'prop-types'
import { ScrollView } from 'react-native'

/**
 * A wrapper for ScrollView that supports an `onScrollEnd` function.
 *
 * React Native has two scroll end handlers, we want to treat them both the same.
 */
export const ScrollViewEnd = React.forwardRef(({ onScrollEnd, ...props }, ref) => (
  <ScrollView
    ref={ref}
    {...props}
    onScrollEndDrag={onScrollEnd}
    onMomentumScrollEnd={onScrollEnd}
  />
))
ScrollViewEnd.displayName = 'ScrollViewEnd'

ScrollViewEnd.propTypes = {
  onScrollEnd: PropTypes.func.isRequired
}
