Oct 16, 2020
.
Admin
Hi Guys,
In this blog, I will explain you how to create material ui menu in react native. You can easily create material ui menu in react native. First i will import stylesheet namespace from react-native-paper, after I will make material ui menu using in react native.
Here, I will give you full example for simply display material ui menu using react native as bellow.
Step 1 - Create project
In the first step Run the following command for create project.
expo init MaterialUIMenu
Step 2 - Install Package
In the step,I will install npm i react-native-paper package .
npm i react-native-paper
Step 3 - App.js
In this step, You will open App.js file and put the code.
import * as React from 'react';
import { View, StyleSheet } from 'react-native';
import { Button, Menu, Divider, Provider } from 'react-native-paper';
const MyComponent = () => {
const [visible, setVisible] = React.useState(false);
const openMenu = () => setVisible(true);
const closeMenu = () => setVisible(false);
return (
<Provider>
<View
style={{
paddingTop: 0,
flexDirection: 'row',
justifyContent: 'center',
}}>
<Menu
style={styles.menu}
visible={visible}
onDismiss={closeMenu}
anchor={<Button onPress={openMenu} style={styles.button}>Menu</Button>}>
<Menu.Item onPress={() => {}} title="Home" />
<Menu.Item onPress={() => {}} title="Gallery" />
<Divider />
<Menu.Item onPress={() => {}} title="Event" />
<Menu.Item onPress={() => {}} title="Abouts Us" />
</Menu>
</View>
</Provider>
);
};
export default MyComponent;
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
},
button:{
backgroundColor : 'orange',
marginTop : 200
},
menu:{
marginTop : 210
}
});
Step 4 - Run project
In the last step run your project using bellow command.
npm start
Output
It will help you...
#React Native