Skip to content

Instantly share code, notes, and snippets.

@kevinold
Forked from jgable/example1.ios.js
Created February 24, 2017 04:43
Show Gist options
  • Save kevinold/ff7ab146a2e4fea57be509ea2dee04ec to your computer and use it in GitHub Desktop.
Save kevinold/ff7ab146a2e4fea57be509ea2dee04ec to your computer and use it in GitHub Desktop.
TouchableHighlight Examples
/**
* Touchable Highlight example (that fires invariant as expected)
*/
'use strict';
var React = require('react-native');
var {
AppRegistry,
StyleSheet,
Text,
TouchableHighlight,
View,
} = React;
var ExampleComponent = React.createClass({
displayName: 'ExampleComponent',
render: function () {
return (
<View style={styles.container}>
<Text>Some Text 1</Text>
</View>
);
}
});
var AwesomeProject = React.createClass({
getInitialState: function () {
return { toggled: false };
},
render: function() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit index.ios.js{'\n'}
Press Cmd+R to reload
</Text>
<TouchableHighlight onPress={() => this.setState({ toggled: !this.state.toggled })}>
<Text>Toggle</Text>
</TouchableHighlight>
{this.renderOther()}
</View>
);
},
renderOther: function () {
if (!this.state.toggled) {
return null;
}
return (
<TouchableHighlight onPress={this.handlePress} underlayColor="white">
<ExampleComponent />
</TouchableHighlight>
);
}
});
var styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
},
});
AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment