ProductList.js 4.88 KB
'use strict';

import React from 'react';
import ReactNative, {
	AppRegistry,
	Platform,
	StyleSheet,
	Dimensions,
	TouchableOpacity,
} from 'react-native';
import createReactClass from 'create-react-class';

import {
	Provider,
	connect
} from 'react-redux';

import configureStore from './store/configureStore';
import {Record, List, Map} from 'immutable';

import appInitialState from './reducers/app/appInitialState';
import productListForBrandInitialState from './reducers/productListForBrand/productListForBrandInitialState';
import ProductListForBrandContainer from './containers/ProductListForBrandContainer';
import productListForShopInitialState from './reducers/productListForShop/productListForShopInitialState';
import ProductListForShopContainer from './containers/ProductListForShopContainer';
import ProductListPoolContainer from './containers/ProductListPoolContainer';
import ProductListPoolInitialState from './reducers/productListPool/productListPoolInitialState';
import CategoryProListInitialState from './reducers/categoryProList/categoryProListInitialState';

import screenInitialState from './reducers/screen/screenInitialState';
import screenCategoryInitialState from './reducers/screenCategory/screenCategoryInitialState';
import screenSubInitialState from './reducers/screenSub/screenSubInitialState';

import ScreenContainer from './containers/ScreenContainer';
import ScreenCategoryContainer from './containers/ScreenCategoryContainer';
import ScreenSubContainer from './containers/ScreenSubContainer';

import CategoryProductListContainer from './containers/CategoryProListContainer'


import {
	setPlatform,
	setChannel,
	setHost,
	setServiceHost,
	setType,
	setShop,
	setBrandId,
	setOriginParams,
	setSaleType,
	setActivityId,
	setBannerUrl,
	setListType
} from './reducers/app/appActions';

import {
	updateDataSource
} from './reducers/screenSub/screenSubActions';

import {
	updateCategoryDataSource
} from './reducers/screenCategory/screenCategoryActions';


function getInitialState() {
	const _initState = {
		app: (new appInitialState()),
    	productForBrand: (new productListForBrandInitialState()),
		screen: (new screenInitialState()),
		screenCategory: (new screenCategoryInitialState()),
		screenSub: (new screenSubInitialState()),
		productListForShop: (new productListForShopInitialState()),
		productListPool: (new ProductListPoolInitialState()),
		categoryProList: (new CategoryProListInitialState()),
	};
	return _initState;
}

export default function native(platform) {

	let YH_ProductListRNView = createReactClass({

		render() {
		  	const store = configureStore(getInitialState());
			store.dispatch(setPlatform(platform));

			let {
				host,
				serviceHost,
				channel,
				type,
				brand_id,
				shop_id,
				dictParams,
				saleType,
				activityId,
				filterSubMap,
				bannerUrl,
				listType,
			} = this.props;

			store.dispatch(setHost(host));
			store.dispatch(setServiceHost(serviceHost));
			store.dispatch(setChannel(channel));
			store.dispatch(setType(type));
			store.dispatch(setBrandId(brand_id));
			store.dispatch(setShop(shop_id));
			store.dispatch(setOriginParams(dictParams));
			store.dispatch(setSaleType(saleType));
			store.dispatch(setActivityId(activityId));
			store.dispatch(setBannerUrl(bannerUrl));
			store.dispatch(setListType(listType));

			if (type == 'YH_ScreenCategoryView' ) {
				return (
					<Provider store={store}>
						<ScreenContainer />
					</Provider>
				);
			} else if(type == 'YH_ProductFilterCategoryView' ){
				store.dispatch(updateCategoryDataSource(filterSubMap));
				return (
					<Provider store={store}>
						<ScreenCategoryContainer />
					</Provider>
				);
			} else if (type == 'YH_ProductFilterSubView' ){
				store.dispatch(updateDataSource(filterSubMap));
				return (
					<Provider store={store}>
						<ScreenSubContainer />
					</Provider>
				);
			} else if (type == 'YH_ProductListForBrandRNView' ){
				return (
					<Provider store={store}>
						<ProductListForBrandContainer />
					</Provider>
				);
			} else if (type == 'YH_ProductListForShopRNView' ){
				return (
					<Provider store={store}>
						<ProductListForShopContainer />
					</Provider>
				);
			} else if (type == 'YH_ProductListPoolView' ||
					   type == 'YH_VipProListVC' ||
					   type == 'YH_PromotionProductListVC' ||
					   type == 'YH_OutLetProListVC' ||
				   	   type == 'YH_InstalmentView' ||
				   	   type == 'YH_NewUserView' ||
					   type == 'YH_ActivityProListVC' ||
				   	   type == 'YH_LatestView' ||
					   type == 'YH_FilterProListVC'){
				return (
					<Provider store={store}>
						<ProductListPoolContainer />
					</Provider>
				);
			} else if (type == 'YH_CategoryProList') {
				return (
					<Provider store={store}>
						<CategoryProductListContainer />
					</Provider>
				);
			}

			return null;
		}
	});

	AppRegistry.registerComponent('YH_ProductListRNView', () => YH_ProductListRNView);
}

let styles = StyleSheet.create({

});