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

261
Views
React Native LayoutAnimation no funciona en dispositivos Android

Estaba tratando de crear una animación de colapso usando LayoutAnimation de React Native y vi algunos temas que esto no funcionaba solo en dispositivos Android. Para hacerlo posible, fue necesario poner el siguiente código dentro de un constructor:

 if (Platform.OS === 'android') { UIManager.setLayoutAnimationEnabledExperimental && UIManager.setLayoutAnimationEnabledExperimental(true); }

Como estoy usando un componente funcional, puse este código dentro de un useEffect sin dependencias. Sin embargo, la animación sigue sin funcionar. ¿Estoy haciendo algo mal o necesito hacer algo más?

Mi código:

 const Collapse = ({ item, onPress }: CollapseProps) => { const [layoutHeight, setLayoutHeight] = useState<null | number>(0); useEffect(() => { if (item.isExpanded) { setLayoutHeight(null); } else { setLayoutHeight(0); } }, [item.isExpanded]); return ( <View> <TouchableOpacity onPress={onPress}> <Text>{item.title}</Text> </TouchableOpacity> <View style={{ overflow: 'hidden', height: layoutHeight, }}> {item.data.map((element: any) => ( <Text>{element.text}</Text> ))} </View> </View> ); }; const Menu = () => { const [menuMock, setMenuMock] = useState(mockMenu); useEffect(() => { if (Platform.OS === 'android') { // eslint-disable-next-line no-unused-expressions UIManager.setLayoutAnimationEnabledExperimental && UIManager.setLayoutAnimationEnabledExperimental(true); } }, []); const updateLayout = (index: number) => { LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut); const arrOfMenuMock = [...menuMock] as any; arrOfMenuMock[index].isExpanded = !arrOfMenuMock[index].isExpanded; // setIsDataOpen(true); setMenuMock(arrOfMenuMock); }; return ( <Menu> {menuMock.map((item, key) => ( <Collapse item={item} key={key} onPress={() => updateLayout(key)} /> ))} </Menu> ) }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Mover LayoutAnimation.configureNext antes de cambiar el estado

 useEffect(() => { LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut); if (item.isExpanded) { setLayoutHeight(null); } else { setLayoutHeight(0); } }, [item.isExpanded]);
about 4 years ago · Juan Pablo Isaza Report

0

Actualización : el código no debe estar en useEffect, sino encima de los componentes.

 if (Platform.OS === 'android') { if (UIManager.setLayoutAnimationEnabledExperimental) { UIManager.setLayoutAnimationEnabledExperimental(true); } }

La documentación de LayoutAnimation recomienda hacer esto

https://reactnative.dev/docs/layoutanimation

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!