Skip to content

Instantly share code, notes, and snippets.

@kmagiera
Created March 15, 2016 10:31
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 kmagiera/bbfbac6c00077d188bc5 to your computer and use it in GitHub Desktop.
Save kmagiera/bbfbac6c00077d188bc5 to your computer and use it in GitHub Desktop.
/**
* @providesModule Playground
*/
'use strict';
var React = require('react-native');
var {
Animated,
StyleSheet,
Text,
View,
TouchableHighlight
} = React;
var FadeInView = React.createClass({
getInitialState: function() {
return {
fadeAnim: new Animated.Value(0),
}
},
componentDidMount: function() {
Animated.timing(
this.state.fadeAnim,
{
toValue: 1,
duration: 2000,
useNativeDriver: true,
},
).start();
},
render: function() {
return (
<Animated.View // Special animatable View
style={{
opacity: this.state.fadeAnim,
}}>
{this.props.children}
</Animated.View>
);
}
});
var Playground = React.createClass({
getInitialState: function() {
return {
show: true,
}
},
render: function() {
return (
<View>
<TouchableHighlight onPress={() => {
this.setState((state) => (
{show: !state.show}
));
}}>
<View style={styles.content}>
<Text>Press to {this.state.show ? 'Hide' : 'Show'}</Text>
</View>
</TouchableHighlight>
{this.state.show && <FadeInView>
<View style={styles.content}>
<Text>FadeInView</Text>
</View>
</FadeInView>}
</View>
);
}
});
var styles = StyleSheet.create({
content: {
backgroundColor: 'deepskyblue',
borderWidth: 1,
borderColor: 'dodgerblue',
padding: 20,
margin: 20,
borderRadius: 10,
alignItems: 'center',
},
});
module.exports = Playground;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment