小编Lui*_*cia的帖子

如何使用Animated.diffClamp反应原生

有关如何实现Animated.diffClamp的任何代码示例?

我正在尝试创建一个标题滚动动画,就像谷歌播放应用程序中的那个.当你开始向下滚动时我已经隐藏了标题,但问题是我想在你开始向上滚动时再次显示标题,它只在你到达视图顶部时显示.

class Services extends Component {
  constructor(props){
  super(props);
  this.state = {
    scrollY : new Animated.Value(0),
  }
}

renderScrollViewContent(){
  return (
    <View style={styles.scrollViewContent}>
    </View>
  )
}

render() {
  const headerHeight = this.state.scrollY.interpolate({
    inputRange: [0, 60],
    outputRange: [0, -60],
    extrapolate: 'clamp'
  });

  return (
    <View style={styles.container}>
      <ScrollView style={styles.container}
        scrollEventThrottle={16}
        onScroll={Animated.event(
          [{nativeEvent: {contentOffset: {y: this.state.scrollY}}}]
        )}
      >
        {this.renderScrollViewContent()}
      </ScrollView>
      <Animated.View style={[styles.header, {top: headerHeight}]}>
        <View style={styles.bar}>
          <Text style={styles.title}>Title</Text>
        </View>
      </Animated.View>
    </View>
  );
 }
}
Run Code Online (Sandbox Code Playgroud)

animation android react-native

2
推荐指数
2
解决办法
4260
查看次数

标签 统计

android ×1

animation ×1

react-native ×1