我的应用程序中有一个选项卡栏,我不希望每次呈现新路线时导航过渡都会受到影响。因此,我希望将选项卡栏放在Navigator之外,但在这种情况下,如何触发导航操作?我不能访问从Navigator外部传递给renderScene函数的navigator对象。
下面是在app.js中返回的内容:
<View>
<Navigator
ref="navigator"
initialRoute={{name: "start"}}
renderScene={this.renderScene.bind(this)}
configureScene={this.configureScene.bind(this)}
/>
<TabBar navigator={???} style={styles.nav} />
</View>发布于 2017-01-06 00:28:01
好了,我想我解决了这个问题。问题似乎是refs在组件的第一次渲染时不可用。我通过以下方式解决了这个问题:
<Navigator
ref={(r) => { this.navigatorRef = r; }}
initialRoute={{name: "start"}}
renderScene={this.renderScene.bind(this)}
configureScene={this.configureScene.bind(this)}
/>
{this.state ? <TabBar navigator={this.state.navigatorRef} style={styles.nav} /> : null }并添加了这个:
componentDidMount() {
this.setState({navigatorRef: this.navigatorRef});
}只是为了让组件使用TabBar第二次呈现。
发布于 2017-01-05 22:52:33
我不认为这是做你想做的事情的最好方法。但要回答你的问题:
<View>
<Navigator
ref="navigator"
initialRoute={{name: "start"}}
renderScene={this.renderScene.bind(this)}
configureScene={this.configureScene.bind(this)}
/>
<TabBar getNavigator={()=>this.refs.navigator} style={styles.nav} />
</View>然后你可以从你的TabBar调用getNavigator()
发布于 2017-04-06 00:00:24
这是另一个适用于我的版本。它是黑客的,将来可能会崩溃,但如果你很着急,可能会有所帮助;)
<View>
<Navigation
ref={(r) => { this.navigation = r }}
/>
<OtherScreen
navigation={(this.navigation || {})._navigation}
{...this.props}
/>
</View>
https://stackoverflow.com/questions/41487877
复制相似问题