我有以下代码:
select.js
:
export const getNavigationRoutes = state => state.navigation.routes
export const getNavigationIndex = state => state.navigation.index
export const getNavigationTab = createSelector(
[getNavigationRoutes, getNavigationIndex],
(routes, index) => (routes[index])
)
export const getBackNavSupported = createSelector(
getNavigationTab, nevTab => nevTab.index !== 0
)
viewController.js
:
import {connect} from 'react-redux'
import AppView from './AppView'
import { getBackNavSupported } from '../selectors
export default connect(
state => ({
backNavSupported: getBackNavSupported(state),
}))
)(AppView)
我的状态从
变化{
"index": 1,
"key": "root",
"routes": [
{
"key": "HomeTab",
"title": "Home",
"index": 0,
"routes": [ /* .... */ ]
},
{
"key": "FamilyTab",
"title": "Family",
"index": 0,
"iconName": "people",
"routes": [ /* .... */ ]
},
]
}
到
{
"index": 1,
"key": "root",
"routes": [
{
"key": "HomeTab",
"title": "Home",
"index": 0,
"routes": [ /* ... */ ]
},
{
"key": "FamilyTab",
"title": "Family",
"index": 1,
"routes": [ /* ... */ ]
}
]
}
我在backNavSupported
中使用AppView
,但当我在状态发生变化后检查backNavSupported
的值时,我得到false
,其中现在对我有意义......
我错过了什么?
更新
我如何在组件中使用它(可能是范围问题?):
componentDidMount() {
const { backNavSupported} = this.props
BackAndroid.addEventListener('hardwareBackPress', () => {
if (backNavSupported ) {
back()
return true
}
return false
})
}