Skip to content

Commit 4cbcb3d

Browse files
committed
update
1 parent e26bc2a commit 4cbcb3d

File tree

10 files changed

+146
-89
lines changed

10 files changed

+146
-89
lines changed

ios/RnProject/AppDelegate.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
1919
NSURL *jsCodeLocation;
2020

2121
[[RCTBundleURLProvider sharedSettings] setDefaults];
22-
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
22+
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"/rn/app" fallbackResource:nil];
2323

2424
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
25-
moduleName:@"RnProject"
25+
moduleName:@"Demo"
2626
initialProperties:nil
2727
launchOptions:launchOptions];
2828
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

ios/RnProject/Base.lproj/LaunchScreen.xib

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="7702" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="10117" systemVersion="15G31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
33
<dependencies>
44
<deployment identifier="iOS"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7701"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
66
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
77
</dependencies>
88
<objects>

rn/app.js

+7-26
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,9 @@ import {
99
Text
1010
} from 'react-native';
1111

12-
import Route from './route';
13-
14-
let NavigatorBarMap = {
15-
LeftButton(route, navigator, index, navState) {
16-
return (<Text>Cancel</Text>);
17-
},
18-
RightButton(route, navigator, index, navState) {
19-
return (<Text>Done</Text>);
20-
},
21-
Title(route, navigator, index, navState) {
22-
return (<Text>Awesome Nav Bar</Text>);
23-
}
24-
};
12+
import Route from './base/route';
13+
import NavigationBarMap from './base/navigationBar';
14+
import goBack from './common/goBack';
2515

