MessageList.js 1.6 KB
'use strict';

import React, {Component} from 'react';
import {Dimensions, ListView, StyleSheet, View} from 'react-native';
import {Immutable} from "immutable";
import MessageCell from './cell/MessageCell';


export default class MessageList extends Component {

    constructor(props) {
        super(props);
        this._renderRow = this._renderRow.bind(this);
        this.dataSource = new ListView.DataSource({
            rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
        });
    }

    _renderRow(rowData, sectionID, rowID) {
        return (
            <MessageCell
                data={rowData}
                resourceJumpWithUrl={this.props.resourceJumpWithUrl}
                shareAction={this.props.shareAction}
            />
        );
    }

    render() {
        let {messageList} = this.props;
        let resourceList = messageList.list ? messageList.list.toArray() : [];

        return (
            <View style={styles.container}>
                <ListView
                    ref={(c) => {
                        this.listView = c;
                    }}
                    contentContainerStyle={styles.contentContainer}
                    enableEmptySections={true}
                    dataSource={this.dataSource.cloneWithRows(resourceList)}
                    renderRow={this._renderRow}/>
            </View>
        );
    }
}

let {width} = Dimensions.get('window');

let styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: '#f0f0f0',
    },
    contentContainer: {
        width: width,
    }
});