我有以下代码:
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
in AppView
,但是当我检查状态更改backNavSupported
后false
的值时,我得到了 ,这对我来说很有意义......
我错过了什么?
更新
这就是我在组件中使用它的方式(可能是范围问题?):
componentDidMount() {
const { backNavSupported} = this.props
BackAndroid.addEventListener('hardwareBackPress', () => {
if (backNavSupported ) {
back()
return true
}
return false
})
}