带有flex 1的ScrollView使其不可滚动 [英] ScrollView with flex 1 makes it un-scrollable

查看:690
本文介绍了带有flex 1的ScrollView使其不可滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在 ScrollView 上运行flex,只要ScrollView的 flex:1 滚动内部不起作用
这里是博览会的小提琴(你可以运行这个代码和玩)
https: //snack.expo.io/SySerKNp-



请注意,如果您删除 flex:1 > ScrollView 它确实让滚动,但是你失去了挠性的力量(让红色容器向下推动上部框(ScrollView))的能力,所以我必须在那里有一个flex。



ps - 我只在android上工作,我没有在iPhone上测试它(我不介意在那里的结果)

任何想法我错过了什么?为什么当 flex:1 时, ScrollView 不能正常工作?
thanks!
解决方案

我相信你的问题是,你正在告诉ScrollView占用所有可用空间flex = 1但事情是ScrollView工作不同。它自动呈现所有的孩子,所以它的工作与flex不同。这是与正常ListView或FlatList有更好的性能差异。

我相信这个零食可以解决这个问题: https: //snack.expo.io/SkxN9GOT-



基本上,我得到设备的高度,并设置固定高度的ScrollView,基于(screenHeight - 红色框的当前高度)。

I'm trying to run flex on a ScrollView, and as long as the ScrollView has flex: 1 the scroll inside does not work. here is the expo fiddle (that you can run this code and play with) https://snack.expo.io/SySerKNp-

note that if you remove the flex: 1 from the ScrollView it does let scroll but then you lose the flex power ( the ability to let the red container down to push up the upper box (the ScrollView) ) so I must have a flex there.

p.s - I'm working only on android, and I haven't tested it on iPhone( I don't mind the result there )

any idea what am I missing ? why the ScrollView won't function right when it has a flex: 1 ? thanks !

解决方案

I believe your problem is that you are telling the ScrollView to occupy all available space with flex=1 but the thing is that ScrollView works differently. It automatically renders all its children so it does work different with flex. That is the difference against a normal ListView or FlatList which have better performance.

I believe this snack solves that issue: https://snack.expo.io/SkxN9GOT-

Basically, I am getting the height of the device and setting the ScrollView with a fixed height, based on (screenHeight - the current height of the red box).

这篇关于带有flex 1的ScrollView使其不可滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