我构建了一个React Native应用,其中有2个用于更改屏幕的标签。当我更改屏幕时,我还要更改标题的标题。因此,当按Tab 1时,如果打开Tab 2屏幕,则图块为Tab 1和Tab 2。 我想了解在我的代码中需要执行哪种更改或添加操作。我分享了我认为应该进行更改的代码,但是如果我错了,请引导我选择我应该分享的正确代码。我是Native的新手,正在尝试学习它。
我有一个Route.js文件:
import React from 'react';
import { View, Platform, Image, StyleSheet } from "react-native";
import {createStackNavigator} from "react-navigation";
import FlightsTabNavigator from "./App/navigations/FlightsTabNavigator";
import FlightsHeader from "./App/components/header/FlightsHeader";
import HeaderStyle from "./App/styles/HeaderStyle";
import s from "./App/styles/headerImgStyle";
const Routes = createStackNavigator({
FlightsTabNavigator: {
screen: FlightsTabNavigator,
}
},{
initialRouteName: 'FlightsTabNavigator',
navigationOptions: {
headerTitle: '',
headerBackground: (
<Image
style={s.image}
//source={require('./App/assets/header/header.jpg')}
source={{uri: 'https://images.unsplash.com/photo-1503365113766-4a362681eac5?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=79cf794378a008ab1d74b8e612d72ad0&auto=format&fit=crop&w=1050&q=80'}}
/>
),
header: props => <FlightsHeader {...props} />,
...HeaderStyle,
animationEnabled: true
}
});
export default Routes;
标题:
import React from "react";
import { Header } from "react-navigation";
import { View, Text, Platform, Image, StyleSheet } from "react-native";
const FlightsHeader = props => {
return (
<View>
<Header {...props} />
</View>
);
};
export default FlightsHeader;