admin管理员组文章数量:1400182
I am developing a book application, which supports both portrait and landscape modes. The pages of the book are svgs which are rendered inside a horizontal @shopify/flash-list
. The Page component also has a vertical ScrollView which is enabled only in landscape mode.
The problem is that when in landscape mode I scroll vertically fast the ScrollView seems to be not rendered yet and the FlashList scroll is getting triggered, i.e page swipe instead of staying on the same page and scrolling down. If I wait for 1-2 sec. everything works fine and the indented scrollable is getting triggered
I am developing a book application, which supports both portrait and landscape modes. The pages of the book are svgs which are rendered inside a horizontal @shopify/flash-list
. The Page component also has a vertical ScrollView which is enabled only in landscape mode.
The problem is that when in landscape mode I scroll vertically fast the ScrollView seems to be not rendered yet and the FlashList scroll is getting triggered, i.e page swipe instead of staying on the same page and scrolling down. If I wait for 1-2 sec. everything works fine and the indented scrollable is getting triggered
2 Answers
Reset to default 0If you use react-native-gesture-handler (or you can wrap FlashList/ScrollView with it), you may control gestures more explicitly. For instance, wrapping your vertical ScrollView in a PanGestureHandler that has higher priority than the FlashList’s horizontal scroll can help
import {
PanGestureHandler,
GestureHandlerRootView
} from 'react-native-gesture-handler';
function VerticalScrollWrapper({ children }) {
const onGestureEvent = /* vertical scroll logic */;
return (
<PanGestureHandler
onGestureEvent={onGestureEvent}
// The waitFor or simultaneousHandlers may help control
// whether the parent gesture is blocked or recognized.
>
<ScrollView>
{children}
</ScrollView>
</PanGestureHandler>
);
}
You can use simultaneousHandlers or waitFor props to coordinate with the FlashList’s gesture handler, effectively telling React Native which gesture to prioritize.
or you can disable the FlashList scroll initially scrollEnabled={false} then enable it a short time later or as soon as the vertical ScrollView is fully laid out
The issue comes from the double scroll conflict between the FlashList and the ScrollView. One possible solution is to handle the book pages (in portrait mode) as components within a full-screen carousel — for example, using react-native-reanimated-carousel with horizontal pagination. Then, reserve the vertical scroll gesture only for landscape mode within each page. This way, you can avoid conflicts between horizontal and vertical scroll gestures and ensure a smoother experience.
本文标签: javascriptNested scrollable issue on react nativeStack Overflow
版权声明:本文标题:javascript - Nested scrollable issue on react native - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744157341a2593169.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论