我正在为我的应用开发使用反应导航.当我运行log-android时,它会记录这样的事情.
导航调度:行动:{...},新州:{...}
它来自createNavigationContainer.js第150行.
我已经通过github和文档表示可以通过在顶级导航器上设置onNavigationStateChange = {null}来完成.
如何通过设置onNavigationStateChange = {null}来实现这一点,我应该在哪里设置它?
我尝试设置如下,但页面将无法重定向到其他页面.
export default () => {
<App onNavigationStateChange={null} />
}
Run Code Online (Sandbox Code Playgroud)
以下是我的app.js代码
import React, { Component } from 'react';
import { AppRegistry, StyleSheet, Text, View } from 'react-native';
import { StackNavigator,DrawerNavigator } from 'react-navigation';
import DrawerContent from './components/drawer/drawerContent.js';
import News from './components/news/home.js';
const drawNavigation = DrawerNavigator(
{
Home : {
screen : News ,
navigationOptions : {
header : null
}
}
},
{
contentComponent: props => <DrawerContent {...props} />
}
)
const StackNavigation = StackNavigator({
Home : { screen : drawNavigation,
navigationOptions: {
header: null
}
}
});
export default StackNavigation;
Run Code Online (Sandbox Code Playgroud)
这是我的drawerContent.js
import React, {Component} from 'react'
import {View,Text, StyleSheet,
TouchableNativeFeedback,
TouchableOpacity,
TouchableHighlight
} from 'react-native'
import { DrawerItems, DrawerView } from 'react-navigation';
import Icon from 'react-native-vector-icons/Octicons';
import MaterialIcons from 'react-native-vector-icons/MaterialIcons';
class DrawerContent extends Component {
constructor(props){
super(props);
console.log('DrawerContent|testtttttt');
}
render(){
return (
<View style={styles.container}>
<Text>Hi darren</Text>
<TouchableOpacity style={{ marginBottom:5 }} onPress={() => this.props.navigation.navigate('RegistrationScreen') } >
<View style={styles.nonIconButton}>
<Text style={{ color: 'black',fontSize: 13 }} >Sign Up</Text>
</View>
</TouchableOpacity>
<Text>Hi darren</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
});
export default DrawerContent;
Run Code Online (Sandbox Code Playgroud)
首先,确保您使用的是最新版本,react-navigation因为评论指出修复是最近提交的。
根据您的代码示例,要禁用所有导航状态更改的日志记录,您需要替换以下代码:
export default StackNavigation;
Run Code Online (Sandbox Code Playgroud)
和:
export default () => (
<StackNavigation onNavigationStateChange={null} />
);
Run Code Online (Sandbox Code Playgroud)
这StackNavigation似乎是您的根导航器。
| 归档时间: |
|
| 查看次数: |
1197 次 |
| 最近记录: |