我在這裏使用了光滑的React Navigation並在nested navigation recipe之後,但我不知道如何將'this'傳遞給我的導航。對不起,我的無知。React Native:將道具傳遞給嵌套導航
這裏是我的總體結構輪廓:
class MyApp extends Component {
render() {
return (
<StackNavigation
screenProps={this.state}
/>
)
}
}
const MainScreenNavigator = TabNavigator(
{
Awesome: { screen: Awesome } // How do I pass this.state?
}
)
const routesConfig = {
Home: { screen: MainScreenNavigator },
Profile: { screen: Profile }
}
const StackNavigation = StackNavigator(routesConfig, {initialRouteName: 'Home'})
那麼,如何通過this.state我MainScreenNavigator?
我想我的觀點是'const StackNavigation'是在App組件外聲明的,所以它沒有'this'的上下文,並且這個'不可用 – AlxVallejo
你是對的,我直到現在才意識到。但是......你想做什麼?爲什麼'screenProps'不能解決你的問題? –
因此,這*起作用*爲初始渲染,但我注意到如果這些道具被修改(例如通過修改根組件的狀態),子畫面不會重新渲染。無論如何強迫導航員更新道具? –