SystemMessageContainer.js 2.69 KB
'use strict';

import React from 'react';
import ReactNative from 'react-native';
import Immutable, {Map} from 'immutable';


import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';

import SystemMessage from '../components/message/SystemMessage';
import * as messageActions from '../reducers/message/messageActions';

const {
    Text,
    View,
    StyleSheet,
    Dimensions,
    Platform,
    InteractionManager,
} = ReactNative;

const actions = [
    messageActions,
];

function mapStateToProps(state) {
    return {
        ...state
    };
}

function mapDispatchToProps(dispatch) {
    const creators = Map()
        .merge(...actions)
        .filter(value => typeof value === 'function')
        .toObject();

    return {
        actions: bindActionCreators(creators, dispatch),
        dispatch
    }
}

class SystemMessageContainer extends React.Component {
    constructor(props) {
        super(props);

        this._onPressSection = this._onPressSection.bind(this);
        this._onRefresh = this._onRefresh.bind(this);
        this._onEndReached = this._onEndReached.bind(this);
    }

    componentDidMount() {
        this._onEndReached();
    }


    _onPressSection(id) {
        console.log('_onPressSection  id =' + id);
        // this.props.actions.goToPost(id);
    }


    _onRefresh() {
        // console.log('_onRefresh  id =' + id);
        InteractionManager.runAfterInteractions(() => {
            this.props.actions.systemMessage(true);
        });
    }

    _onEndReached() {
        InteractionManager.runAfterInteractions(() => {
            this.props.actions.systemMessage(false);
        });
    }

    render() {

        let {system} = this.props.message;
        let {ptr, isFetching, list, endReached} = system;
        let isRefreshing = ptr;
        let isLoadingMore = isFetching;

        return (
            <View style={styles.container}>
                <SystemMessage
                    list={list}
                    isFetching={isFetching}
                    ptr={ptr}
                    endReached={endReached}
                    isRefreshing={isRefreshing}
                    isLoadingMore={isLoadingMore}
                    onRefresh={this._onRefresh}
                    onPressSection={this._onPressSection}
                    onEndReached={this._onEndReached}
                />
            </View>
        );
    }
}


let {width, height} = Dimensions.get('window');
let navbarHeight = (Platform.OS === 'android') ? 50 : 64;

let styles = StyleSheet.create({
    container: {
        // top: 0,
        height: height,
        backgroundColor: 'transparent'
    },

});


export default connect(mapStateToProps, mapDispatchToProps)(SystemMessageContainer);