MoreView.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import React, {Component} from 'react';
  2. import Global from '../utils/Global';
  3. import Utils from '../utils/Utils';
  4. import ImagePicker from 'react-native-image-crop-picker';
  5. import {Dimensions, Image, PixelRatio, StyleSheet, Text, TouchableOpacity, View,} from 'react-native';
  6. const {width} = Dimensions.get('window');
  7. const icons = [
  8. require('../../images/ic_more_card.png'),
  9. require('../../images/ic_more_take_pic.png'),
  10. require('../../images/ic_more_recorder.png'),
  11. require('../../images/ic_more_position.png'),
  12. require('../../images/ic_more_movie.png'),
  13. require('../../images/ic_more_phone.png'),
  14. require('../../images/ic_more_gallery.png'),
  15. require('../../images/ic_more_collection.png'),
  16. ];
  17. const iconTexts = [
  18. "相册", "拍摄", "语音聊天", "位置",
  19. "红包", "语音输入", "名片", "我的收藏"
  20. ];
  21. export default class MoreView extends Component {
  22. render() {
  23. var page = [];
  24. for (var i = 0; i < 2; i++) {
  25. var row = [];
  26. for (var j = 0; j < 4; j++) {
  27. row.push(
  28. <Cell
  29. key={"row" + i + "col" + j}
  30. icon={icons[i * 4 + j]}
  31. text={iconTexts[i * 4 + j]}
  32. index={i * 4 + j}
  33. sendImageMessage={this.props.sendImageMessage}
  34. />
  35. );
  36. }
  37. page.push(
  38. <View key={"page" + i} style={styles.rowContainer}>{row}</View>
  39. );
  40. }
  41. return (
  42. <View style={styles.moreViewContainer}>
  43. {page}
  44. </View>
  45. );
  46. }
  47. }
  48. class Cell extends Component {
  49. render() {
  50. return (
  51. <TouchableOpacity style={styles.cellContainer} activeOpacity={0.6} onPress={() => this.handleClick()}>
  52. <View style={styles.cellContainer}>
  53. <View style={styles.cellImgContainer}>
  54. <Image style={styles.cellImage} source={this.props.icon}/>
  55. </View>
  56. <Text numberOfLines={1} style={styles.cellText}>{this.props.text}</Text>
  57. </View>
  58. </TouchableOpacity>
  59. );
  60. }
  61. handleClick() {
  62. let index = this.props.index;
  63. switch (index) {
  64. case 0:
  65. this.chooseImage();
  66. break;
  67. default:
  68. }
  69. }
  70. chooseImage() { // 从相册中选择图片发送
  71. ImagePicker.openPicker({
  72. cropping: false
  73. }).then(image => {
  74. if (this.props.sendImageMessage) {
  75. let path = image.path;
  76. if (!Utils.isEmpty(path)) {
  77. let name = path.substring(path.lastIndexOf('/') + 1, path.length);
  78. this.props.sendImageMessage(image);
  79. }
  80. }
  81. });
  82. }
  83. }
  84. const styles = StyleSheet.create({
  85. moreViewContainer: {
  86. width: width,
  87. height: Global.emojiViewHeight,
  88. flexDirection: 'column',
  89. paddingLeft: 15,
  90. paddingRight: 15,
  91. paddingTop: 10,
  92. paddingBottom: 10,
  93. backgroundColor: '#F4F4F4'
  94. },
  95. rowContainer: {
  96. flexDirection: 'row',
  97. flex: 1,
  98. alignItems: 'center',
  99. height: Global.emojiViewHeight / 2 - 20,
  100. },
  101. cellContainer: {
  102. flex: 1,
  103. flexDirection: 'column',
  104. justifyContent: 'center',
  105. alignItems: 'center',
  106. marginLeft: 10,
  107. marginRight: 10,
  108. },
  109. cellImgContainer: {
  110. width: 55,
  111. height: 55,
  112. justifyContent: 'center',
  113. alignItems: 'center',
  114. backgroundColor: '#FBFBFB',
  115. borderWidth: 1 / PixelRatio.get(),
  116. borderColor: '#DFDFDF',
  117. borderRadius: 10,
  118. },
  119. cellImage: {
  120. width: 35,
  121. height: 35,
  122. },
  123. cellText: {
  124. fontSize: 12,
  125. width: 55,
  126. textAlign: 'center'
  127. }
  128. });