Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

137
Views
¿Cómo esperar a que finalice una función de desvanecimiento?

Me gustaría cambiar un valor cuando finaliza una función fadeOut.

tengo la siguiente función:

 const fadeOut = (duration: number = 300) => { Animated.timing( opacity, { toValue: 0, duration, useNativeDriver: true } ).start(); }

Y lo llamo así:

 const fadeOutScreen = () => { fadeOut(1000); // The value would be true when the fadeOut is over setHide(true); }

Pero el valor se cambia antes de que finalice la operación.

¿Como puedo resolver esto?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Hazlo asíncrono:

Aquí están los documentos

Parque infantil TS

 const fadeOut = (duration: number = 300) => new Promise<boolean>(resolve => { Animated.timing( opacity, { toValue: 0, duration, useNativeDriver: true, } ).start(({finished}) => resolve(finished)); }); const fadeOutScreen = async () => { const finished = await fadeOut(1000); if (finished) setHide(true); else { // animation was interrupted } };
about 4 years ago · Juan Pablo Isaza Report

0

La animación se ejecuta de forma asincrónica, pero la función fadeOutScreen continuará ejecutándose de forma sincrónica después de que se inicie la animación.

Animated.start() , sin embargo, toma una devolución de llamada que se llama una vez que finaliza la animación, por lo que puede hacerlo así:

 const fadeOut = (duration: number = 300, cb?: (boolean) => void) => { Animated.timing( opacity, { toValue: 0, duration, useNativeDriver: true } ).start( //vvvvvvvv--- This tells whether the animation has finished or stopped ({finished}) => cb?.(finished) // ^^--- Only call callback if present (new syntax) ); }
 const fadeOutScreen = () => { fadeOut( 1000, finished => { if(finished) setHide(true); } ); }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!