Skip to content

Commit 83f10e3

Browse files
committed
mobx/prettier => Login page
1 parent 82bf979 commit 83f10e3

File tree

10 files changed

+288
-16
lines changed

10 files changed

+288
-16
lines changed

.babelrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"presets": ["react-native"]
2+
"presets": ["react-native"],
3+
"plugins": ["transform-decorators-legacy"]
34
}

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
* [x] 热更新 code-push
44
* [x] carousel
55
* [x] redux 案例
6+
* [x] mobx 案例
67
* [x] react-navigation 案例
78
* [x] Android 硬更新
89
* [x] iOS 硬更新
9-
* [ ] native
10+
* [x] native 混合
1011

1112
### 项目架构
1213

index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
// import './App'
21
import './src';

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"dependencies": {
1111
"core-js": "^2.5.5",
1212
"immutable": "^3.8.2",
13+
"mobx": "^4.2.0",
14+
"mobx-react": "^5.0.0",
1315
"react": "16.3.1",
1416
"react-native": "0.55.3",
1517
"react-native-blur": "^3.2.2",
@@ -31,7 +33,9 @@
3133
},
3234
"devDependencies": {
3335
"babel-jest": "22.4.1",
36+
"babel-plugin-transform-decorators-legacy": "^1.3.4",
3437
"babel-preset-react-native": "4.0.0",
38+
"babel-preset-react-native-stage-0": "^1.0.1",
3539
"jest": "22.4.2",
3640
"prettier": "^1.12.1",
3741
"react-test-renderer": "16.2.0"

src/navigators/AppWithNavigation.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import React, { Component } from 'react';
22
import { StackNavigator, TabNavigator, TabBarBottom } from 'react-navigation';
33
import Ionicons from 'react-native-vector-icons/Ionicons';
44
import CardStackStyleInterpolator from 'react-navigation/src/views/CardStack/CardStackStyleInterpolator';
5-
import LoginScreen from '../page';
5+
import LoginScreen from '../page/Login';
6+
import RootScreen from '../page/Root';
67
import ModalScreen from '../components/ModalScreen';
78
import HomeScreen from '../page/home';
89
import TodoListScreen from '../page/home/containers/TodoList';
@@ -72,6 +73,9 @@ const MainStack = StackNavigator(
7273
LoginScreen: {
7374
screen: LoginScreen
7475
},
76+
RootScreen: {
77+
screen: RootScreen
78+
},
7579
HomeScreen: {
7680
screen: HomeScreen
7781
},

src/page/Login/index.js

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
import React, { Component } from 'react';
2+
import ReactNative from 'react-native';
3+
import { connect } from 'react-redux';
4+
import LinearGradient from 'react-native-linear-gradient';
5+
import InputAccessoryView from 'InputAccessoryView';
6+
import { NavigationActions } from 'react-navigation';
7+
const {
8+
Alert,
9+
AlertIOS,
10+
Image,
11+
View,
12+
Text,
13+
StyleSheet,
14+
StatusBar,
15+
ActivityIndicator,
16+
ScrollView,
17+
LayoutAnimation,
18+
TextInput,
19+
Button,
20+
TouchableOpacity
21+
} = ReactNative;
22+
type Props = {};
23+
type State = {};
24+
25+
class LoginScreen extends Component<Props, State> {
26+
state = { text: '' };
27+
get gradient() {
28+
return (
29+
<LinearGradient
30+
colors={['#04befe', '#4481eb']}
31+
startPoint={{ x: 1, y: 0 }}
32+
endPoint={{ x: 0, y: 1 }}
33+
style={{ ...StyleSheet.absoluteFillObject }}
34+
/>
35+
);
36+
}
37+
onChangeText = text => {
38+
console.log(text);
39+
};
40+
onLogin = () => {
41+
const resetAction = NavigationActions.reset({
42+
index: 0,
43+
actions: [NavigationActions.navigate({ routeName: 'RootScreen' })]
44+
});
45+
LayoutAnimation.linear();
46+
this.props.navigation.dispatch(resetAction);
47+
};
48+
render() {
49+
return (
50+
<View style={styles.container}>
51+
{this.gradient}
52+
<View style={styles.loginInputBox}>
53+
<TextInput
54+
{...inputOption}
55+
value={this.state.text}
56+
placeholder={'请输入用户名'}
57+
inputAccessoryViewID={inputAccessoryViewID}
58+
onChangeText={this.onChangeText}
59+
/>
60+
<TextInput
61+
{...inputOption}
62+
value={this.state.text}
63+
placeholder={'请输入密码'}
64+
inputAccessoryViewID={inputAccessoryViewID}
65+
onChangeText={this.onChangeText}
66+
/>
67+
<TouchableOpacity
68+
onPress={this.onLogin}
69+
activeOpacity={0.6}
70+
style={[styles.loginButton]}
71+
underlayColor={''}>
72+
<Text style={styles.buttonTitle}>登录</Text>
73+
</TouchableOpacity>
74+
</View>
75+
76+
<InputAccessoryView nativeID={inputAccessoryViewID} backgroundColor="#fffffff7">
77+
<View style={styles.textInputContainer}>
78+
<Button onPress={() => alert(1)} title="Send" />
79+
</View>
80+
</InputAccessoryView>
81+
</View>
82+
);
83+
}
84+
}
85+
const inputAccessoryViewID = 'inputAccessoryView1';
86+
87+
const styles = StyleSheet.create({
88+
container: {
89+
flex: 1
90+
},
91+
loginInputBox: {
92+
marginTop: 100,
93+
paddingHorizontal: 20
94+
},
95+
loginButton: {
96+
justifyContent: 'center',
97+
alignItems: 'center',
98+
width: '100%',
99+
height: 45,
100+
borderRadius: 25,
101+
backgroundColor: '#53B6F6',
102+
marginTop: 20
103+
},
104+
buttonTitle: {
105+
color: '#fff',
106+
fontSize: 17
107+
},
108+
textInputContainer: {
109+
flexDirection: 'row'
110+
},
111+
useridStyle: {
112+
height: 50,
113+
paddingLeft: 10,
114+
borderBottomWidth: StyleSheet.hairlineWidth,
115+
borderColor: 'rgba(255,255,255,.5)',
116+
borderRadius: 6,
117+
color: '#f1f1f1',
118+
fontSize: 16.5
119+
},
120+
text: {
121+
padding: 10,
122+
color: 'white'
123+
},
124+
textBubbleBackground: {
125+
backgroundColor: '#2f7bf6',
126+
borderRadius: 20,
127+
width: 110,
128+
margin: 20
129+
}
130+
});
131+
const inputOption = {
132+
style: styles.useridStyle,
133+
autoCapitalize: 'none',
134+
autoCorrect: false,
135+
underlineColorAndroid: 'transparent',
136+
keyboardAppearance: 'dark',
137+
placeholderTextColor: 'rgba(255,255,255,.7)'
138+
};
139+
LoginScreen.navigationOptions = () => ({ header: null });
140+
export default connect()(LoginScreen);

src/page/index.js renamed to src/page/Root.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const customAnimationConfig = {
3737
springDamping: 1
3838
}
3939
};
40-
class LoginScreen extends Component {
40+
class LoginScreenView extends Component {
4141
static navigationOptions = ({ navigation, navigationOptions }) => {
4242
return { header: null };
4343
// const { params } = navigation.state;
@@ -88,14 +88,14 @@ class LoginScreen extends Component {
8888
Alert.alert('温馨提示', '用户名或密码不能为空!');
8989
} else {
9090
this.refs.modal.open(); //loading 状态
91-
this.props.actions.login({ phone: this.state.phone, password: this.state.password }); //dispath 登陆
91+
/*this.props.actions.login({ phone: this.state.phone, password: this.state.password }); //dispath 登陆
9292
const resetAction = NavigationActions.reset({
9393
index: 0,
9494
actions: [NavigationActions.navigate({ routeName: 'NavigationBar' })]
9595
});
9696
LayoutAnimation.configureNext(customAnimationConfig);
9797
this.props.navigation.dispatch(resetAction);
98-
console.log(this.props);
98+
console.log(this.props);*/
9999
}
100100
};
101101
onCheckForUpdate = () => {
@@ -238,7 +238,7 @@ const mapDispatchToProps = (dispatch, ownProps) => {
238238
setDefaultTheme: () => dispatch({ type: 'DEFAULT_THEME' })
239239
};
240240
};
241-
export default connect(mapStateToProps, mapDispatchToProps)(LoginScreen);
241+
export default connect(mapStateToProps, mapDispatchToProps)(LoginScreenView);
242242

243243
// { deploymentKey: 'o1kLkW73Fosz7Wp3MWkWKHNoTbQG4ksvOXqog',
244244
// description: '1.优化操作流程',

src/page/main/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default class MainHomeScreen extends Component {
3232
index: 0,
3333
actions: [NavigationActions.navigate({ routeName: 'LoginScreen' })]
3434
});
35-
LayoutAnimation.configureNext(customAnimationConfig);
35+
LayoutAnimation.spring();
3636
this.props.navigation.dispatch(resetAction);
3737
};
3838
render() {

src/styles/SliderEntry.style.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ export default StyleSheet.create({
5454
borderTopLeftRadius: entryBorderRadius,
5555
borderTopRightRadius: entryBorderRadius
5656
},
57-
// image's border radius is buggy on iOS; let's hack it!
5857
radiusMask: {
5958
position: 'absolute',
6059
bottom: 0,

0 commit comments

Comments
 (0)