我做了一个登录按钮,它将跳转到main-ui。我不希望人们在导航器默认样式的左上角看到后退按钮。
似乎NavigatorIOS
没有合适的API可以使用。你能给我个主意吗?
您必须使用Navigator。我建议将它与React Native Navbar结合使用。
使用Navbar,您可以传递左右按钮组件...或者,如果它们不可见,则只需将它们设为空视图即可。该属性是leftButton
和rightButton
。
React文档上的导航器示例应该可以帮助您入门:
<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
您的定义中将包括显示NavBar:
const MySceneComponent = (props) => (
<View style={{ flex: 1, }}>
<NavigationBar
title={titleConfig}
rightButton={BUTTON_OR_NOT}
{...props} />
{props.children}
</View>
);
当然,您可能希望将导航位抽象到一个组件中,该组件将在其周围显示导航栏,如上图所示{children}
。您将进一步希望将route
和navigation
信息传递到Navbar中,以便它可以显示页面信息并使之生效,以便单击后退按钮进行调用navigator.pop()
,这是我通过props
via传递的信息{...props}
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句