Created
December 17, 2018 08:56
-
-
Save vldvel/aafc4642bbb9b9d2163b761a62593fdc to your computer and use it in GitHub Desktop.
Using Swiper.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as React from 'react'; | |
| import { Loader } from 'path-to-loader'; | |
| import { Swiper } from 'path-to-swiper'; | |
| class PullToUpdate extends React.PureComponent { | |
| state = { | |
| translate: 0 | |
| }; | |
| rootNode = null; | |
| setRootNode = (node) => { | |
| this.rootNode = node; | |
| }; | |
| onMove = ({ event, y, direction }) => { | |
| if (direction === 'Y' && this.rootNode && this.rootNode.scrollTop === 0) { | |
| event.stopPropagation(); | |
| this.setTranslate(y); | |
| } | |
| }; | |
| onMoveEnd = async ({ y, direction }) => { | |
| if (direction === 'Y') { | |
| if (y >= MAX_TRANSFORM_SIZE) { | |
| await this.props.onToggleDown(); | |
| this.setTranslate(0); | |
| } else { | |
| this.setTranslate(0); | |
| } | |
| } | |
| }; | |
| setTranslate = (translate) => { | |
| this.setState({ translate }); | |
| }; | |
| render() { | |
| return ( | |
| <Swiper | |
| onMove={this.onMove} | |
| onMoveEnd={this.onMoveEnd} | |
| > | |
| <div ref={this.setRootNode}> | |
| {this.state.translate > 0 && <Loader />} | |
| {this.props.children} | |
| </div> | |
| </Swiper> | |
| ); | |
| } | |
| } | |
| export { PullToUpdate }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment