No Description

EmotionsChildView.js 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /**
  2. * Desc: EmotionsChildView
  3. *
  4. * Created by WangGanxin on 2018/1/31
  5. * Email: mail@wangganxin.me
  6. */
  7. import React, {Component,PureComponent} from 'react';
  8. import {
  9. View,
  10. Image,
  11. FlatList,
  12. StyleSheet,
  13. Dimensions,
  14. TouchableWithoutFeedback,
  15. } from 'react-native';
  16. import PropTypes from 'prop-types';
  17. import {EMOTIONS_DATA} from './DataSource';
  18. let {width} = Dimensions.get('window');
  19. let itemWidth = width / 7;
  20. export default class EmotionsChildView extends PureComponent {
  21. constructor(props){
  22. super(props);
  23. }
  24. _rednerItem=(item) => {
  25. if (item.item.value === '/{del'){
  26. return <TouchableWithoutFeedback onPress={() => this.props.onPress(item.item.value)}>
  27. <View key={item.item.key} style={styles.itemStyle}>
  28. <Image style={styles.deleteStyle} source={require('./emotions/ic_emoji_del.png')}/>
  29. </View>
  30. </TouchableWithoutFeedback>;
  31. }
  32. return <TouchableWithoutFeedback onPress={() => this.props.onPress(item.item.value)}>
  33. <View key={item.item.key} style={styles.itemStyle}>
  34. <Image style={styles.emojiStyle} source={EMOTIONS_DATA[item.item.value]}/>
  35. </View>
  36. </TouchableWithoutFeedback>;
  37. }
  38. render(){
  39. return (
  40. <FlatList
  41. style={[styles.wrapper,this.props.style]}
  42. horizontal={false}
  43. numColumns={7}
  44. refreshing={false}
  45. scrollEnabled={false}
  46. initialNumToRender={21}
  47. data={this.props.dataSource}
  48. renderItem={this._rednerItem}/>
  49. );
  50. }
  51. }
  52. EmotionsChildView.propTypes = {
  53. dataSource: PropTypes.array.isRequired,
  54. onPress:PropTypes.func,
  55. };
  56. EmotionsChildView.defaultProps = {
  57. dataSource:[],
  58. };
  59. const styles = StyleSheet.create({
  60. wrapper: {
  61. width:'100%',
  62. height:175,
  63. },
  64. itemStyle: {
  65. width:itemWidth,
  66. height:50,
  67. justifyContent:'center',
  68. alignItems:'center',
  69. },
  70. emojiStyle:{
  71. width:35,
  72. height:35,
  73. },
  74. deleteStyle:{
  75. width:35,
  76. height:24,
  77. }
  78. });