Skip to content

Commit

Permalink
feat: added onTopReached callback
Browse files Browse the repository at this point in the history
  • Loading branch information
pwysowski committed Aug 5, 2020
1 parent 620a5ef commit 0f3d0b8
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/StickyParallaxHeader.js
@@ -1,5 +1,14 @@
import React, { Component } from 'react'
import { arrayOf, bool, func, node, number, shape, string, oneOfType } from 'prop-types'
import {
arrayOf,
bool,
func,
node,
number,
shape,
string,
oneOfType
} from 'prop-types'
import {
Dimensions,
ImageBackground,
Expand Down Expand Up @@ -170,6 +179,15 @@ class StickyParallaxHeader extends Component {
return null
}

isCloseToTop = ({contentOffset}) => {
const { onTopReached } = this.props
if (contentOffset.y <= 0) {
return onTopReached && onTopReached()
}

return null
}

renderHeader = () => {
const { header, headerHeight, backgroundColor, transparentHeader } = this.props

Expand Down Expand Up @@ -335,6 +353,7 @@ class StickyParallaxHeader extends Component {
useNativeDriver: true,
listener: (e) => {
this.isCloseToBottom(e.nativeEvent)
this.isCloseToTop(e.nativeEvent)
scrollEvent(e)
}
}
Expand Down Expand Up @@ -416,7 +435,8 @@ StickyParallaxHeader.propTypes = {
snapStopThreshold: oneOfType([bool, number]),
snapValue: oneOfType([bool, number]),
transparentHeader: bool,
onRef: func
onRef: func,
onTopReached: func
}

StickyParallaxHeader.defaultProps = {
Expand Down

0 comments on commit 0f3d0b8

Please sign in to comment.