Created
April 6, 2016 15:21
-
-
Save moduscreate/d115bdc5db1ccd6252fffadfab8fec65 to your computer and use it in GitHub Desktop.
GiphyList transformed with Babel
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
| var GiphyList = function(_Component) { | |
| babelHelpers.inherits(GiphyList, _Component); | |
| function GiphyList() { | |
| var _Object$getPrototypeO; | |
| var _temp, _this, _ret; | |
| babelHelpers.classCallCheck(this, GiphyList); | |
| for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | |
| args[_key] = arguments[_key]; | |
| } | |
| return _ret = (_temp = (_this = babelHelpers.possibleConstructorReturn(this, (_Object$getPrototypeO = Object.getPrototypeOf(GiphyList)).call.apply(_Object$getPrototypeO, [this].concat(args))), _this), _this. | |
| state = { | |
| data: [], | |
| animatedIndex: -1 | |
| }, _this. | |
| onAfterLoad = function(data) { | |
| _this.setState({ | |
| data: data.data | |
| }); | |
| }, _this. | |
| onItemPress = function(index, data) { | |
| var state = _this.state; | |
| state.animatedIndex = index; | |
| _this.setState(state); | |
| }, _temp), babelHelpers.possibleConstructorReturn(_this, _ret); | |
| } | |
| babelHelpers.createClass(GiphyList, [{ | |
| key: 'componentWillMount', | |
| value: function componentWillMount() { | |
| fetch(url).then(function(r) { | |
| return r.json(); | |
| }).then(this.onAfterLoad).catch(function(e) { | |
| alert('Failure fetching data'); | |
| console.log(e); | |
| }); | |
| } | |
| }, { | |
| key: 'buildImages', | |
| value: function buildImages( | |
| data) { | |
| var animIdx = this.state.animatedIndex, | |
| images = [], | |
| length = data.length, | |
| i = 0, | |
| source = void 0, | |
| item = void 0; | |
| if (data.length == 0) { | |
| data.length = length = 10; | |
| } | |
| for (; i < length; i++) { | |
| item = data[i]; | |
| images.push( | |
| _reactNative2.default.createElement(TouchableImage, { | |
| data: item, | |
| key: 'img' + i, | |
| style: styles.touchable, | |
| index: i, | |
| animate: animIdx == i, | |
| onPress: this.onItemPress | |
| })); | |
| } | |
| return images; | |
| } | |
| }, { | |
| key: 'render', | |
| value: function render() | |
| { | |
| var state = this.state, | |
| data = state.data, | |
| images = this.buildImages(data); | |
| return ( | |
| _reactNative2.default.createElement(_reactNative.View, { | |
| style: this.props.style | |
| }, | |
| _reactNative2.default.createElement(_reactNative.ScrollView, { | |
| contentContainerStyle: styles.container, | |
| style: { | |
| backgroundColor: '#F5FCFF' | |
| } | |
| }, | |
| images), | |
| _reactNative2.default.createElement(_reactNative.View, { | |
| style: styles.topBar | |
| }))); | |
| } | |
| }]); | |
| return GiphyList; | |
| }(_reactNative.Component); | |
| module.exports = GiphyList; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment