Skip to content

Instantly share code, notes, and snippets.

@tgoldenberg
Last active February 18, 2021 17:41
Show Gist options
  • Save tgoldenberg/5f9185111972d9d412cf to your computer and use it in GitHub Desktop.
Save tgoldenberg/5f9185111972d9d412cf to your computer and use it in GitHub Desktop.
Making a react native icon bounce
const React = require('react-native');
var Icon = require('react-native-vector-icons/FontAwesome');
let {
View,
Text,
Animated,
StyleSheet,
TextInput,
TouchableHighlight,
ScrollView,
AsyncStorage,
LayoutAnimation,
Image,
} = React;
class UserList extends React.Component{
constructor(props: any) {
super(props);
this.state = {
bounceValue: new Animated.Value(.8),
userIcon: ""
};
}
componentDidMount(){
Icon.getImageSource('rocket', 20).then((source) => this.setState({ userIcon: source }));
}
render(): ReactElement {
return (
<View style={{flex: 1, flexDirection: 'row'}}>
<Animated.Image
style={{
flex: 1,
width: 50,
height: 50
}}
source={this.state.userIcon}
/>
<TouchableHighlight onPress={() => {
this.bounce();
}}>
<Text>BOUNCE</Text>
</TouchableHighlight>
</View>
);
}
bounce(){
this.state.bounceValue.setValue(0.9);
Animated.spring(
this.state.bounceValue, {
toValue: 0.8,
friction: 2,
}
).start();
}
}
module.exports = UserList;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment