Advertisement
zidniryi

Untitled

Jan 6th, 2020
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import {
  3. StyleSheet,
  4. Text,
  5. View,
  6. TouchableOpacity,
  7. Image,
  8. Alert,
  9. ScrollView,
  10. FlatList,
  11. Dimensions
  12. } from 'react-native';
  13.  
  14. var {height, width} = Dimensions.get('window');
  15.  
  16. export default class Menu extends Component {
  17.  
  18. constructor(props) {
  19. super(props);
  20. this.state = {
  21. data: [
  22. {id:1, title: "You", color:"#FF4500", image:"https://img.icons8.com/color/70/000000/name.png"},
  23. {id:2, title: "Home", color:"#87CEEB", image:"https://img.icons8.com/office/70/000000/home-page.png"},
  24. {id:3, title: "Love", color:"#4682B4", image:"https://img.icons8.com/color/70/000000/two-hearts.png"} ,
  25. {id:4, title: "Family", color:"#6A5ACD", image:"https://img.icons8.com/color/70/000000/family.png"} ,
  26. {id:5, title: "Friends", color:"#FF69B4", image:"https://img.icons8.com/color/70/000000/groups.png"} ,
  27. {id:6, title: "School", color:"#00BFFF", image:"https://img.icons8.com/color/70/000000/classroom.png"} ,
  28. {id:7, title: "Things", color:"#00FFFF", image:"https://img.icons8.com/dusk/70/000000/checklist.png"} ,
  29. {id:8, title: "World", color:"#20B2AA", image:"https://img.icons8.com/dusk/70/000000/globe-earth.png"} ,
  30. {id:9, title: "Remember", color:"#191970", image:"https://img.icons8.com/color/70/000000/to-do.png"} ,
  31. {id:10, title: "Game", color:"#008080", image:"https://img.icons8.com/color/70/000000/basketball.png"} ,
  32. ]
  33. };
  34. }
  35.  
  36. clickEventListener(item) {
  37. Alert.alert(item.title)
  38. }
  39.  
  40. render() {
  41. return (
  42. <View style={styles.container}>
  43. <FlatList style={styles.list}
  44. contentContainerStyle={styles.listContainer}
  45. data={this.state.data}
  46. horizontal={false}
  47. keyExtractor= {(item) => {
  48. return item.id;
  49. }}
  50. renderItem={({item}) => {
  51. return (
  52. <TouchableOpacity style={[styles.card, {backgroundColor:item.color}]} onPress={() => {this.clickEventListener(item)}}>
  53. <Image style={styles.cardImage} source={{uri:item.image}}/>
  54. <Text style={styles.title}>{item.title}</Text>
  55. </TouchableOpacity>
  56. )
  57. }}/>
  58. </View>
  59. );
  60. }
  61. }
  62.  
  63. const styles = StyleSheet.create({
  64. container:{
  65. flex:1,
  66. marginTop:20,
  67. },
  68. list: {
  69. //paddingHorizontal: 5,
  70. backgroundColor:"#E6E6E6",
  71. },
  72.  
  73. /******** card **************/
  74. card:{
  75. width: width,
  76. height:150,
  77. flexDirection:'row',
  78. padding:20,
  79.  
  80. justifyContent: 'center',
  81. alignItems: 'center'
  82. },
  83. cardImage:{
  84. height: 70,
  85. width: 70,
  86. },
  87. title:{
  88. fontSize:28,
  89. flex:1,
  90. color:"#FFFFFF",
  91. fontWeight:'bold',
  92. marginLeft:40
  93. },
  94. subTitle:{
  95. fontSize:12,
  96. flex:1,
  97. color:"#FFFFFF",
  98. },
  99. icon:{
  100. height: 20,
  101. width: 20,
  102. }
  103. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement