我在使用從https://reactnavigation.org/docs/navigators/tab的React Navigation的Tab Navigator,當我在Tab.screen之間切換時,我沒有在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>
);
}
}
我會在儀表盤屏幕的道具時,它呈現組件第一,但是當我切換我沒有得到道具標籤。 我需要獲取當前的屏幕名稱,例如TODAY或THISWEEK。