将元素推送到导航堆栈时遇到问题。我用自己的减速机:
export default function navigationReducer(state = initialState, action = {}) {
switch (action.type) {
case NAV_PUSH:
if (state.navigationState.children[state.navigationState.index].key === (action.state && action.state.key))
return state;
return {...state,...{
navigationState: StateUtils.push(state.navigationState, action.state)
}
};
case NAV_POP:
if (state.navigationState.index === 0 || state.navigationState.children.length === 1)
return state.navigationState;
return {...state,...{
navigationState: StateUtils.pop(state.navigationState)
}
};
case NAV_JUMP_TO_KEY:
return {...state,...{
navigationState: StateUtils.jumpTo(state.navigationState, action.key)
}
};
case NAV_JUMP_TO_INDEX:
return {...state,...{
navigationState: StateUtils.jumpToIndex(state.navigationState, action.index)
}
};
case NAV_RESET:
return {...state,...{
navigationState: StateUtils.reset(state.navigationState, [action.state],0)
}
};
default:
return state
}
}
当我推送之前已经推过的项目时,我得到一个异常,表明导航堆栈应该是唯一的。
Each child in an array or iterator should have a unique "key" prop. Check the render method of `NavigationAnimatedView`
导航库不保证此要求。 有意义的是导航堆栈应该只包含唯一的项目,如果它应该,我会认为库负责这个,这不是我必须手动检查的东西吗?