Skip to content

Instantly share code, notes, and snippets.

@moduscreate
Last active April 6, 2016 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moduscreate/edccc51a2c95ad73c6e33da512b6eb6c to your computer and use it in GitHub Desktop.
Save moduscreate/edccc51a2c95ad73c6e33da512b6eb6c to your computer and use it in GitHub Desktop.
GiphyList transformed with Babel
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