NewFriendsScreen.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import React, {Component} from 'react';
  2. import CommonTitleBar from '../views/CommonTitleBar';
  3. import {Button, Dimensions, FlatList, Image, PixelRatio, StyleSheet, Text, TextInput, View} from 'react-native';
  4. const {width} = Dimensions.get('window');
  5. export default class NewFriendsScreen extends Component {
  6. render() {
  7. let listData = [];
  8. for (let i = 0; i < 30; i++) {
  9. listData.push({
  10. key: i,
  11. title: '王大锤',
  12. subtitle: '我是王大锤',
  13. state: i % 2 == 0 ? 1 : (i % 3 == 0 ? 2 : 3)
  14. })
  15. }
  16. return (
  17. <View style={{flex: 1, flexDirection: 'column'}}>
  18. <CommonTitleBar nav={this.props.navigation} title={"新的朋友"}/>
  19. <View style={styles.searchView}>
  20. <View style={styles.searchEditText}>
  21. <Image style={styles.searchImg} source={require('../../images/ic_search_gray.png')}/>
  22. <TextInput style={styles.searchInput} underlineColorAndroid="transparent" placeholder="微信号/QQ号/手机号"/>
  23. </View>
  24. <View style={styles.searchLine}></View>
  25. </View>
  26. <Text style={styles.newFriendTag}>新的朋友</Text>
  27. <View style={styles.listContainer}>
  28. <FlatList
  29. data={listData}
  30. renderItem={this.renderItem}
  31. />
  32. </View>
  33. </View>
  34. );
  35. }
  36. renderItem = (item) => {
  37. console.log(item)
  38. return (
  39. <View key={"list-item-" + item.item.key} style={listItem.container}>
  40. <Image style={listItem.avatar} source={require('../../images/avatar.png')}/>
  41. <View style={listItem.titleContainer}>
  42. <Text style={listItem.title}>{item.item.title}</Text>
  43. <Text style={listItem.subtitle}>{item.item.subtitle}</Text>
  44. </View>
  45. <View style={listItem.btnContainer}>
  46. {
  47. item.item.state == 1 ? (
  48. <Button title="接受" color="#19AD17" onPress={() => {
  49. }}/>
  50. ) : (
  51. <Text>已添加</Text>
  52. )
  53. }
  54. </View>
  55. </View>
  56. );
  57. }
  58. }
  59. const listItem = StyleSheet.create({
  60. container: {
  61. flex: 1,
  62. width: width,
  63. flexDirection: 'row',
  64. padding: 10,
  65. alignItems: 'center',
  66. backgroundColor: '#FFFFFF',
  67. marginBottom: 1 / PixelRatio.get()
  68. },
  69. avatar: {
  70. width: 45,
  71. height: 45,
  72. marginLeft: 10,
  73. marginRight: 10,
  74. },
  75. titleContainer: {
  76. flexDirection: 'column',
  77. },
  78. title: {
  79. fontSize: 16
  80. },
  81. subtitle: {
  82. fontSize: 13
  83. },
  84. btnContainer: {
  85. flex: 1,
  86. flexDirection: 'row',
  87. justifyContent: 'flex-end'
  88. }
  89. });
  90. const styles = StyleSheet.create({
  91. searchView: {
  92. flexDirection: 'column',
  93. backgroundColor: '#FFFFFF',
  94. paddingLeft: 20,
  95. paddingRight: 20,
  96. paddingTop: 5,
  97. paddingBottom: 5,
  98. marginTop: 20,
  99. marginBottom: 20,
  100. },
  101. searchEditText: {
  102. flexDirection: 'row',
  103. alignItems: 'center',
  104. },
  105. searchImg: {
  106. width: 20,
  107. height: 20,
  108. marginLeft: 15,
  109. },
  110. searchInput: {
  111. flex: 1,
  112. fontSize: 15
  113. },
  114. searchLine: {
  115. height: 1,
  116. backgroundColor: '#ECECEC'
  117. },
  118. newFriendTag: {
  119. fontSize: 13,
  120. color: '#8A8A8A',
  121. marginLeft: 10,
  122. marginBottom: 5,
  123. },
  124. listContainer: {
  125. flex: 1,
  126. flexDirection: 'column',
  127. justifyContent: 'center',
  128. alignItems: 'center',
  129. }
  130. })