Authored by 于良

Merge branch 'classify' of http://git.yoho.cn/mobile/YH_RNComponent into classify

... ... @@ -7,18 +7,21 @@ import Coupon from './coupon/Coupon';
import QRCode from './qrcode/QRCode';
import BrandStore from './brandStore/BrandStore';
import Classify from './classify/Classify';
import Seckill from './seckill/Seckill';
// import Search from './search/Search';
export default function native(platform) {
Coupon(platform);
BrandStore(platform);
Classify(platform);
Seckill(platform);
if (Platform.OS === 'ios') {
Community(platform);
Plustar(platform);
Coupon(platform);
Seckill(platform);
} else {
}
}
... ...
'use strict';
import React from 'react';
import ReactNative, {
AppRegistry,
Platform,
StyleSheet,
Dimensions,
TouchableOpacity,
} from 'react-native';
import {
Provider,
connect
} from 'react-redux';
import configureStore from './store/configureStore';
import {Record, List, Map} from 'immutable';
import appInitialState from './reducers/app/appInitialState';
import seckillInitialState from './reducers/seckill/seckillInitialState';
import SeckillContainer from './containers/SeckillContainer';
import {
setPlatform,
} from './reducers/app/appActions';
import {
setContentCode,
setHost,
} from './reducers/seckill/seckillActions';
function getInitialState() {
const _initState = {
app: (new appInitialState()),
seckill: (new seckillInitialState()),
};
return _initState;
}
export default function native(platform) {
let YH_Seckill = React.createClass({
render() {
const store = configureStore(getInitialState());
store.dispatch(setPlatform(platform));
if(this.props.contentCode){
store.dispatch(setContentCode(this.props.contentCode));
}
store.dispatch(setHost(this.props.host));
return (
<Provider store={store}>
<SeckillContainer />
</Provider>
);
}
});
AppRegistry.registerComponent('YH_Seckill', () => YH_Seckill);
}
let styles = StyleSheet.create({
});
... ...
'use strict';
import React, {Component} from 'react';
import ReactNative, {
View,
Text,
Image,
ListView,
StyleSheet,
Dimensions,
TouchableOpacity,
} from 'react-native';
export default class SeckillListView extends Component {
constructor(props) {
super(props);
}
render() {
return (
<View style={styles.container}>
<View style={styles.bottomToolBar}>
<TouchableOpacity
underlayColor={'transparent'}
onPress={() => {
ReactNative.NativeModules.YH_SeckillHelper.dissMissCallBack();
}}
>
<Image style={styles.closeScan} source={require('../../images/left_icon.png')}/>
</TouchableOpacity>
</View>
</View>
);
}
}
let styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'white',
},
bottomToolBar: {
top: 200,
height: 44,
backgroundColor: '#000',
},
closeScan: {
left: 10,
width: 25,
height: 25,
top: 10,
},
});
... ...
import keyMirror from 'key-mirror';
export default keyMirror({
SET_PLATFORM: null,
SET_HOST: null,
SET_CHANNEL: null,
SET_TYPE: null,
SECKILL_SET_REMIND: null,
SECKILL_CANCEL_REMIND: null,
});
... ...
'use strict'
import React, {Component} from 'react';
import {
StyleSheet,
Dimensions,
Platform,
View,
NativeModules,
} from 'react-native'
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {Map} from 'immutable';
import * as seckillActions from '../reducers/seckill/seckillActions';
import SeckillListView from '../components/seckill/SeckillListView';
const actions = [
seckillActions,
];
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 SeckillContainer extends Component {
constructor(props) {
super(props);
}
componentDidMount() {
}
render() {
return (
<SeckillListView
/>
);
}
}
let styles = StyleSheet.create({
container: {
flex: 1,
},
});
export default connect(mapStateToProps, mapDispatchToProps)(SeckillContainer);
... ...
'use strict';
import ReactNative from 'react-native';
const {
SET_PLATFORM,
SET_CHANNEL,
} = require('../../constants/actionTypes').default;
export function setPlatform(platform) {
return {
type: SET_PLATFORM,
payload: platform
};
}
export function setChannel(channel) {
return {
type: SET_CHANNEL,
payload: channel
};
}
... ...
'use strict';
import {Record, List, Map} from 'immutable';
let InitialState = Record({
platform: 'ios', // ios, android
channel: 1, // 1 - boy, 2 - girl, 3 - kid, 4 - lifestyle, 5 - yoho
});
export default InitialState;
... ...
'use strict';
import InitialState from './appInitialState';
const {
SET_PLATFORM,
SET_CHANNEL,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
export default function appReducer(state = initialState, action) {
if (!(state instanceof InitialState)) return initialState.merge(state);
switch (action.type) {
case SET_PLATFORM:
return state.set('platform', action.payload);
case SET_CHANNEL:
return state.set('channel', action.payload);
}
return state;
}
... ...
import {combineReducers} from 'redux';
import app from './app/appReducer';
import seckill from './seckill/seckillReducer';
const rootReducer = combineReducers({
app,
seckill,
});
export default rootReducer;
... ...
'use strict';
import ReactNative from 'react-native';
import SeckillService from '../../services/SeckillService';
const Platform = require('Platform');
const {
SET_HOST,
} = require('../../constants/actionTypes').default;
export function setHost(host) {
return {
type: SET_HOST,
payload: host
};
}
... ...
'use strict';
import {Record, List, Map} from 'immutable';
let InitialState = Record({
contentCode: 'b78b32ed81b18dde8ac84fd33602b88b',
host:'http://api.yoho.cn',
isFetching: false,
error: null,
floors: List(),
showSuccessTip: false,
showNetErrorTip: false,
});
export default InitialState;
... ...
'use strict';
import InitialState from './seckillInitialState';
import Immutable, {Map} from 'immutable';
const {
SET_HOST,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
export default function seckillReducer(state=initialState, action) {
switch(action.type) {
case SET_HOST:{
return state.set('host',action.payload);
}
}
return state;
}
... ...
'use strict';
import Request from '../../common/services/Request';
export default class SeckillService {
constructor (host) {
let baseURL = 'http://api.yoho.cn';
if(host){
baseURL = host;
}
this.api = new Request(baseURL);
}
}
... ...
/**
* # configureStore.js
*
* A Redux boilerplate setup
*
*/
'use strict';
/**
* ## Imports
*
* redux functions
*/
import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import createLogger from 'redux-logger';
/**
* ## Reducer
* The reducer contains the 4 reducers from
* device, global, auth, profile
*/
import reducer from '../reducers';
const logger = createLogger({
predicate: (getState, action) => process.env.NODE_ENV === `development`
});
/**
* ## creatStoreWithMiddleware
* Like the name...
*/
const createStoreWithMiddleware = applyMiddleware(
thunk,
logger
)(createStore);
/**
* ## configureStore
* @param {Object} the state with for keys:
* device, global, auth, profile
*
*/
export default function configureStore(initialState) {
return createStoreWithMiddleware(reducer, initialState);
};
... ...