BrandContainer.js 2.74 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 brandActions from '../reducers/brand/brandActions';

import Brand from '../components/brand/Brand';


const actions = [
    brandActions,
];

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

        this.onEndReached = this.onEndReached.bind(this);
        this.onPressProduct = this.onPressProduct.bind(this);
        this.onPressLike = this.onPressLike.bind(this);
        this.onPressHome = this.onPressHome.bind(this);
        this.onPromptHidden = this.onPromptHidden.bind(this);
    }

    componentDidMount() {
        this.props.actions.brandList();
        
    }

    componentWillUnmount() {
        
    }

    onEndReached() {
        this.props.actions.brandList();
    }

    onPressProduct(product) {
        let productSkn = product.get('product_skn', 0)
        if (!productSkn) {
          return;
        }

        let isGlobalProduct = product.get('is_global', 'N') == 'Y'; // 是否全球购商品
        let action = '';
        if (isGlobalProduct) {

        } else {
            action = 'go.productDetail';
        }

        let url = `http://m.yohobuy.com?openby:yohobuy={"action":"${action}","params":{"product_skn":"${productSkn}"}}`;
        ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
    }

    onPressLike(brand, index) {
        this.props.actions.favoriteOperation(index);  
    }

    onPressHome(brand) {
        if (!brand) {
            return;
        }

        ReactNative.NativeModules.YH_CommonHelper.pushBrandVC(brand);
    }

    onPromptHidden() {
        this.props.actions.hidePromt();
    }

    render() {
        let {
            brand,
        } = this.props;

        return (
            <Brand
                data={brand}
                onEndReached={this.onEndReached}
                onPressProduct={this.onPressProduct}
                onPressLike={this.onPressLike}
                onPressHome={this.onPressHome} 
                onPromptHidden={this.onPromptHidden}     
            />
        );
    }
}

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