Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ To prevent Chrome overscroll set `overscroll-behavior-y: contain [or] none;` on
| resetEase | String | `cubic-bezier(0.215, 0.61, 0.355, 1)` | Ease when resetting |
| shouldPullToRefresh | Function | `() => window.scrollY <= 0` | When to allow pulling |
| disabled | Boolean | | Disables all functionality |
| targetComponent | Boolean | `false` | Enable to only handle touch events on the wrapped component, otherwise all window touch events will be handled |

## Examples

Expand Down
20 changes: 13 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,26 @@ class Pullable extends React.Component {

this.clearTouchStatus();

this.componentId = `pull-div-${Date.now() + Math.floor(Math.random() * 10000)}`;

this.state = {
status: 'ready',
height: 0
};
}

componentDidMount() {
window.addEventListener('touchstart', this.onTouchStart);
window.addEventListener('touchmove', this.onTouchMove, { passive: false });
window.addEventListener('touchend', this.onTouchEnd);
let element = this.props.targetComponent ? document.getElementById(this.componentId) : window;
element.addEventListener('touchstart', this.onTouchStart);
element.addEventListener('touchmove', this.onTouchMove, { passive: false });
element.addEventListener('touchend', this.onTouchEnd);
}

componentWillUnmount() {
window.removeEventListener('touchstart', this.onTouchStart);
window.removeEventListener('touchmove', this.onTouchMove, { passive: false });
window.removeEventListener('touchend', this.onTouchEnd);
let element = this.props.targetComponent ? document.getElementById(this.componentId) : window;
element.removeEventListener('touchstart', this.onTouchStart);
element.removeEventListener('touchmove', this.onTouchMove, { passive: false });
element.removeEventListener('touchend', this.onTouchEnd);

clearTimeout(this.refreshCompletedTimeout);
clearTimeout(this.resetTimeout);
Expand Down Expand Up @@ -142,7 +146,9 @@ class Pullable extends React.Component {
</SpinnerSVG>
</Spinner>
</Container>
{this.props.children}
<div id={this.componentId}>
{this.props.children}
</div>
</React.Fragment>
);
}
Expand Down