Skip to content

Commit

Permalink
Merge pull request #2 from AndrewSouthpaw/master
Browse files Browse the repository at this point in the history
Add onEndReached props.
  • Loading branch information
erennyuksell authored Jun 25, 2019
2 parents 843fcbd + 58a9f4d commit 1d515d9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ Prop | Description | Type | Default
`errorComponent` | Custom function to render the page of an image that couldn't be displayed | `function` | A `<View>` with a stylized error
`flatListProps` | Props to be passed to the underlying `FlatList` | `object` | `{windowSize: 3}`
`pageMargin` | Blank space to show between images | `number` | `0`
`onEndReached` | Fired when the page index is within the `onEndReachedThreshold` of the `images` content | `function`
`onEndReachedThreshold` | How far from the end (in units of visible length of the list) the end of the list of images must be from the end of the content to trigger the onEndReached callback. Thus a value of 0.5 will trigger onEndReached when the end of the content is within half the visible length of the images. | `number` | `0.5`
`onPageSelected` | Fired with the index of page that has been selected | `function`
`onPageScrollStateChanged` | Called when page scrolling state has changed, see [scroll state and events](#scroll-state-and-events) | `function`
`onPageScroll` | Scroll event, see [scroll state and events](#scroll-state-and-events) | `function`
Expand Down
6 changes: 6 additions & 0 deletions src/Gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export default class Gallery extends PureComponent {
initialPage: PropTypes.number,
scrollViewStyle: ViewPropTypes ? ViewPropTypes.style : View.propTypes.style,
pageMargin: PropTypes.number,
onEndReached: PropTypes.func,
onEndReachedThreshold: PropTypes.number,
onPageSelected: PropTypes.func,
onPageScrollStateChanged: PropTypes.func,
onPageScroll: PropTypes.func,
Expand All @@ -32,6 +34,7 @@ export default class Gallery extends PureComponent {
removeClippedSubviews: true,
imageComponent: undefined,
scrollViewStyle: {},
onEndReachedThreshold: 0.5,
flatListProps: DEFAULT_FLAT_LIST_PROPS
};

Expand Down Expand Up @@ -215,6 +218,9 @@ export default class Gallery extends PureComponent {
onPageSelected (page) {
this.currentPage = page;
this.props.onPageSelected && this.props.onPageSelected(page);
if (page + 1 > this.props.onEndReachedThreshold * this.props.images.length) {
this.props.onEndReached && this.props.onEndReached();
}
}

onPageScrollStateChanged (state) {
Expand Down

0 comments on commit 1d515d9

Please sign in to comment.