Custom Pressables
The mergeAnimateProp
worklet makes it easy to build custom components on top of MotiPressable
.
mergeAnimateProp
#
Say you want to build a PressableScale
component, which changes to scale: 0.96
when it's pressed.
You might start by making it like this:
However, this entirely overrides the animate
prop you pass to PressableScale
:
That's where mergeAnimateProp
comes in. Pass it the interaction state, animate
prop, and any overrides you want.
#
TypeScriptAnd in your component:
#
Usage with DripsyThen, you can use it like so:
#
In children componentsYou can also use mergeAnimateProp
in children components, with hooks like useMotiPressable
#
API#
Argumentsinteraction
required: the current interaction state, given to you by theanimateProp
.
overrides
will always supercede any values in animate
.