当嵌套子滚动视图滚动到其视图末尾时,如何防止*锁定*父滚动视图滚动?
在react-native项目中,有一个父级平面列表/滚动视图。在此父列表中的每个项目内,都存在一个嵌套的滚动视图。
预期行为:当父滚动视图被锁定时,父滚动视图永远不应该滚动,只允许子滚动视图滚动。当满足子滚动视图的外部边界时(意味着您已滚动到子视图的底部或一直返回到子视图的顶部),父视图保持锁定状态
实际发生的情况:使用父视图滚动锁定,一旦子滚动视图到达其滚动边界,将子滚动视图滚动到最底部/顶部将滚动父滚动视图
重现行为的步骤:
- 向下轻拂子滚动视图之一直到到达底部
- (即使你已经到达了下方边界)尝试向下滚动子视图,
- 观察父滚动视图现在滚动的事实,即使父滚动视图被锁定,
如何在嵌套时真正防止父滚动视图滚动 -滚动视图到达其视图的末尾?
只在 Android 上注意到这一点,但 iOS 上也可能存在。
这是一个最小的可重现示例: https://staging.snack.expo.dev/b3XuJ6iA3
In a react-native project, there is a parent flatlist/scrollview. inside each item in this parent list, there exists a nested scroll view.
Expected behavior: When the parent scroll view is locked, the parent should NEVER scroll, only the child scrollview should be allowed to scroll. and when the outer bound of the child scroll view is met (meaning youve scrolled to the bottom or all the way back to the top of child view), the parent remains locked
What actually happens: with parent view scroll-locked, scrolling the child scrollview to the very bottom/top will scroll the parent scroll view, once the child scroll view reaches its scroll-boundary
Steps to reproduce behavior:
- flick one of the child scroll views downward until it reaches the bottom
- (even though youve reached the downward boundary) attempt to scroll the child down even more
- observe the fact the parent scroll view now scrolls instead, even though the parent scroll view is locked
How can the parent scroll view be truly prevented from scrolling when nested-scroll-view reaches the end of its view?
only noticed this on android, but could possibly exist on ios as well.
here is a minimum reproducible example: https://staging.snack.expo.dev/b3XuJ6iA3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将多个
ScrollViews
嵌套在FlatList
中,这是ScrollView
的便捷包装器(与 文档) ,但您在子项中将nestedScrollEnabled
设置为 true滚动视图
。您需要在父ScrollView
(FlatList
)上设置它。以下代码完全禁用父
FlatList
的滚动,同时允许在所有嵌套的ScrollViews
中滚动。这是代码的工作 snack ,其中包含上述更改,我已在 Android(三星 Galaxy S9)和 iOS(iPhone 12)上成功测试。
You are nesting multiple
ScrollViews
inside aFlatList
, which is a convenience wrapper aroundScrollView
(compare with the documentation) , but you are settingnestedScrolEnabled
to true in the childScrollViews
. You need to set it on the parentScrollView
(theFlatList
).The following code completely disables scrolling for the parent
FlatList
while allowing scrolling in all nestedScrollViews
.Here is a working snack of your code with the changes mentioned above which I have successfully tested on Android (Samsung Galaxy S9) and iOS (iPhone 12).