This package provides React Native bindings for
@floating-ui/core — a library that provides anchor positioning
for a floating element to position it next to a given reference
element.
This will position the floating element at the bottom center
of the reference element by default.
Positioning is relative to the parent by default, see
ScrollView or
offsetParent to adjust this.
refs.setReference is the reference (or anchor) element
that is being referred to for positioning.
refs.setFloating is the floating element that is being
positioned relative to the reference element.
floatingStyles is an object of positioning styles to
apply to the floating element’s style prop.
The refs are functions to make them reactive — this ensures
changes to the reference or floating elements, such as with
conditional rendering, are handled correctly by updating the
position.
When your floating element is portaled to the app root, while the
reference element is inside a <ScrollView />, pass the
sameScrollView option, and spread scrollProps
to the component:
useFloating() only calculates the position once on
render, or when the reference/floating elements changed.
Depending on the context in which the floating element lives, you
may need to update its position in an Effect.
The Hook returns an update() function to update the
position at will: