MessageList.js 1.66 KB
'use strict';

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


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 (
            <SingleImage
                data={rowData}
                messageResourceInfo={this.props.messageResourceInfo}
                resourceJumpWithUrl={this.props.resourceJumpWithUrl}
            />
        );
    }

    render() {
        let {messageResourceInfo} = this.props;

        let resourceList = messageResourceInfo.resourceList ? messageResourceInfo.resourceList.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,
    }
});