我正在尝试在 react native 中构建类似于 IMessage 和 WhatsApp 标题的内容,用户可以在其中下拉以显示标题中的搜索栏。

我已经能够下拉以显示隐藏的输入,但是因为滚动视图的 y 值在拉动时变为负数,它会弹回y = 0并防止输入粘在顶部。我试过同时使用translateY和scaleY来显示隐藏的输入。
class List extends Component {
scrollY = new Animated.Value(0)
render() {
const translateY = this.props.scrollY.interpolate({
inputRange: [ -50, 0 ],
outputRange: [ 50, 0 ],
extrapolate: 'clamp',
})
return (
<>
<Animated.View style={[
styles.container,
{ transform: [ { translateY } ] },
]}>
<Input />
</Animated.View>
<Animated.ScrollView
onScroll={Animated.event(
[ { nativeEvent: { contentOffset: { y: this.scrollY } } } ],
{ …Run Code Online (Sandbox Code Playgroud)