我遇到以下错误说明(通过 iOS 测试):
无法读取 null 的属性“getScrollableNode”
在尝试将 react-native 的Animated与侧面样式组件样式工具一起用于 react 和 react-native 时。
这是<Logo />
我创建的组件的示例:
import React from 'react';
import { Image, Dimensions } from 'react-native';
import styled from 'styled-components/native';
const { width } = Dimensions.get('window');
const logoWidth = width - (width * 0.2);
const logoHeight = logoWidth * 0.4516;
const SLogoImage = styled(Image)`
width: ${logoWidth};
height: ${logoHeight};
`;
const Logo = ({ ...rest }) => (
<SLogoImage
source={require('../assets/logo.png')}
{...rest}
/>
);
export default Logo;
然后,我将此组件导入我想要对其应用动画的场景之一:
import React from 'react';
import { View, Animated } from 'react-native';
import Logo from '../components/Logo';
const ALogo = Animated.createAnimatedComponent(Logo);
class HomeScene extends Component {
state = {
fadeAnim: new Animated.Value(0)
}
componentDidMount() {
Animated.timing(
this.state.fadeAnim,
{ toValue: 1 }
).start()
}
render() {
<View>
<ALogo style={{ opacity: this.state.fadeAnim }} />
</View>
}
}
export default HomeScene;
这会导致上面提到的错误,尝试用谷歌搜索它并找不到任何解释它是什么。如有必要,请随时索取更多详细信息。
相关 GitHub 问题: https ://github.com/styled-components/styled-components/issues/341