我已经创建了一个登录按钮,它将跳转到main-ui。我不希望人们在导航器默认样式的左上角看到后退按钮。
似乎NavigatorIOS
没有合适的API可供使用。你能给我一些想法吗?
答案 0 :(得分:1)
您必须使用Navigator。我建议将其与React Native Navbar结合使用。
使用Navbar,您可以传入右侧和左侧按钮组件......或者只是让它们成为空视图,如果它们不可见。该属性为>
和<ToolbarAndroid
title='WWF'
style={styles.toolbar}
navIcon={require("./App/assets/logo.png")}
logo={require("./App/assets/logo.png")}
actions={[{title: 'list', show: 'always'}, {title: 'partners', show: 'always'}, {title: 'about', show: 'always'}]}
onActionSelected={this.onActionSelected} />
。
React文档中的导航器示例应该让您入门:
leftButton
现在在rightButton
的定义中,您将包括显示NavBar:
<Navigator
initialRoute={{name: 'My First Scene', index: 0}}
renderScene={(route, navigator) =>
<MySceneComponent
name={route.name}
onForward={() => {
var nextIndex = route.index + 1;
navigator.push({
name: 'Scene ' + nextIndex,
index: nextIndex,
});
}}
onBack={() => {
if (route.index > 0) {
navigator.pop();
}
}}
/>
}
/>
当然,您可能希望将导航位抽象为一个显示其周围导航栏的组件,如上图所示,显示为MySceneComponent
。您还需要将const MySceneComponent = (props) => (
<View style={{ flex: 1, }}>
<NavigationBar
title={titleConfig}
rightButton={BUTTON_OR_NOT}
{...props} />
{props.children}
</View>
);
和{children}
信息传递到Navbar,以便它可以显示页面信息并进行设置,以便点击后退按钮调用route
,这就是我所做的通过navigation
传递navigator.pop()
。