如何给contentContainerStyle添加动画?

mai*_*dib 0 reactjs react-native react-animated

我目前正在尝试为滚动视图设置动画,因此它会调整到其上方手风琴的高度。我试图通过使用动画来使滚动视图偏移,但我不断收到错误 TranslateY 的键必须是数字:{“translateY”:0}。如果我将其包装在 Animated.View 中,动画将不再起作用?

  <AnimatedScrollView
      {...props}
      onScroll={Animated.event([
        { nativeEvent: { contentOffset: { y: this.state.scroll } } },
      ])}
      scrollEventThrottle={16}
      contentContainerStyle={{
        transform: [
          {
            translateY: this.state.contentOffset,
          },
        ],
      }}
    >
Run Code Online (Sandbox Code Playgroud)

bmo*_*ent 5

我有一个类似的问题,但我contentContainerStyle根本不使用就解决了。我在原来的滚动视图子项Animated.View之间添加了一个Animated.ScrollView,然后将我的动画样式添加到其中

<Animated.ScrollView>
    <Animated.View style={animatedStyle}>
        {/* original scrollview children */}
    </Animated.View>
</Animated.ScrollView>
Run Code Online (Sandbox Code Playgroud)