useMotiPressableTransition()
useMotiPressableTransition
lets you motify any Moti component's transition
prop based on a parent's interaction state.
Please refer to the Moti transition
prop options to see what this hook should return.
Example:
#
UsageWrap your component with MotiPressable
.
Then, in the Item
component:
#
Access a unique IDYou can also access a pressable via unique ID. Say you have mutliple nested pressables:
By adding id="list"
, we can now access that unique component's interaction state.
Then, in the Item
component, add list
as the first argument of useMotiPressableTransition
:
This lets you uniquely transition based on interactionns made on the list
pressable.
#
PerformanceThis hook runs on the native thread and triggers zero re-renders. Like all things moti, it has great performance out-of-the-box.
Similar to useMemo
, you can also pass in a dependency array as the last argument to reduce updates:
#
APIThe following usages are valid:
If there's a unique MotiPressable component with an id
prop as the parent:
#
Argumentsfactory
is a worklet that receives the interaction state as the first argument, and returns a transition object.id
is a unique string to identify the parentMotiPressable
component whose interaction state you're trying to access.deps
is a dependency array, just likeuseMemo
#
ReturnsA Moti transition
object, meant to be passed to any Moti component's transition
prop.