{"name":"universal-panresponder","version":"0.2.2","description":"A universal PanResponder API.","license":"BSD-3-Clause","main":"lib/index.js","repository":{"type":"git","url":"git+https://github.com/alibaba/rax.git"},"bugs":{"url":"https://github.com/alibaba/rax/issues"},"homepage":"https://github.com/alibaba/rax#readme","dependencies":{"universal-env":"^0.2.2"},"_id":"universal-panresponder@0.2.2","scripts":{},"_shasum":"1f078a27cfdf72b2403841a125666656edda28d5","_from":".","_npmVersion":"4.2.0","_nodeVersion":"4.6.2","_npmUser":{"name":"yuanyan","email":"yuanyan.cao@gmail.com"},"maintainers":[{"name":"yuanyan","email":"yuanyan.cao@gmail.com"}],"dist":{"shasum":"1f078a27cfdf72b2403841a125666656edda28d5","tarball":"http://registry-npm.ywwl.com/universal-panresponder/download/universal-panresponder-0.2.2.tgz","integrity":"sha512-CI2dsCckGsIG9OeMOKMTlnHdL7tE+lvmx5LfA9qyZ4DTKsRJnTAG79s2RvoTqnszh8QXjih51QPAszYc1L4giw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC9NZ21Gg8HDan0oYEEIruiqpMfnFklfeTNHUf5fDLc2AIhAO3HamtWsveS+BZInIyZvuzKrcQSvJVj0lwSlcYF3VAV"}],"size":47742,"noattachment":false,"key":"/universal-panresponder/-/universal-panresponder-0.2.2.tgz"},"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/universal-panresponder-0.2.2.tgz_1488522944375_0.020487152505666018"},"directories":{},"readme":"# universal-panresponder [![npm](https://img.shields.io/npm/v/universal-panresponder.svg)](https://www.npmjs.com/package/universal-panresponder)\n\n> A solution to the touch gesture. Reference to the [React Native PanResponder](https://facebook.github.io/react-native/docs/panresponder.html)\n\n## Install\n\n```bash\n$ npm install universal-panresponder --save\n```\n\n## Usage\n\n```jsx\nimport {createElement, Component, render, findDOMNode} from 'rax';\nimport {View} from 'rax-components';\nimport PanResponder from 'universal-panresponder';\n\nconst CIRCLE_SIZE = 80;\nconst CIRCLE_COLOR = 'blue';\nconst CIRCLE_HIGHLIGHT_COLOR = 'green';\n\nclass PanResponderSample extends Component {\n\n  componentWillMount () {\n    this._panResponder = PanResponder.create({\n      onStartShouldSetPanResponder: this._handleStartShouldSetPanResponder,\n      onMoveShouldSetPanResponder: this._handleMoveShouldSetPanResponder,\n      onPanResponderGrant: this._handlePanResponderGrant,\n      onPanResponderMove: this._handlePanResponderMove,\n      onPanResponderRelease: this._handlePanResponderEnd,\n      onPanResponderTerminate: this._handlePanResponderEnd,\n    });\n    this._previousLeft = 20;\n    this._previousTop = 84;\n    this._circleStyles = {\n      style: {\n        left: this._previousLeft,\n        top: this._previousTop\n      }\n    };\n  }\n\n  componentDidMount () {\n    this._updatePosition();\n  }\n\n  render () {\n    return (\n      <View style={styles.container}>\n        <View\n          ref={(circle) => { this.circle = circle; }}\n          style={styles.circle}\n          {...this._panResponder.panHandlers}\n        />\n      </View>\n    );\n  }\n\n  _highlight() {\n    if (this.circle && this.circle.setNativeProps) {\n      this.circle.setNativeProps({\n        style: {\n          backgroundColor: CIRCLE_HIGHLIGHT_COLOR\n        }\n      });\n    }\n  }\n\n  _unHighlight() {\n    if (this.circle && this.circle.setNativeProps) {\n      this.circle.setNativeProps({\n        style: {\n          backgroundColor: CIRCLE_COLOR\n        }\n      });\n    }\n  }\n\n  _updatePosition () {\n    if (this.circle && this.circle.setNativeProps) {\n      this.circle.setNativeProps(this._circleStyles);\n    }\n  }\n\n  _handleStartShouldSetPanResponder (e, gestureState) {\n    // Should we become active when the user presses down on the circle?\n    return true;\n  }\n\n  _handleMoveShouldSetPanResponder (e, gestureState) {\n    // Should we become active when the user moves a touch over the circle?\n    return true;\n  }\n\n  _handlePanResponderGrant = (e, gestureState) => this._highlight();\n\n\n  _handlePanResponderMove = (e, gestureState) => {\n    this._circleStyles.style.left = this._previousLeft + gestureState.dx;\n    this._circleStyles.style.top = this._previousTop + gestureState.dy;\n    this._updatePosition();\n  };\n\n  _handlePanResponderEnd = (e, gestureState) => {\n    this._unHighlight();\n    this._previousLeft += gestureState.dx;\n    this._previousTop += gestureState.dy;\n  };\n}\n\nconst styles = {\n  circle: {\n    width: CIRCLE_SIZE,\n    height: CIRCLE_SIZE,\n    borderRadius: CIRCLE_SIZE / 2,\n    backgroundColor: CIRCLE_COLOR,\n    position: 'absolute',\n    left: 0,\n    top: 0,\n  },\n  container: {\n    flex: 1,\n    paddingTop: 64,\n  },\n};\n\nrender(<PanResponderSample />, mountNode);\n```\n\nFor more complete documentation, please refer to [React Native PanResponder](https://facebook.github.io/react-native/docs/panresponder.html).","publish_time":1488522946443,"_cnpm_publish_time":1488522946443,"dist-tags":{"latest":"0.6.5"}}