我尝试从特定场景的视图更新NavigationHeader标题(以及左右组件)。
示例:
我目前的方法效果不佳。我尝试使用NavigationStateUtils将场景替换为自身的更新版本。如果我的视图是堆栈中的第一个视图,则此方法有效。但是,如果我尝试在不是第一个的路线上添加更新导航标题的调用,它将冻结,因为导航还没有完成它的动画。
我可以尝试在通话中添加超时,但是在全局范围内提出有意义的延迟似乎很麻烦。
case UPDATE_NAV_HEADER: {
const tabs = state.get('tabs')
const tabKey = tabs.getIn(['routes', tabs.get('index')]).get('key')
const scenes = state.get(tabKey).toJS()
const route = scenes.routes.slice(-1)[0]
var leftComponent = null
if (action.payload.leftComponent) {
leftComponent = action.payload.leftComponent
} else if (route.navLeftComponent) {
leftComponent = route.navLeftComponent
}
var rightComponent = null
if (action.payload.rightComponent) {
rightComponent = action.payload.rightComponent
} else if (route.navRightComponent) {
rightComponent = route.navRightComponent
}
const newScene = NavigationStateUtils.replaceAt(
scenes,
route.key,
{
key: route.key,
title: action.payload.newTitle ? action.payload.newTitle : route.title,
navLeftComponent: leftComponent,
navRightComponent: rightComponent,
shouldRenderHeader: "shouldRenderHeader" in route ? route.shouldRenderHeader : true,
shouldRenderTabBar: "shouldRenderTabBar" in route ? route.shouldRenderTabBar : true
}
)
return state.set(tabKey, fromJS(newScene))
}