Skip to content

Instantly share code, notes, and snippets.

@b1acKr0se
Created May 16, 2019 05:00
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 b1acKr0se/88af0467fda3bfd80e0311ea39cb5eef to your computer and use it in GitHub Desktop.
Save b1acKr0se/88af0467fda3bfd80e0311ea39cb5eef to your computer and use it in GitHub Desktop.
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow
*/
import React, { Component } from "react";
import { View, Image, TouchableOpacity } from "react-native";
const snap = require("./thanos_snap.png");
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
currentIndex: 0,
isAnimating: false
};
}
thanosSnap = () => {
if (!this.state.isAnimating) {
const that = this;
that.setState({ isAnimating: true });
let x = 0;
const id = setInterval(() => {
if (++x == 48) {
window.clearInterval(id);
that.setState({ isAnimating: false, currentIndex: 0 });
} else {
that.setState({ currentIndex: x });
}
}, 40);
}
};
render() {
return (
<View style={styles.container}>
<TouchableOpacity onPress={this.thanosSnap}>
<View style={{ width: 80, height: 80, overflow: "hidden" }}>
<Image
source={snap}
style={{
width: 3840,
height: 80,
transform: [
{ translateX: this.state.currentIndex * -80 }
]
}}
/>
</View>
</TouchableOpacity>
</View>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment