Created
March 30, 2015 01:13
-
-
Save jgable/43391acf85ccdbf249bc to your computer and use it in GitHub Desktop.
TouchableHighlight Examples
This file contains hidden or 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
/** | |
* 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); |
eh... could u please tell how to hide the alert in the callback function?
@carl1990 me too
@carl1990 me too
@carl1990, @mrboli, @thEpisode it would be something like this:
React.createClass({
getInitialState: function () {
return { toggled: false };
},
handlePress: function() {
this.setState({ toggled: !this.state.toggled })
},
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.handlePress}>
<Text>Toggle</Text>
</TouchableHighlight>
{this.renderOther()}
</View>
);
},
renderOther: function () {
if (!this.state.toggled) {
return null;
}
return (
<TouchableHighlight onPress={this.handlePress} underlayColor="white">
<ExampleComponent />
</TouchableHighlight>
);
}
})
@ThiagoNP Thanks for this demos, help me a lot.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I want to know how to implement
handlePress
method