In this React Native lesson we are going to learn about React Native Floating Action Button, for this we are going to use third part library that is called react native paper, so paper is a collection of customizable and production-ready components for React Native, following Google’s Material Design guidelines, also floating action button represents the primary action in an application.
First you need to install react native paper.
1 |
npm install react-native-paper |
This is our FloatingButton.js file, we have added our floating button in this component, you can use FAB for creating of floating button, you can give style, icon and also an event for the button.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
import React from 'react' import { StyleSheet, View, Text } from 'react-native'; import { FAB } from 'react-native-paper'; function FloatingButton() { return ( <FAB style={styles.fab} small = {false} icon="plus" onPress={() => console.log('Pressed')} /> ) } const styles = StyleSheet.create({ fab: { position: 'absolute', margin: 16, right: 0, bottom:0, flex:1, }, }) export default FloatingButton |
This is our App.js file and we have added our newly component in here.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
import React from 'react'; import { StyleSheet, Text, View } from 'react-native'; import FloatingButton from './components/FloatingButton'; export default function App() { return ( <FloatingButton/> ); } const styles = StyleSheet.create({ fab: { position: 'absolute', margin: 16, right: 0, flex:1, }, }) |
First run this command to start your metro bundler.
1 |
npm start |
Now you can run your application.