【问题标题】:Animation: Image component cannot contain child even when child component position is absolute动画:即使子组件位置是绝对的,图像组件也不能包含子组件
【发布时间】:2018-01-13 14:36:37
【问题描述】:

我正在使用 React Native,现在知道 Image 不能再包含子组件。

问题是我正在使用这样的动画组件:

return (
<Animated.Image source={this.props.image}
                                style={[styles.top, borderStyles, {
                                width: this.state.top_width,
                                height: this.state.top_height,
                                transform: this.state.top_pan.getTranslateTransform()
                            }]}>
                    {back}
</Animated.Image>
)

另一种方法是使用 ImageBackground,但是当我尝试将上面的代码转换为使用如下自定义动画时:

var AnimatedImage = Animated.createAnimatedComponent(ImageBackground)

return (
            <AnimatedImage
                source={this.props.image}
                style={[styles.top, borderStyles, {
                width: this.state.top_width,
                height: this.state.top_height,
                transform: this.state.top_pan.getTranslateTransform()
                }]}
            >
                {back}
            </AnimatedImage>
)

现在在更新由 RCTView 管理的视图的属性“不透明度”时会出错

在动画中使用 ImageBackground 以适应 RN 0.50 重大变化的正确方法是什么?

【问题讨论】:

  • 你能解决吗?我有同样的问题

标签: react-native


【解决方案1】:

你可以使用这个神奇的技巧:

var AnimatedImage = Animated.createAnimatedComponent(ImageBackground)

而不是ImageBackgroundAnimated.Image

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-02-23
    • 2018-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-23
    • 2019-07-01
    • 2018-02-21
    相关资源
    最近更新 更多