Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

81
Vistas
Changing translateX after setTimeout

I have a card component that the user can move to the side to reveal buttons.

If the user didn't tap any button after 2 seconds, I want to slide the card back to place. I tried to achieve this with setTimeout, but I get an error that says I need to use runOnJS, I tried, but got the same error. This is what I have:

const panGesture = useAnimatedGestureHandler<PanGestureHandlerGestureEvent>({

    onEnd: event => {
      const shouldStick = translateX.value >= TRANSLATE_X_THRESHOULD;
      if (shouldStick) {
        translateX.value = withTiming(120);
        setTimeout(() => {
          translateX.value = withTiming(0);
        }, 2000)
      } else {
        translateX.value = withTiming(0);
      }
    },
  });

I also tried wrapping setTimeout with runOnJS, like this:

runOnJS(() => {
          setTimeout(() => {
            translateX.value = withTiming(0);
          }, 2000);
});

but it also didn't work. is it the right way to achieve what I'm trying to achieve?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda