我正在使用来自https://reactnavigation.org/docs/navigators/tab的 React Navigation 的选项卡导航器,当我在选项卡屏幕之间切换时,我在 this.props.navigation 中没有任何导航状态。
选项卡导航器:
import React, { Component } from 'react';
import { View, Text, Image} from 'react-native';
import DashboardTabScreen from 'FinanceBakerZ/src/components/dashboard/DashboardTabScreen';
import { TabNavigator } from 'react-navigation';
render() {
console.log(this.props.navigation);
return (
<View>
<DashboardTabNavigator />
</View>
);
}
const DashboardTabNavigator = TabNavigator({
TODAY: {
screen: DashboardTabScreen
},
THISWEEK: {
screen: DashboardTabScreen
}
});
仪表板屏幕:
import React, { Component } from 'react';
import { View, Text} from 'react-native';
export default class DashboardTabScreen extends Component {
constructor(props) {
super(props);
this.state = {};
console.log('props', props);
}
render() {
console.log('props', this.props);
return (
<View style={{flex: 1}}>
<Text>Checking!</Text>
</View>
);
}
}
当它首先呈现组件时,我在仪表板屏幕上获得道具,但在切换选项卡时我没有得到道具。我需要获取当前的屏幕名称,即今天或本周。