|
| 1 | +import React, { Component } from 'react'; |
| 2 | +import styles from './MessageListStyle.js'; |
| 3 | + |
| 4 | +import Avatar from '../Avatar/Avatar'; |
| 5 | +import MessageBox from '../MessageBox/MessageBox'; |
| 6 | + |
| 7 | +import { |
| 8 | + ScrollView, |
| 9 | +} from 'react-native'; |
| 10 | + |
| 11 | +export class MessageList extends Component { |
| 12 | + |
| 13 | + constructor(props) { |
| 14 | + super(props); |
| 15 | + } |
| 16 | + |
| 17 | + onOpen(item, i, e) { |
| 18 | + if (this.props.onOpen instanceof Function) |
| 19 | + this.props.onOpen(item, i, e); |
| 20 | + } |
| 21 | + |
| 22 | + onDownload(item, i, e) { |
| 23 | + if (this.props.onDownload instanceof Function) |
| 24 | + this.props.onDownload(item, i, e); |
| 25 | + } |
| 26 | + |
| 27 | + onPress(item, i, e) { |
| 28 | + if (this.props.onPress instanceof Function) |
| 29 | + this.props.onPress(item, i, e); |
| 30 | + } |
| 31 | + |
| 32 | + onTitlePress(item, i, e) { |
| 33 | + if (this.props.onTitlePress instanceof Function) |
| 34 | + this.props.onTitlePress(item, i, e); |
| 35 | + } |
| 36 | + |
| 37 | + onForwardPress(item, i, e) { |
| 38 | + if (this.props.onForwardPress instanceof Function) |
| 39 | + this.props.onForwardPress(item, i, e); |
| 40 | + } |
| 41 | + |
| 42 | + loadRef(ref) { |
| 43 | + this.mlistRef = ref; |
| 44 | + if (this.props.cmpRef instanceof Function) |
| 45 | + this.props.cmpRef(ref); |
| 46 | + } |
| 47 | + |
| 48 | + render() { |
| 49 | + return ( |
| 50 | + <ScrollView |
| 51 | + ref={this.loadRef.bind(this)} |
| 52 | + style={styles.rceContainerMlist}> |
| 53 | + { |
| 54 | + this.props.dataSource.map((x, i) => ( |
| 55 | + <MessageBox |
| 56 | + key={i} |
| 57 | + {...x} |
| 58 | + onOpen={this.props.onOpen && ((e) => this.onOpen(x, i, e))} |
| 59 | + onDownload={this.props.onDownload && ((e) => this.onDownload(x, i, e))} |
| 60 | + onTitlePress={this.props.onDownload && ((e) => this.onTitlePress(x, i, e))} |
| 61 | + onForwardPress={this.props.onForwardPress && ((e) => this.onForwardPress(x, i, e))} |
| 62 | + onPress={this.props.onPress && ((e) => this.onPress(x, i, e))}/> |
| 63 | + )) |
| 64 | + } |
| 65 | + </ScrollView> |
| 66 | + ); |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | + |
| 71 | +MessageList.defaultProps = { |
| 72 | + onPress: null, |
| 73 | + onTitlePress: null, |
| 74 | + onForwardPress: null, |
| 75 | + onOpen: null, |
| 76 | + onDownload: null, |
| 77 | + dataSource: [], |
| 78 | + lockable: false, |
| 79 | + toBottomHeight: 300, |
| 80 | +}; |
| 81 | + |
| 82 | +export default MessageList; |
0 commit comments