我有一个
react-navigation
像这样的路由器:
const RootNavigator = createSwitchNavigator({
App: createBottomTabNavigator({
Home: {
screen: HomeScreenContainer
},
Scan: {
screen: DocumentScanScreenContainer
},
// ...
}, {
tabBarOptions: {
showLabel: false,
// ...
}
})
})
这个
HomeScreenContainer
和
DocumentScanScreenContainer
是必需的,因为
反应式导航
仅接受
React.Component
和我的
HomeScreen
和
DocumentScanScreen
组件是Redux组件,直接导入会使
反应式导航
引发错误。
主屏幕控制器
和
文档扫描屏幕容器
是相似的,所以这里是
文档扫描屏幕容器
:
import React from 'react'
import PropTypes from 'prop-types'
import DocumentScanScreen from '../../screens/DocumentScanScreen'
export default class DocumentScanScreenContainer extends React.Component {
static propTypes = {
navigation: PropTypes.shape.isRequired
}
render() {
const { navigation } = this.props
// Passing the navigation object to the screen so that you can call
// this.props.navigation.navigate() from the screen.
return (
<DocumentScanScreen navigation={navigation} />
)
}
}
最后是一个简短的版本
文档扫描屏幕
:
import React from 'react'
import { connect } from 'react-redux'
import PropTypes from 'prop-types'
class DocumentScanScreen extends React.Component {
static propTypes = {
token: PropTypes.string,
navigation: PropTypes.shape.isRequired
}
componentDidMount() {
const { token, navigation } = this.props
if (token === undefined || token === null || token === 0) {
navigation.navigate('Authentication')
}
}
// ...
}
我在每一级都有警告说
navigation
是未定义的,所以它就像我的
文档扫描屏幕容器
没有收到
航行
来自路由器的道具:
警告:道具类型失败:documentscanscreencontainer:道具类型
航行
是无效的;它必须是一个函数,通常来自
prop-types
包装,但已收到
undefined
.
是我做错了,还是有办法通过,从路由器,
航行
支持
文档扫描屏幕容器
?