Skip to content

How to start animation only with onLongPress ? #148

Answered by nandorojo
siddharth-kt asked this question in Q&A
Discussion options

You must be logged in to vote

Is something like this what you want?

import { MotiPressable, useDynamicAnimation } from 'moti/interactions'

function Button() {
  const longPressAnimation = useDynamicAnimation(() => ({
    scale: 1 // this is your initial state
  }))

  return (
    <MotiPressable
      state={longPressAnimation}
      onLongPress={() => {
        longPressAnimation.animateTo({ scale: 0.9 })
      }}
      onPressOut={() => {
        longPressAnimation.animateTo({ scale: 1 })
      }}
    />
  )
}

Or, you could use preset variants:

import { MotiPressable, useAnimationState } from 'moti/interactions'

function Button() {
  const longPressAnimation = useAnimationState({
    from: { scale: 1 },
    longPr…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by siddharth-kt
Comment options

You must be logged in to vote
1 reply
@nandorojo
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants