SaleContainer.js 2.14 KB
'use strict'

import React, {Component} from 'react';
import ReactNative, {
    StyleSheet,
    Dimensions,
    Platform,
    View,
    Text,
    NativeModules,
    InteractionManager,
    NativeAppEventEmitter,
} from 'react-native'

import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {Map} from 'immutable';
import * as saleActions from '../reducers/sale/saleActions';

import Sale from '../components/sale/Sale';


const actions = [
    saleActions,
];

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 SaleContainer extends Component {
    constructor(props) {
        super(props);

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

        this.subscription = NativeAppEventEmitter.addListener(
            'ChannelDidChangeEvent',
            (reminder) => {
                this.home && this.home.trigggePullToRefresh();
            }
        );
    }

    componentDidMount() {
        
    }

    componentWillUnmount() {
        this.subscription && this.subscription.remove();
    }

    _onRefresh() {
        InteractionManager.runAfterInteractions(() => {
            
        });
    }

    _onEndReached() {
        InteractionManager.runAfterInteractions(() => {
            
        });
    }

    render() {
        let {sale} = this.props;
        return (
            <View style={styles.container}>
                <Sale
                    ref={(c) => {
                        this.sale = c;
                    }}
                    data={sale}
                    onRefresh={this._onRefresh}
                    onEndReached={this._onEndReached}
                />
            </View>
        );
    }
}

let styles = StyleSheet.create({
    container: {
        flex: 1,
    },

});

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