1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
8 |
|
9 | var _react = require('react');
|
10 |
|
11 | var _react2 = _interopRequireDefault(_react);
|
12 |
|
13 | var _ZyngaScroller = require('./ZyngaScroller');
|
14 |
|
15 | var _ZyngaScroller2 = _interopRequireDefault(_ZyngaScroller);
|
16 |
|
17 | var _TouchableArea = require('./TouchableArea');
|
18 |
|
19 | var _TouchableArea2 = _interopRequireDefault(_TouchableArea);
|
20 |
|
21 | var _propTypes = require('prop-types');
|
22 |
|
23 | var _propTypes2 = _interopRequireDefault(_propTypes);
|
24 |
|
25 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
26 |
|
27 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
28 |
|
29 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
30 |
|
31 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
32 |
|
33 | var TouchWrapper = function (_React$Component) {
|
34 | _inherits(TouchWrapper, _React$Component);
|
35 |
|
36 | function TouchWrapper(props) {
|
37 | _classCallCheck(this, TouchWrapper);
|
38 |
|
39 | var _this = _possibleConstructorReturn(this, (TouchWrapper.__proto__ || Object.getPrototypeOf(TouchWrapper)).call(this, props));
|
40 |
|
41 | _this.state = {
|
42 | left: 0,
|
43 | top: 0,
|
44 | initialized: false
|
45 | };
|
46 |
|
47 | _this.onScroll = function (scrollLeft, scrollTop) {
|
48 | if (_this.state.initialized) {
|
49 | _this.props.onScroll(scrollLeft, scrollTop);
|
50 | } else {
|
51 | _this.setState({
|
52 | initialized: true
|
53 | });
|
54 | }
|
55 | };
|
56 |
|
57 | return _this;
|
58 | }
|
59 |
|
60 | _createClass(TouchWrapper, [{
|
61 | key: 'componentDidMount',
|
62 | value: function componentDidMount() {
|
63 | this.scroller = new _ZyngaScroller2.default(this.onScroll);
|
64 | this.scroller.setDimensions(this.props.tableWidth, this.props.tableHeight, this.props.contentWidth, this.props.contentHeight);
|
65 | }
|
66 | }, {
|
67 | key: 'componentWillReceiveProps',
|
68 | value: function componentWillReceiveProps(nextProps) {
|
69 | var diffTableWidth = nextProps.tableWidth !== this.props.tableWidth;
|
70 | var diffTableHeight = nextProps.tableHeight !== this.props.tableHeight;
|
71 | var diffContentWidth = nextProps.contentWidth !== this.props.contentWidth;
|
72 | var diffContentHeight = nextProps.contentHeight !== this.props.contentHeight;
|
73 |
|
74 | if (this.scroller && (diffTableWidth || diffTableHeight || diffContentWidth || diffContentHeight)) {
|
75 | this.scroller.setDimensions(nextProps.tableWidth, nextProps.tableHeight, nextProps.contentWidth, nextProps.contentHeight);
|
76 | }
|
77 | }
|
78 | }, {
|
79 | key: 'render',
|
80 | value: function render() {
|
81 | return _react2.default.createElement(
|
82 | _TouchableArea2.default,
|
83 | { scroller: this.scroller },
|
84 | this.props.children
|
85 | );
|
86 | }
|
87 | }]);
|
88 |
|
89 | return TouchWrapper;
|
90 | }(_react2.default.Component);
|
91 |
|
92 | TouchWrapper.propTypes = {
|
93 | tableWidth: _propTypes2.default.number.isRequired,
|
94 | tableHeight: _propTypes2.default.number.isRequired,
|
95 | contentWidth: _propTypes2.default.number,
|
96 | contentHeight: _propTypes2.default.number,
|
97 | onScroll: _propTypes2.default.func.isRequired,
|
98 | children: _propTypes2.default.any
|
99 | };
|
100 | exports.default = TouchWrapper; |
\ | No newline at end of file |