diff --git a/dist/GestureView.js b/dist/GestureView.js deleted file mode 100644 index ba1fbc9..0000000 --- a/dist/GestureView.js +++ /dev/null @@ -1,79 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, '__esModule', { - value: true -}); - -var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } - -var _mixinsEvents = require('./mixins/events'); - -var _mixinsEvents2 = _interopRequireDefault(_mixinsEvents); - -var _mixinsDraggable = require('./mixins/draggable'); - -var _mixinsDraggable2 = _interopRequireDefault(_mixinsDraggable); - -var _react = require('react'); - -var _react2 = _interopRequireDefault(_react); - -var _reactNative = require('react-native'); - -exports['default'] = _react2['default'].createClass({ - displayName: 'GestureView', - - mixins: [(0, _mixinsEvents2['default'])(['onLayout']), (0, _mixinsDraggable2['default'])()], - - propTypes: { - gestures: _react.PropTypes.array.isRequired, - onError: _react.PropTypes.func.isRequired, - toStyle: _react.PropTypes.func.isRequired, - style: _react.PropTypes.any, - children: _react.PropTypes.array, - type: _react.PropTypes.oneOf(['View', 'Image']), - source: _react.PropTypes.any - }, - - componentDidMount: function componentDidMount() { - var _this = this; - - this.layoutStream.subscribe(function (layout) { - return _this.container.setNativeProps({ - style: _this.props.toStyle(layout) - }); - }, function (err) { - return _this.props.onError(err); - }); - }, - - render: function render() { - var _this2 = this; - - var props = _extends({ - ref: function ref(container) { - return _this2.container = container; - }, - style: this.props.style, - onLayout: function onLayout(_ref) { - var nativeEvent = _ref.nativeEvent; - - _this2.onLayout.onNext(nativeEvent); - }, - type: this.props.type || 'View', - source: this.props.source - }, this.gestureResponder.panHandlers); - return _react2['default'].createElement( - _reactNative.View, - null, - this.props.type === 'View' ? _react2['default'].createElement( - _reactNative.View, - props, - this.props.children - ) : _react2['default'].createElement(_reactNative.Image, props) - ); - } -}); -module.exports = exports['default']; \ No newline at end of file diff --git a/dist/create.js b/dist/create.js deleted file mode 100644 index 5ad62d8..0000000 --- a/dist/create.js +++ /dev/null @@ -1,20 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, '__esModule', { - value: true -}); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } - -var _curry = require('curry'); - -var _curry2 = _interopRequireDefault(_curry); - -function createGesture(responder, transducer, getInitialLayout, draggable) { - return draggable.onDragStart.flatMap(function () { - return responder(draggable.onDragMove, getInitialLayout).transduce(transducer).takeUntil(draggable.onDragRelease); - }); -}; - -exports['default'] = (0, _curry2['default'])(createGesture); -module.exports = exports['default']; \ No newline at end of file diff --git a/dist/drag.js b/dist/drag.js deleted file mode 100644 index ceda480..0000000 --- a/dist/drag.js +++ /dev/null @@ -1,27 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, '__esModule', { - value: true -}); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } - -var _transducersJs = require('transducers.js'); - -var _responderOneFinger = require('./responder/oneFinger'); - -var _responderOneFinger2 = _interopRequireDefault(_responderOneFinger); - -var responder = _responderOneFinger2['default']; - -exports.responder = responder; -var transducer = (0, _transducersJs.map)(function (gesture) { - var layout = gesture.get('initialLayout').set('rotate', 0); - var initialTouch = gesture.get('initialTouches').get(0); - var currentTouch = gesture.get('touches').get(0); - - return layout.withMutations(function (l) { - return l.set('x', l.get('x') + (currentTouch.get('pageX') - initialTouch.get('pageX'))).set('y', l.get('y') + (currentTouch.get('pageY') - initialTouch.get('pageY'))); - }).toJS(); -}); -exports.transducer = transducer; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 8c30a0d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,15 +0,0 @@ -'use strict'; - -module.exports = { - drag: require('./drag'), - pinch: require('./pinch'), - create: require('./create'), - draggable: require('./mixins/draggable'), - events: require('./mixins/events'), - GestureView: require('./GestureView'), - responders: { - general: require('./responder/general'), - oneFinger: require('./responder/oneFinger'), - twoFinger: require('./responder/twoFinger') - } -}; \ No newline at end of file diff --git a/dist/mixins/draggable.js b/dist/mixins/draggable.js deleted file mode 100644 index 869ff20..0000000 --- a/dist/mixins/draggable.js +++ /dev/null @@ -1,87 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, '__esModule', { - value: true -}); -exports['default'] = draggableMixin; - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } - -var _rx = require('rx'); - -var _rx2 = _interopRequireDefault(_rx); - -var _create = require('../create'); - -var _create2 = _interopRequireDefault(_create); - -var _reactNative = require('react-native'); - -function yes() { - return true; -} - -function draggableMixin(gestureDefs) { - gestureDefs = gestureDefs || []; - - var target; - var layout; - - var getInitialLayout = function getInitialLayout() { - return layout; - }; - var isCurrentTarget = function isCurrentTarget(ev) { - return ev.target === target; - }; - - return { - componentWillMount: function componentWillMount() { - var onDragStart = new _rx2['default'].Subject(); - var onDragMove = new _rx2['default'].Subject(); - var onDragRelease = new _rx2['default'].Subject(); - - this.onLayout.take(1).subscribe(function (ev) { - return target = ev.target; - }); - - this.onLayout.subscribe(function (ev) { - return layout = ev.layout; - }); - - var draggable = { - onDragStart: onDragStart.filter(isCurrentTarget), - onDragMove: onDragMove.filter(isCurrentTarget), - onDragRelease: onDragRelease.filter(isCurrentTarget) - }; - - this.gestureResponder = _reactNative.PanResponder.create({ - onStartShouldSetPanResponder: yes, - onStartShouldSetPanResponderCapture: yes, - onMoveShouldSetPanResponder: yes, - onMoveShouldSetPanResponderCapture: yes, - onPanResponderGrant: function onPanResponderGrant(evt) { - return onDragStart.onNext(evt.nativeEvent); - }, - onPanResponderMove: function onPanResponderMove(evt, gestureState) { - return onDragMove.onNext(evt.nativeEvent); - }, - onPanResponderTerminationRequest: yes, - onPanResponderRelease: function onPanResponderRelease(evt) { - return onDragRelease.onNext(evt.nativeEvent); - }, - onPanResponderTerminate: yes, - onShouldBlockNativeResponder: yes - }); - - if (this.props && this.props.gestures) { - gestureDefs = gestureDefs.concat(this.props.gestures); - } - - this.layoutStream = _rx2['default'].Observable.merge(gestureDefs.map(function (def) { - return (0, _create2['default'])(def.responder, def.transducer, getInitialLayout, draggable); - })); - } - }; -} - -module.exports = exports['default']; \ No newline at end of file diff --git a/dist/mixins/events.js b/dist/mixins/events.js deleted file mode 100644 index 5d818a2..0000000 --- a/dist/mixins/events.js +++ /dev/null @@ -1,36 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, '__esModule', { - value: true -}); -exports['default'] = events; - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } - -var _rx = require('rx'); - -var _rx2 = _interopRequireDefault(_rx); - -function events() { - var evs = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0]; - - return { - componentWillMount: function componentWillMount() { - var streams = evs.reduce(function (res, eventName) { - res[eventName] = new _rx2['default'].Subject(); - return res; - }, {}); - - Object.assign(this, streams, { __streams: streams }); - }, - componentWillUnmount: function componentWillUnmount() { - var _this = this; - - evs.forEach(function (ev) { - return _this.__streams[ev].onCompleted(); - }); - } - }; -} - -module.exports = exports['default']; \ No newline at end of file diff --git a/dist/pinch.js b/dist/pinch.js deleted file mode 100644 index 5487040..0000000 --- a/dist/pinch.js +++ /dev/null @@ -1,38 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, '__esModule', { - value: true -}); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } - -var _responderTwoFinger = require('./responder/twoFinger'); - -var _responderTwoFinger2 = _interopRequireDefault(_responderTwoFinger); - -var _transducersJs = require('transducers.js'); - -var responder = _responderTwoFinger2['default']; - -exports.responder = responder; -var transducer = (0, _transducersJs.map)(function (gesture) { - var layout = gesture.get('initialLayout'); - var startX = layout.get('x'); - var startY = layout.get('y'); - var startWidth = layout.get('width'); - var startHeight = layout.get('height'); - var newHeight = startHeight + gesture.get('increasedDistance'); - var scale = newHeight / startHeight; - var newWidth = startWidth * scale; - var xWidthDiff = (newWidth - startWidth) / 2; - var yHeightDiff = (newHeight - startHeight) / 2; - - return { - x: startX - gesture.getIn(['centerDiff', 'x']) - xWidthDiff, - y: startY - gesture.getIn(['centerDiff', 'y']) - yHeightDiff, - width: newWidth, - height: newHeight, - rotate: gesture.get('angleChanged') - }; -}); -exports.transducer = transducer; \ No newline at end of file diff --git a/dist/responder/general.js b/dist/responder/general.js deleted file mode 100644 index c110783..0000000 --- a/dist/responder/general.js +++ /dev/null @@ -1,86 +0,0 @@ -/** - * Here is the beggining of everything. All the other responders - * including one finger touch responder and two finger touch responder - * will use this responder as the basic responder, what the other - * responder will do is adding properties to the result which comes - * from this responder. - */ - -'use strict'; - -Object.defineProperty(exports, '__esModule', { - value: true -}); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } - -var _rx = require('rx'); - -var _rx2 = _interopRequireDefault(_rx); - -var _immutable = require('immutable'); - -var _immutable2 = _interopRequireDefault(_immutable); - -var _curry = require('curry'); - -var _curry2 = _interopRequireDefault(_curry); - -function toImmutableTouch(touch) { - return _immutable2['default'].Map({ - timestamp: touch.timestamp, - target: touch.target, - pageY: touch.pageY, - locationX: touch.locationX, - locationY: touch.locationY, - identifier: touch.identifier, - pageX: touch.pageX - }); -} - -function reset(s) { - return s['delete']('initialLayout')['delete']('initialTouches'); -} - -function genernalResponder(n, onMove, getInitialLayout) { - return _rx2['default'].Observable.create(function (o) { - var state = _immutable2['default'].Map(); - var paused = false; - - onMove.subscribe(function (event) { - if (!event.touches) { - return; - } - var touches = event.touches; - - if (touches.length === n) { - touches = touches.map(toImmutableTouch); - if (!state.get('initialLayout')) { - state = state.withMutations(function (s) { - return s.set('initialLayout', _immutable2['default'].fromJS(getInitialLayout())).set('initialTouches', _immutable2['default'].fromJS(touches)); - }); - } - - state = state.withMutations(function (s) { - return s.set('target', event.target).set('pageX', event.pageX).set('pageY', event.pageY).set('locationX', event.locationX).set('locationY', event.locationY).set('identifier', event.identifier).set('touches', _immutable2['default'].fromJS(touches)).set('timestamp', event.timestamp); - }); - - o.onNext(state); - } else { - if (paused) { - return; - } - - state = state.withMutations(reset); - paused = true; - } - }, o.onError.bind(o), o.onCompleted.bind(o)); - - return function () { - state = _immutable2['default'].Map(); - }; - }); -} - -exports['default'] = (0, _curry2['default'])(genernalResponder); -module.exports = exports['default']; \ No newline at end of file diff --git a/dist/responder/oneFinger.js b/dist/responder/oneFinger.js deleted file mode 100644 index abc6542..0000000 --- a/dist/responder/oneFinger.js +++ /dev/null @@ -1,18 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, '__esModule', { - value: true -}); -exports['default'] = oneFingerResponder; - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } - -var _general = require('./general'); - -var _general2 = _interopRequireDefault(_general); - -function oneFingerResponder(onMove, getInitialLayout) { - return (0, _general2['default'])(1, onMove, getInitialLayout); -} - -module.exports = exports['default']; \ No newline at end of file diff --git a/dist/responder/twoFinger.js b/dist/responder/twoFinger.js deleted file mode 100644 index 040df14..0000000 --- a/dist/responder/twoFinger.js +++ /dev/null @@ -1,90 +0,0 @@ -/** - * # Two finger responder - * - * This responder will be pretty simple, - * it extends the general event with few things: - * - * 1. initialCenter - the initial center point of the first touch - * 2. initialDistance - the initial distances of the first touch - * 3. currentCenter - the current center point of two touches - * 4. currentDistance - the current distance of two touches - * 5. increasedDistance - the increased distance from start - * 6. centerDiff - the different of the center point - */ - -'use strict'; - -Object.defineProperty(exports, '__esModule', { - value: true -}); -exports['default'] = twoFingerResponder; - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } - -var _immutable = require('immutable'); - -var _general = require('./general'); - -var _general2 = _interopRequireDefault(_general); - -function center(touches) { - var a = touches.get(0); - var b = touches.get(1); - - return (0, _immutable.Map)({ - x: (a.get('pageX') + b.get('pageX')) / 2, - y: (a.get('pageY') + b.get('pageY')) / 2 - }); -} - -function pow2abs(a, b) { - return Math.pow(Math.abs(a - b), 2); -} - -function distance(touches) { - var a = touches.get(0); - var b = touches.get(1); - - return Math.sqrt(pow2abs(a.get('pageX'), b.get('pageX')) + pow2abs(a.get('pageY'), b.get('pageY')), 2); -} - -function toDeg(rad) { - return rad * 180 / Math.PI; -} - -function angle(touches) { - var a = touches.get(0); - var b = touches.get(1); - - var deg = toDeg(Math.atan2(b.get('pageY') - a.get('pageY'), b.get('pageX') - a.get('pageX'))); - - if (deg < 0) { - deg += 360; - } - - return deg; -} - -function mutate(gesture) { - var initCenter = center(gesture.get('initialTouches')); - var currentCenter = center(gesture.get('touches')); - var initDistance = distance(gesture.get('initialTouches')); - var currentDistance = distance(gesture.get('touches')); - var initAngle = angle(gesture.get('initialTouches')); - var currentAngle = angle(gesture.get('touches')); - - return gesture.set('initialCenter', initCenter).set('initialDistance', initDistance).set('initialAngle', initAngle).set('currentCenter', currentCenter).set('currentDistance', currentDistance).set('currentAngle', currentAngle).set('angleChanged', currentAngle - initAngle).set('increasedDistance', currentDistance - initDistance).set('centerDiff', (0, _immutable.Map)({ - x: initCenter.get('x') - currentCenter.get('x'), - y: initCenter.get('y') - currentCenter.get('y') - })); -} - -function extend(gesture) { - return gesture.withMutations(mutate); -} - -function twoFingerResponder(onMove, getInitialLayout) { - return (0, _general2['default'])(2, onMove, getInitialLayout).map(extend); -} - -module.exports = exports['default']; \ No newline at end of file diff --git a/package.json b/package.json index acbafa6..a695218 100644 --- a/package.json +++ b/package.json @@ -2,11 +2,9 @@ "name": "react-native-gestures", "version": "0.2.0", "description": "composable gesture system in react native", - "main": "dist/index.js", + "main": "src/index.js", "scripts": { - "test": "standard src/*.js && mocha --compilers js:babel/register --recursive --require should", - "start": "node_modules/.bin/babel src --out-dir dist", - "watch": "node_modules/.bin/babel src --out-dir dist --watch" + "test": "standard src/*.js && mocha --compilers js:babel/register --recursive --require should" }, "repository": { "type": "git",