Nox*_*102 4 navigation hamburger-menu react-native
我对React-Native很新,所以我肯定可能会遗漏一些东西.但我想要做的就是将汉堡包类型按钮添加到主导航栏中的设置页面.我在主要部分设置了一个链接,就像我想要汉堡包按钮一样. 截图
import React from 'react';
import { AppRegistry, Text, View, Button } from 'react-native';
import { StackNavigator } from 'react-navigation';
class HomeScreen extends React.Component {
static navigationOptions = {
title: 'Welcome',
headerLeft: <Button onPress={ WHAT GOES HERE?? } title= "=" />
};
render() {
const { navigate } = this.props.navigation;
return (
<Button
onPress={() => navigate('Settings')}
title="Link to Settings" />
);
}
}
class Settings extends React.Component {
static navigationOptions = {
title: 'Settings',
headerLeft: <Button title= "=" />
};
render() {
return <Text>Hello, Settings!</Text>;
}
}
const SimpleApp = StackNavigator({
Home: { screen: HomeScreen },
Settings: { screen: Settings}
});
AppRegistry.registerComponent('NavPractice', () => SimpleApp);Run Code Online (Sandbox Code Playgroud)
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>Run Code Online (Sandbox Code Playgroud)
And*_*yco 14
有了这个,你就非常接近解决方案了.
static navigationOptions = {
title: 'Welcome',
headerLeft: <Button onPress={ WHAT GOES HERE?? } title= "=" />
};
Run Code Online (Sandbox Code Playgroud)
鲜为人知的事实是navigationOptions接受返回导航选项的功能.该功能接受一些道具,navigation其中之一.知道这一点,稍微调整你的代码.
static navigationOptions = function(props) {
return {
title: 'Welcome',
headerLeft: <Button onPress={() => props.navigation.navigate('DrawerOpen')} title= "=" />
}
};
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,您似乎正在向侧边栏添加选项并导航到侧边栏菜单。
//sidebar menu no.1
class HomeScreen extends React.Component {
static navigationOptions = {
title: 'Welcome',
headerLeft: <Button onPress={//action taken when option in the menu bar is clicked} title= "//the title of the screen where you will navigate and the sidebar menu lable" />
};
render() {
const { navigate } = this.props.navigation;
return (
<Button
onPress={() => navigate('Settings')}
title="Link to Settings" />
);
}
}
Run Code Online (Sandbox Code Playgroud)
通过这种方式,您可以创建尽可能多的抽屉选项。现在如何组合抽屉选项:
//react navigation为您提供DrawerNavigator API
const MyApp = DrawerNavigator({
Home: {
screenA: HomeScreen ,
},
Settings: {
screen: MySettingScreens,
},
});
Run Code Online (Sandbox Code Playgroud)
抽屉还附带了一个 prop,即 screenProps={/* 该 prop 将作为 props.screenProps */} 传递给屏幕组件和导航选项,如下所示:
<MyApp
screenProps={/* this prop will get passed to the screen components and nav options as props.screenProps */}
/>
Run Code Online (Sandbox Code Playgroud)
以下是反应导航器提供的用于打开/关闭抽屉的道具。
this.props.navigation.navigate('DrawerOpen'); // open drawer
this.props.navigation.navigate('DrawerClose'); // close drawer
Run Code Online (Sandbox Code Playgroud)
您还可以根据自己的喜好设置抽屉样式,如下所示:
抽屉宽度-抽屉的宽度抽屉位置-选项是向左或向右。默认为左侧位置。contentComponent - 默认情况下,抽屉中没有可用的滚动视图。为了在抽屉中添加滚动视图,您需要contentComponent在配置中添加。contentOptions - 顾名思义,它们用于为活动和非活动抽屉项目(标签)提供颜色。
干杯:)
| 归档时间: |
|
| 查看次数: |
14418 次 |
| 最近记录: |