Skip to content

Commit 1086fc2

Browse files
committed
返回按钮改为箭头、标题居中
1 parent 8cc3cca commit 1086fc2

File tree

7 files changed

+88
-2
lines changed

7 files changed

+88
-2
lines changed

MainPage.js

+10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
import TabNavigator from 'react-native-tab-navigator';
1313
import TabPage1 from './TabPage1.js'
1414
import TabPage2 from './TabPage2.js'
15+
import TabPage3 from './TabPage3.js'
1516

1617
class MainPage extends Component {
1718
constructor(props) {
@@ -49,6 +50,15 @@ class MainPage extends Component {
4950
onPress={() => this.setState({ selectedTab: 'tab2' })}>
5051
<TabPage2 routerCallback={this.jumpPage} />
5152
</TabNavigator.Item>
53+
54+
<TabNavigator.Item
55+
selected={this.state.selectedTab === 'tab3'}
56+
title="Tab3"
57+
renderIcon={() => <Image source={require('./res/icon_bottomtag_home_n.png')} style={styles.tabImage} />}
58+
renderSelectedIcon={() => <Image source={require('./res/icon_bottomtag_home_s.png')} style={styles.tabImage} />}
59+
onPress={() => this.setState({ selectedTab: 'tab3' })}>
60+
<TabPage3 routerCallback={this.jumpPage} />
61+
</TabNavigator.Item>
5262
</TabNavigator>
5363
</View>
5464
);

TabPage3.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Sample React Native App
3+
* https://github.com/facebook/react-native
4+
* @flow
5+
*/
6+
// 'use strict';
7+
import React, { Component } from 'react';
8+
import {
9+
View,
10+
Text,
11+
StyleSheet
12+
} from 'react-native';
13+
14+
import SecondPage from './SecondPage.js'
15+
16+
class TestPage3 extends Component {
17+
constructor(props) {
18+
super(props);
19+
this.toRoute = this.toRoute.bind(this);
20+
}
21+
22+
toRoute(){
23+
var r = {name: 'From TabPage3',
24+
component: SecondPage};
25+
this.props.routerCallback('toRoute',r);
26+
}
27+
28+
render() {
29+
return (
30+
<View style={{flex: 1}}>
31+
32+
<Text style={styles.textStyle} onPress={this.toRoute}> Tab 页面 3</Text>
33+
34+
</View>
35+
);
36+
}
37+
};
38+
39+
var styles = StyleSheet.create({
40+
textStyle:{
41+
backgroundColor:'#eee',
42+
color:'#000',
43+
fontSize:30,
44+
marginTop:30,
45+
},
46+
});
47+
48+
export default TestPage3;

components/icons/NavBackButton.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from "react";
2+
import { StyleSheet, Image } from 'react-native';
3+
4+
export default class NavBackButton extends React.Component {
5+
render() {
6+
return (
7+
<Image source={require('../../res/icon_nav_back.png')} style={styles.backButton} />
8+
);
9+
}
10+
}
11+
12+
const styles = StyleSheet.create({
13+
backButton: {
14+
width: 10,
15+
height: 17,
16+
marginLeft: 10,
17+
marginTop: 3,
18+
marginRight: 10,
19+
},
20+
});

index.android.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66

77
import Router from 'react-native-simple-router';
88
import MainPage from './MainPage';
9+
import NavBackButton from './components/icons/NavBackButton.js'
910

1011
// 声明第一个页面
1112
const firstRoute = {
@@ -19,18 +20,25 @@ class ReactNativeCodeSnippet extends Component {
1920
<Router
2021
firstRoute={firstRoute}
2122
handleBackAndroid
22-
headerStyle={styles.header}
23+
headerStyle={styles.navHeader}
24+
titleStyle={styles.navTitle} // 标题的样式
25+
backButtonComponent={NavBackButton} // 返回按钮使用箭头
2326
ref={'router'}
2427
/>
2528
);
2629
}
2730
}
2831

2932
const styles = StyleSheet.create({
30-
header: {
33+
navHeader: {
3134
backgroundColor: '#fcaf17',
3235
},
36+
navTitle: {
37+
textAlign: 'center',
38+
}
3339
});
3440

3541
// 一定要注意引号中的'ReactNativeCodeSnippet'必须与MainActivity中getMainComponentName()的返回值一致,否则会报错
3642
AppRegistry.registerComponent('ReactNativeCodeSnippet', () => ReactNativeCodeSnippet);
43+
44+

res/icon_nav_back.png

1.09 KB
Loading

res/icon_nav_search.png

776 Bytes
Loading

res/icon_nav_setting.png

1.01 KB
Loading

0 commit comments

Comments
 (0)