React Native Material UI Snackbar Example

React Native

Nicesnippets

70

23-10-2020


React Native Material UI Snackbar Example

Hi Guys,

In this blog, I will explain you how to create material ui snackbar in react native. You can easily create material ui snackbar in react native. First i will import stylesheet namespace from react-native-paper, after I will make material ui snackbar using in react native.

Here, I will give you full example for simply display material ui snackbar using react native as bellow.

Step 1 - Create project


In the first step Run the following command for create project.

expo init MaterialUISnackbar

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, Snackbar } from 'react-native-paper';

const SnackBarDemo = () => {

const [visible, setVisible] = React.useState(false);

const toggleSnackBar = () => {

setVisible(!visible);

}

const dismissSnackBar = () => {

setVisible(false);

}

return (

<View style={styles.container}>

<Button onPress={toggleSnackBar} style={styles.btn}>{visible ? 'Hide Snackbar' : 'Show Snackbar'}</Button>

<Snackbar

visible={visible}

onDismiss={dismissSnackBar}>

This Is Snackbar

</Snackbar>

</View>

);

};

const styles = StyleSheet.create({

container: {

flex: 1,

justifyContent: 'space-between',

marginTop: 250,

},

btn: {

backgroundColor : 'pink',

width : 200,

marginLeft: 80,

}

});

export default SnackBarDemo;

Step 4 - Run project

In the last step run your project using bellow command.

npm start

Output

It will help you...


Recommended Posts