Skip to content
Advertisement

How to place floating action button in bottom right in React Native

I am trying to place a floating action button in the lower right corner of my app but it is placing it in the top left way off screen.

Returned view:

JavaScript

Styles:

JavaScript

My current view displays a header and a bottom tab view. I am able to place multiple FAB’s in each tab screen but that produces an undesirable behavior. Thank you for any help.

Edit: What I have:

What I want:

Advertisement

Answer

Your issue was on adding { flex: 1, position: 'absolute',} to the button style together. The parent component that covers all the phone screen would use flex: 1, your button component is the one that receives the style for the position.

Always creating a new component makes stuff easier to read and understand. So let’s say you have a button component (<FloatingButton/>), you would do something like this:

JavaScript

You will get this result:

This is the button component:

JavaScript

Check the snack demo: https://snack.expo.io/@abranhe/floating-btn

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement