当前位置:网站首页>taro项目小程序场景下scrollview引发的问题汇总
taro项目小程序场景下scrollview引发的问题汇总
2022-07-18 12:08:00 【LittleMoon_lyy】
场景一:滑动穿透问题
滑动穿透出现的场景:
<Scrollview scrollY style={
height}>
// 1.使用了AtFloatLayout组件
// 2.带遮罩层的弹窗
</Scrollview>
出现滑动穿透的原因是,taro 3的事件冒泡机制是单独在小程序逻辑层实现,所有事件都是绑定的bind而不是catch,在touchmove事件回调中调用e.stopPropagation()并不能阻止滑动穿透,只会阻止上层组件的事件回调触发。
而是应该在View组件中添加catchMove属性,只要该属性值为true,就会使用catchTouchmove代替bindTouchmove进行事件绑定,从而阻止滑动穿透。
解决:
<View catchMove>
<Scrollview scrollY style={
height}>
</Scrollview>
</View>
场景二 更复杂一点的滑动穿透问题
实际项目中使用Scrollview的场景会更复杂,如多层Scrollview嵌套等等。
这里举一个例子,在场景一中,如果最外层的View添加了touch事件,那么仅靠添加catchMove属性是无法阻止滑动穿透的。
<View
onTouchStart={
handleMoveStart}
onTouchMove={
handleMove}
onTouchEnd={
handleEnd}
catchMove
>
<ScrollView scrollY style={
height}>
// 带遮罩层的弹窗或AtFloatLayout
</ScrollView>
</View>
注意,此时就算在外层的View里添加了catchMove,或者将内层的ScrollView的scrollY设置为false,都无法阻止滑动穿透现象。
这里提供两个解决方案:
1.控制外层View的onTouchStart事件,如果带有遮罩层的弹窗出现,则onTouchStart直接返回false,弹窗关闭之后执行原本的逻辑。
2.将带遮罩层的弹窗的代码放在整个View的外面。
<View
onTouchStart={
handleMoveStart}
onTouchMove={
handleMove}
onTouchEnd={
handleEnd}
catchMove
>
<ScrollView scrollY style={
height}>
// ...
</ScrollView>
</View>
// 带遮罩层的弹窗或AtFloatLayout
场景三 使用两层scrollview的情况下,最里层的scrollview下的各种input,textarea的输入框内容发生错位
还原一下场景:
<View catchMove>
<Scrollview scrollY style={
height}>
<AtFloatLayout>
<Input />
<Textarea />
</AtFloatLayout>
</Scrollview>
</View>
看一个效果图:
当我们把第一个scrollview的内容往下滚动后,打开AtFloatLayout里的内容,就会发现里面input和textarea中的placeholder和输入内容全部发生了错位,目前这个问题在华为的鸿蒙系统中必现。
关于这个问题的解决可以看一下微信社区,直接将最外层的scrollview的height改为其他值,不能用100vh。
scrollview里的input内容发生错位
边栏推荐
- 金仓数据库 KingbaseES SQL 语言参考手册 (3.1.3. 用户自定义类型)
- 金仓数据库 KingbaseES SQL语言参考手册(2. KingbaseES SQL介绍)
- Shell | incomplete summary of the method of checking the software installation location
- 软件配置 | Tigervnc的概念、安装以及解决 ‘bash: vncserver: command not found’ 的问题
- Number of ways to splice long strings using word lists
- Tikv & tiflash accelerates complex business queries
- 5g independent networking scheme, 5g first stage standardization work completed
- Mysql8.0 new feature - persistence of self increasing variables
- Two practical skills sharing of SAP Fiori launchpad application
- SAP FICO S_ALR_87012172 与fs10n f.01 有些科目对应不起来的问题
猜你喜欢
行业认可 | 悬镜安全荣膺DevSecOps创新赛道领航者,获选年度创新力十强
非金融类去中心化应用的产品原则
General practice of developer real name authentication
工作流引擎在vivo营销自动化中的应用实践 | 引擎篇03
Beijing bj60 is finally online, safe and comfortable
Camera minimum coverage problem
Capability verification and planning capability of performance test
B站挂了登上全网热搜!技术人员为你还原前因后果
12 个提升程序员软技能与效率的必备工具。
Big model training is difficult to go to the sky? Here comes the efficient and easy-to-use "Li Bai" model library
随机推荐
Kingbasees database administrator's Guide -- 9 manage archive redo log files
MATLAB数字图像处理 实验三:空域频域图像去噪与锐化
Lite actor: lightweight optimization of ark actor concurrency model
人工智能安全的密码学思考-学习
Cannot run program “cd“: error=2, No such file or directory
Flink entry to practice - phase 6 (state management)
The unnamed article Turing Award Yann Lecun team proposed masked Siamese ConvNets, so that the mask strategy can also be applied to the twin networks based on vit for self supervised learning!
音视频技术开发周刊 | 254
Distributed transaction --01--- basic terms and concepts, transaction admission rules, and basic transaction specifications
Unity3d- realize the storage of local data (playerprefs & jsonutility)
postgreSQL查找某个字段中是否包含某个字符
分布式事务--01---基本术语概念 、事务准入规则 、事务基本规范
bloblang教程入门
What are the defenses of a host
一个主机的防御有哪些
相机最小覆盖问题
Application of workflow engine in vivo marketing automation | engine 03
Flink入门到实战-阶段六(多流转换)
[server data recovery] data recovery case of missing shared folders of server storage (drobopro FS network storage)
Find - B-tree