useInterpolateMotiPressable()
In the rare case that you want more customization over pressable state, you can use useInterpolateMotiPressable. As the name implies, it lets you interpolate based on the current interaction state of a parent MotiPressable.
Usage#
Access a unique parent#
If you're passing a unique id prop to your pressable, you can also isolate this hook to that pressable.
Say the parent pressable has id="menu", and you want to isolate this hook to the menu pressable:
Then, in the Item component:
TypeScript support#
useInterpolateMotiPressable returns an Animated.DerivedValue. You can also type it with a generic:
Use the result of the interpolation#
Just like any derived value, you can read the value it returns with .value:
Performance#
Similar to useMemo, you can also pass in a dependency array as the last argument:
API#
The following usages are valid:
If there's a unique MotiPressable component with an id prop as the parent:
Arguments#
- factoryis a worklet that receives the interaction state as the first argument, and can return whatever it wants.
- idis a unique string to identify the parent- MotiPressablecomponent whose interaction state you're trying to access.
- depsis a dependency array, just like- useMemo
Returns#
A derived value, which you can use in Reanimated worklets.