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

193
Vistas
¿Cómo animar el ancho del componente de reacción nativa?

Estoy usando import { Animated } from 'react-native'

Al especificar width: animated-value en el estilo, el width en realidad solo se representa una vez y no cambia dinámicamente. Solo puede ver que el valor animado detrás de escena está cambiando si hace que el elemento se vuelva a renderizar.

 // since only function components can use hooks, wrap the classical component in a function one // that sets up the hook for it function withAnimationHook(Component) { return function WrappedComponent(props) { const anim = useRef(new Animated.Value(0)); useEffect(() => { Animated.loop( Animated.sequence([ Animated.timing(anim.current, { toValue: 1, duration: 2000, }), Animated.timing(anim.current, { toValue: 0, duration: 2000, }), ]) ).start(); }, []); return <Component {...props} anim={anim} />; } } class AnimatedButton extends React.Component { render() { const { anim, width } = this.props return ( <Animated.View style={{ width: width * anim.current._value }}> </Animated.View> ) } } export default withAnimationHook(AnimatedButton)

Sé que configurar el valor animado funciona porque style={{ transform: [{ scale: anim.current }] }} funciona perfectamente (crece y se reduce repetidamente).

¿Por qué width: width * anim.current._value anima el ancho?

¿Cómo puedo animar el ancho?

this.props.width es solo un número por cierto, por ejemplo, 64

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

deja probar esto.

 const SubView = ({ parentValue = 0, propWidth=2000 }) => { const animatedValue = useRef(new Animated.Value(0)).current useEffect(() => { Animated.timing(animatedValue, { toValue: parentvalue, duration: 2000, }).start() }, [parentValue]) return ( <Animated.View style={[ styles.viewStyle, { width: animatedValue.interpolate({ inputRange: [0, 1], outputRange: [0, propWidth], }), }, ]} ></Animated.View> ) } export default React.memo(SubView)
about 4 years ago · Juan Pablo Isaza Denunciar
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