2616
class App extends React.Component {
2717

@@ -31,13 +21,7 @@ class App extends React.Component {
3121
this.navigator = null;
3222
//
3323
BackAndroid.addEventListener('hardwareBackPress', () => {
34-
// Alert.alert('alert', this.navigator + this.route.id);
35-
if (this.navigator && this.navigator.getCurrentRoutes().length > 1) {
36-
this.navigator.pop();
37-
return true;
38-
}
39-
BackAndroid.exitApp();
40-
return false;
24+
return goBack(this.navigator);
4125
});
4226
}
4327

@@ -65,14 +49,11 @@ class App extends React.Component {
6549
Navigator.SceneConfigs.FloatFromRight
6650
// Navigator.SceneConfigs.FadeAndroid
6751
}
52+
sceneStyle={{flex: 1, top: 40}}
6853
navigationBar={
69-
// <Navigator.NavigationBar
70-
// routeMapper={NavigatorBarMap}
71-
// style={{height: 80}}
72-
// />
7354
<Navigator.NavigationBar
74-
routeMapper={NavigatorBarMap}
75-
style={{backgroundColor: 'gray', flex: 1, height: 20}}
55+
routeMapper={NavigationBarMap}
56+
style={{backgroundColor: 'gray', marginTop: 0, height: 40, top: 0}}
7657
/>
7758
}
7859
/>

rn/base/navigationBar.js

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
'use strict';
2+
import React from 'react';
3+
import {
4+
View,
5+
TouchableOpacity,
6+
Text,
7+
StyleSheet,
8+
Dimensions,
9+
BackAndroid,
10+
Alert
11+
} from 'react-native';
12+
13+
import goBack from '../common/goBack';
14+
15+
// navigationBar 的固定left\title\right 布局好诡异,只能用算的了,flex 各种问题
16+
const screenWidth = Dimensions.get('window').width,
17+
btnWidth = 68;
18+
19+
const styles = StyleSheet.create({
20+
btn: {
21+
height: 30,
22+
// borderWidth: 1,
23+
top: 0,
24+
marginVertical: 5
25+
26+
},
27+
title: {
28+
flex: 1,
29+
width: screenWidth - 4 * 2 - btnWidth * 2,
30+
// borderWidth: 1,
31+
alignSelf: 'stretch',
32+
justifyContent: 'center'
33+
},
34+
text: {
35+
textAlign: 'center',
36+
fontSize: 16
37+
},
38+
fix: {
39+
marginTop: 17
40+
},
41+
btnText: {
42+
fontSize: 16,
43+
marginTop: 3
44+
}
45+
});
46+
47+
const NavigationBar = {
48+
49+
Title(route, navigator, index, navState) {
50+
return (
51+
<View style={[styles.title, styles.fix]}>
52+
<Text style={styles.text}>{route.id} + {index}</Text>
53+
</View>
54+
);
55+
},
56+
LeftButton(route, navigator, index, navState) {
57+
return (
58+
<TouchableOpacity style={[styles.btn]} onPress={() => {
59+
goBack(navigator);
60+
}}>
61+
<Text style={[styles.btnText, {textAlign: 'left'}]}>Back</Text>
62+
</TouchableOpacity>
63+
);
64+
},
65+
RightButton(route, navigator, index, navState) {
66+
return (
67+
<TouchableOpacity style={[styles.btn]} onPress={() => {
68+
Alert.alert('options', 'this is some operation.');
69+
}}>
70+
<Text style={[styles.btnText, {textAlign: 'right'}]}>选项</Text>
71+
</TouchableOpacity>
72+
);
73+
}
74+
}
75+
76+
export default NavigationBar;

rn/route.js rn/base/route.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
import React from 'react';
33

44
// 引入用到的所有模板
5-
import Homepage from './components/homepage';
6-
import Index from './components/index';
7-
import Detail from './components/detail';
8-
import Error from './components/error';
5+
import Homepage from '../components/homepage';
6+
import Index from '../components/index';
7+
import Detail from '../components/detail';
8+
import Error from '../components/error';
99

1010
/*
1111
* 路由配置项
12-
* 可配置默认参数 params ,配合 this.props 的限制可使代码更严谨
12+
* 可配置默认参数 props: params ,配合 this.props 的限制可使代码更严谨
1313
*/
1414
const RouteMap = {
1515
'homepage': {index: 0, component: Homepage, params: {}},
@@ -58,7 +58,7 @@ class Route {
5858
Object.assign(params, routeObj.params);
5959
} else {
6060
Component = Error;
61-
params = {};
61+
params = {message: '当前页面没有找到:' + id};
6262
}
6363
return <Component navigator={navigator} {...params} />;
6464
}

rn/common/goBack.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
import {
4+
BackAndroid
5+
} from 'react-native';
6+
7+
export default function (navigator) {
8+
if (navigator && navigator.getCurrentRoutes().length > 1) {
9+
navigator.pop();
10+
return true;
11+
}
12+
BackAndroid.exitApp();
13+
return false;
14+
}

rn/components/detail/index.js

+13-27
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
'use strict';
12
import React, {Component, PropTypes} from 'react';
23
import {
34
View,
4-
Text
5+
Text,
6+
TouchableOpacity
57
} from 'react-native';
68

79
class Detail extends Component {
@@ -10,32 +12,11 @@ class Detail extends Component {
1012

1113
}
1214

13-
componentWillMount() {
14-
15-
}
16-
17-
componentDidMount() {
18-
19-
}
20-
21-
componentWillReceiveProps(nextProps) {
22-
23-
}
24-
25-
shouldComponentUpdate(nextProps, nextState) {
26-
27-
}
28-
29-
componentWillUpdate(nextProps, nextState) {
30-
31-
}
32-
33-
componentDidUpdate(prevProps, prevState) {
34-
35-
}
36-
37-
componentWillUnmount() {
38-
15+
_gotoPage() {
16+
this.props.navigator.push({
17+
id: 'nopage',
18+
params: {}
19+
});
3920
}
4021

4122
render() {
@@ -45,6 +26,11 @@ class Detail extends Component {
4526
<Text>
4627
{new Date(this.props.ts).toLocaleDateString()}
4728
</Text>
29+
<TouchableOpacity onPress={this._gotoPage.bind(this)}>
30+
<Text>
31+
click this to a unretched page!
32+
</Text>
33+
</TouchableOpacity>
4834
</View>
4935
);
5036
}

rn/components/error/index.js

+20-19
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,54 @@
1+
'use strict';
12
import React, {Component, PropTypes} from 'react';
23
import {
34
View,
45
Text
56
} from 'react-native';
67

7-
class componentName extends Component {
8+
class Error extends Component {
89
constructor(props) {
910
super(props);
1011
}
1112

12-
componentWillMount() {
13+
// componentWillMount() {
1314

14-
}
15+
// }
1516

16-
componentDidMount() {
17+
// componentDidMount() {
1718

18-
}
19+
// }
1920

20-
componentWillReceiveProps(nextProps) {
21+
// componentWillReceiveProps(nextProps) {
2122

22-
}
23+
// }
2324

24-
shouldComponentUpdate(nextProps, nextState) {
25+
// shouldComponentUpdate(nextProps, nextState) {
2526

26-
}
27+
// }
2728

28-
componentWillUpdate(nextProps, nextState) {
29+
// componentWillUpdate(nextProps, nextState) {
2930

30-
}
31+
// }
3132

32-
componentDidUpdate(prevProps, prevState) {
33+
// componentDidUpdate(prevProps, prevState) {
3334

34-
}
35+
// }
3536

36-
componentWillUnmount() {
37+
// componentWillUnmount() {
3738

38-
}
39+
// }
3940

4041
render() {
4142
return (
4243
<View>
43-
<Text>页面没有找到...</Text>
44+
<Text>{this.props.message}</Text>
4445
</View>
4546
);
4647
}
4748
}
4849

49-
componentName.propTypes = {
50-
50+
Error.propTypes = {
51+
message: PropTypes.string.isRequired
5152
};
5253

53-
export default componentName;
54+
export default Error;

rn/components/homepage/index.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ import {
66
View,
77
Text,
88
ScrollView,
9-
TouchableOpacity,
10-
Dimensions
9+
TouchableOpacity
1110
} from 'react-native';
1211

1312
import List from './list';
1413

1514
const styles = StyleSheet.create({
1615
wrapper: {
17-
marginTop: 20,
1816
flex: 1,
1917
backgroundColor: 'red'
2018
},
@@ -58,7 +56,7 @@ class Homepage extends React.Component {
5856
{
5957
['1','2','3'].map((value, index) => {
6058
return (
61-
<List key={value} cont={value} navigator={this.props.navigator}/>
59+
<List key={value} num={value} navigator={this.props.navigator}/>
6260
);
6361
})
6462
}

rn/components/homepage/list.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
'use strict';
12
import React, {Component, PropTypes} from 'react';
23
import {
34
View,
@@ -27,7 +28,7 @@ class List extends Component {
2728
_gotoIndex () {
2829
this.props.navigator.push({
2930
id: 'index',
30-
params: {desc: 'this is indexpage from ' + this.props.cont + '!'}
31+
params: {desc: 'this is indexpage from ' + this.props.num + '!'}
3132
});
3233
}
3334

@@ -36,7 +37,7 @@ class List extends Component {
3637
<View style={styles.page}>
3738
<TouchableOpacity onPress={this._gotoIndex.bind(this)}>
3839
<Text>
39-
This is page : {this.props.cont}
40+
This is page : {this.props.num}
4041
</Text>
4142
</TouchableOpacity>
4243
</View>
@@ -45,7 +46,7 @@ class List extends Component {
4546
}
4647

4748
List.propTypes = {
48-
cont: PropTypes.string.isRequired
49+
num: PropTypes.string.isRequired
4950
}
5051

5152
export default List;

0 commit comments

Comments
 (0)