React Native:如何翻译像Android上的Whatsapp一样的粘头
React Native: How to translate sticky header like the one in Whatsapp for Android?
我想创建一个像在Whatsapp的Android粘头。我的方法是听滚动事件,然后立即移动页眉,但这个方法很不流畅,Whatsapp的方法非常流畅。ScrollView的所有反弹都被转移到header,看起来很丑。理想的解决方案是先移动标题,并在移动时终止平移响应器,以便底层的ScrollView成为触摸事件的响应器-但这是不可能的。
你有什么建议使它更完美吗?这是我到目前为止所尝试的。使用动画。视图与动画。
class scrollHeader extends Component {
constructor(props) {
super(props);
this.state = {
scrollY: 0
};
this.lastY = 0;
}
handleScroll(e) {
let dy = e.nativeEvent.contentOffset.y - this.lastY;
let scrollY = this.state.scrollY + dy;
scrollY = Math.min(scrollY, 80);
scrollY = Math.max(scrollY, 0);
this.setState({
scrollY: scrollY
});
this.lastY = e.nativeEvent.contentOffset.y;
}
render() {
const s = StyleSheet.create({
container: {
flex: 1
},
menu: {
position: 'absolute',
height: 160,
top: this.state.scrollY * -1,
left: 0,
right: 0,
backgroundColor: '#075e55',
zIndex: 1,
paddingTop: 40
},
text: {
fontSize: 16,
padding: 20
},
content: {
paddingTop: 160
}
});
return (
<View style={s.container}>
<StatusBar translucent backgroundColor={'#06544c'} />
<View style={s.menu}><Text>{'Menu Header'}</Text></View>
<ScrollView style={s.content} onScroll={(e) => this.handleScroll(e)}>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
<Text>{'Test'}</Text>
</ScrollView>
</View>
);
}
}
React Native的ScrollView
默认支持粘贴头。如果您只想保留特定的标题,可以使用stickyHeaderIndices来实现。
如果你想在Android上的WhatsApp上滚动聊天时复制粘性日期标题,这可以通过使用ListView
和ListViewDataSource
的cloneWithRowsAndSections
来实现。
要了解更多信息,请查看RN的ScrollView或ListView文档
相关文章:
- 使用向下箭头键(与tab键一样)聚焦下一个输入
- 在SVG地图上添加水的渐变,就像在谷歌地图(PHP/JS)中一样
- 如何像模糊图像一样模糊iframe
- FullCalendar:事件发生时阻止重叠.标题是一样的
- 如何检测滚动事件是否像在触摸设备上一样只触发一次
- DIV怎么能像Javascript中的另一个元素一样工作呢
- 我正在创建一个聊天,但每次我发送消息时,它都不会让我再发送另一条消息,就像表格一样;不起作用
- 有没有8个谜题和15个谜题一样无法解决
- 如何缩放像图像一样的元素
- 我需要iframe的内容像动画一样展开,填满整个屏幕并缩小到原来的大小
- 是否可以像字符串一样/操作/函数
- 我可以像其他库一样将JointJS作为AngularJS模块注入吗
- 为什么可以'我们在函数体中为函数对象添加属性,就像在javascript中为对象文字添加属性一样
- 我如何创建一个选择器,就像jQuery有jQuery()或$()一样
- 为什么'这两根绳子不一样吗
- 为什么答案是一样的
- 像谷歌一样更改滚动网站
- 试图清理一个电话号码,以便如果它像816-345-6757一样被输入,它会像8163456757一样返回它
- 如何在javascript对象中设置属性的类型,就像mongoose模式设计一样
- React Native:如何翻译像Android上的Whatsapp一样的粘头