Authored by 张丽霞

学生认证入口,review by 戴强

... ... @@ -8,6 +8,7 @@ import QRCode from './qrcode/QRCode';
import BrandStore from './brandStore/BrandStore';
import Classify from './classify/Classify';
import Seckill from './seckill/Seckill';
import StudentCertification from './studentCertification/StudentCertification';
// import Search from './search/Search';
export default function native(platform) {
... ... @@ -15,6 +16,7 @@ export default function native(platform) {
BrandStore(platform);
Classify(platform);
Seckill(platform);
StudentCertification(platform);
if (Platform.OS === 'ios') {
Community(platform);
... ...
'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 studentInitialState from './reducers/student/studentInitialState';
import StudentContainer from './containers/StudentContainer';
import {
setPlatform,
setChannel,
} from './reducers/app/appActions';
function getInitialState() {
const _initState = {
app: (new appInitialState()),
student: (new studentInitialState()),
};
return _initState;
}
export default function native(platform) {
let YH_Student = React.createClass({
render() {
const store = configureStore(getInitialState());
store.dispatch(setPlatform(platform));
return (
<Provider store={store}>
<StudentContainer />
</Provider>
);
}
});
AppRegistry.registerComponent('YH_Student', () => YH_Student);
}
let styles = StyleSheet.create({
});
... ...
import React, {Component} from 'react';
import ReactNative from 'react-native';
let { requireNativeComponent } = ReactNative;
// requireNativeComponent automatically resolves this to "YH_BannerViewManager"
module.exports = requireNativeComponent('YH_BannerView', null);
class BannerView extends React.Component {
constructor(props) {
super(props);
this._onSelectBanner = this._onSelectBanner.bind(this);
}
_onSelectBanner(event: Event) {
if (!this.props.onSelectBanner) {
return;
}
this.props.onSelectBanner(event.nativeEvent.url);
}
render() {
return <YH_BannerView {...this.props} onPress={this._onSelectBanner} />;
}
}
BannerView.propTypes = {
autoLooping: React.PropTypes.bool,
items: React.PropTypes.arrayOf(
React.PropTypes.shape({
src: React.PropTypes.string.isRequired,
url: React.PropTypes.string.isRequired,
})
),
onSelectBanner: React.PropTypes.func,
};
let YH_BannerView = requireNativeComponent('YH_BannerView', BannerView);
module.exports = BannerView;
... ...
'use strict'
import React, {Component} from 'react';
import {
View,
Text,
TouchableWithoutFeedback,
StyleSheet,
} from 'react-native';
export default class Button extends Component {
constructor(props) {
super(props);
this.state = {
helighted: false,
}
this._onPress = this._onPress.bind(this);
this._onPressIn = this._onPressIn.bind(this);
this._onPressOut = this._onPressOut.bind(this);
this._helightedTextStyle = this._helightedTextStyle.bind(this);
this._selectedTextStyle = this._selectedTextStyle.bind(this);
}
render() {
return (
<TouchableWithoutFeedback
onPress={()=>{this._onPress()}}
onPressIn={()=>{this._onPressIn()}}
onPressOut={()=>{this._onPressOut()}} >
<View style={this.props.containerStyle || styles.container} >
<Text style={[this._selectedTextStyle(), this._helightedTextStyle()]} >
{this.props.title}
</Text>
</View>
</TouchableWithoutFeedback>
);
}
_helightedTextStyle() {
if(this.state.helighted) {
if(this.props.helightedTitleStyle) {
return this.props.helightedTitleStyle;
}
if(this.props.selected) {
return this.props.normalTitleStyle || styles.titleNormal;
} else {
return this.props.selectedTitleStyle || styles.titleSelected;
}
} else {
return this._selectedTextStyle();
}
}
_selectedTextStyle() {
if(this.props.selected) {
return this.props.selectedTitleStyle || styles.titleSelected;
} else {
return this.props.normalTitleStyle || styles.titleNormal;
}
}
_onPressIn() {
this.setState({
helighted: !this.state.helighted,
});
}
_onPressOut() {
this.setState({
helighted: !this.state.helighted,
});
}
_onPress() {
if(!this.props.onPress) {
return;
}
this.props.onPress();
}
};
Button.propTypes = {
title: React.PropTypes.string,
selected: React.PropTypes.bool,
onPress: React.PropTypes.func,
selectedTitleStyle: React.PropTypes.any,
normalTitleStyle: React.PropTypes.any,
helightedTitleStyle: React.PropTypes.any,
containerStyle: React.PropTypes.any,
};
let styles = StyleSheet.create({
container: {
width: 44,
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
titleHelighted: {
color: 'black',
fontSize: 15,
},
titleNormal: {
color: '#b0b0b0',
fontSize: 15,
},
titleSelected: {
color: 'black',
fontSize: 15,
},
});
... ...
/*
* 潮流优选、明星原创
*/
'use strict';
import React, {Component} from 'react';
import ReactNative, {
View,
ScrollView,
Text,
NativeAppEventEmitter,
StyleSheet,
} from 'react-native';
export default class Student extends Component {
constructor(props) {
super(props);
}
componentDidMount() {
}
render() {
return (
<View style={styles.container}>
<Text>
student页面
</Text>
</View>
);
}
}
let styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#f0f0f0',
},
});
... ...
import keyMirror from 'key-mirror';
export default keyMirror({
SET_PLATFORM: null,
SET_CHANNEL: null,
});
... ...
'use strict'
import React, {Component} from 'react';
import ReactNative, {
StyleSheet,
Dimensions,
Platform,
View,
NativeModules,
InteractionManager,
NativeAppEventEmitter,
} from 'react-native'
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {Map} from 'immutable';
import * as studentActions from '../reducers/student/studentActions';
import Student from '../components/student/Student';
const actions = [
studentActions,
];
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 StudentContainer extends Component {
constructor(props) {
super(props);
}
render() {
let {student} = this.props;
return (
<View style={styles.container}>
<Student
/>
</View>
);
}
}
let styles = StyleSheet.create({
container: {
flex: 1,
},
});
export default connect(mapStateToProps, mapDispatchToProps)(StudentContainer);
... ...
'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
host: 'http://api.yoho.cn',
servicehost: 'http://service.yoho.cn',
});
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 student from './student/studentReducer';
const rootReducer = combineReducers({
app,
student,
});
export default rootReducer;
... ...
'use strict';
import ReactNative from 'react-native';
import StudentService from '../../services/StudentService';
const {
SET_PLATFORM,
} = require('../../constants/actionTypes').default;
export function setPlatform(platform) {
return {
type: SET_PLATFORM,
payload: platform,
};
}
... ...
'use strict';
import {Record, List, Map} from 'immutable';
let InitialState = Record({
platform: 'iOS',
});
export default InitialState;
... ...
'use strict';
import InitialState from './studentInitialState';
import Immutable, {Map} from 'immutable';
const {
SET_PLATFORM,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
export default function studentReducer(state=initialState, action) {
switch(action.type) {
case SET_PLATFORM: {
return state.set('platform', action.payload);
}
}
return state;
}
... ...
'use strict';
import Request from '../../common/services/Request';
export default class StudentService {
constructor () {
let baseURL = 'http://service.yoho.cn';
this.api = new Request(baseURL);
}
async fetchList(brand_type, options) {
return await this.api.get({
url: '/guang/api/v3/plustar/getlist',
body: {
brand_type,
...options,
}
})
.then((json) => {
return json;
})
.catch((error) => {
throw(error);
});
}
}
... ...
/**
* # 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);
};
... ...