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';
functionFloatingButton(){
return(
<FAB
style={styles.fab}
small={false}
icon="plus"
onPress={()=>console.log('Pressed')}
/>
)
}
conststyles=StyleSheet.create({
fab:{
position:'absolute',
margin:16,
right:0,
bottom:0,
flex:1,
},
})
export defaultFloatingButton
This is our App.js file and we have added our newly component in here.
First run this command to start your metro bundler.
1
npm start
Now you can run your application.
React Native Floating Action Button
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the ...
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.