Last active
February 18, 2021 17:41
-
-
Save tgoldenberg/5f9185111972d9d412cf to your computer and use it in GitHub Desktop.
Making a react native icon bounce
This file contains 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
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