software-mansion / react-native-reanimated

React Native's Animated library reimplemented
https://docs.swmansion.com/react-native-reanimated/
MIT License
8.83k stars 1.29k forks source link

"Cannot read property 'viewTag' of undefined" when used with react-native-tab-view #919

Closed GuimoBear closed 4 years ago

GuimoBear commented 4 years ago

Description

I'm using react-native-tab-view and decided to install react-native-reanimated@alpha, however, when I tried to use them together, the error "TypeError: cannot read property 'viewTag' of undefined" occurs whenever the component tries be rendered.

WhatsApp Image 2020-06-23 at 11 02 59

I started looking for solutions and ended up arriving at the following code at ./reanimated2/createAnimatedComponent.js

          const processedStyle = styles.map(style => {
            if (style.viewTag) {
              // this is how we recognize styles returned by useAnimatedStyle
              return style.initial;
            } else {
              return style;
            }
          });

I noticed that this style is null or undefined at some point, to correct, I checked, before the viewTag property, the 'style' and the problem was solved.

          const processedStyle = styles.map(style => {
            if (style && style.viewTag) {
              // this is how we recognize styles returned by useAnimatedStyle
              return style.initial;
            } else {
              return style;
            }
          });

Package versions

Dirk41Mavs commented 4 years ago

Thank you guys! This problem makes me recognize even source code can be careless