App11Touchables.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import React from 'react';
  2. import {
  3. Alert,
  4. Button,
  5. Platform,
  6. StyleSheet,
  7. Text,
  8. TouchableHighlight,
  9. TouchableNativeFeedback,
  10. TouchableOpacity,
  11. TouchableWithoutFeedback,
  12. View,
  13. } from 'react-native';
  14. const styles = StyleSheet.create({
  15. container: {
  16. alignItems: 'center',
  17. paddingTop: 60,
  18. },
  19. button: {
  20. alignItems: 'center',
  21. backgroundColor: '#2196F3',
  22. marginBottom: 30,
  23. width: 260,
  24. },
  25. buttonText: {
  26. color: 'white',
  27. padding: 20,
  28. },
  29. });
  30. class Touchables extends React.Component {
  31. onPressButton() {
  32. Alert.alert('You pressed THE button');
  33. }
  34. onLongPressButton() {
  35. Alert.alert('You long-pressed the button');
  36. }
  37. render() {
  38. return (
  39. <View style={styles.container}>
  40. <TouchableHighlight onPress={this.onPressButton} underlayColor="white">
  41. <View style={styles.button}>
  42. <Text style={styles.buttonText}>TouchableHighlight</Text>
  43. </View>
  44. </TouchableHighlight>
  45. <TouchableOpacity onPress={this.onPressButton}>
  46. <View style={styles.button}>
  47. <Text style={styles.buttonText}>TouchableOpacity</Text>
  48. </View>
  49. </TouchableOpacity>
  50. <TouchableNativeFeedback onPress={this.onPressButton}
  51. background={Platform.OS === 'android' ? TouchableNativeFeedback.SelectableBackground() : ''}>
  52. <View style={styles.button}>
  53. <Text style={styles.buttonText}>TouchableNativeFeedback</Text>
  54. </View>
  55. </TouchableNativeFeedback>
  56. <TouchableWithoutFeedback onPress={this.onPressButton}>
  57. <View style={styles.button}>
  58. <Text style={styles.buttonText}>TouchableWithoutFeedback</Text>
  59. </View>
  60. </TouchableWithoutFeedback>
  61. <TouchableHighlight onPress={this.onPressButton} onLongPress={this.onLongPressButton}
  62. underlayColor="white">
  63. <View style={styles.button}>
  64. <Text style={styles.buttonText}>Touchable with Long Press</Text>
  65. </View>
  66. </TouchableHighlight>
  67. </View>
  68. );
  69. }
  70. }
  71. export default Touchables;