-
-
Notifications
You must be signed in to change notification settings - Fork 983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FlatList
component does not scroll vertically on touch in mobile responsive mode
#2617
Comments
I have the same problem with GetureDetector and FlatList/ScrollList on the Web |
Hi! Thanks for submitting this issue. I've managed to identify what causes this problem. We still have to find good way to fix it though. |
Hello @m-bert ! Let me know if you need any help with the tests. Thanks! |
Sure, if we find good way how to deal with this problem I'll definitely ask for help with tests! As for now, I can tell what causes it. So the problem comes from this line. Moreover, |
Hi @echarbeto! Just to let you know, we are close to solving this problem. I've created a draft PR that should fix this issue by replacing I'll get back to you when PR will be ready so you will have opportunity to test if it helps! |
Hi @m-bert , You're right. If I add a margin to the containerStyle of Swipeable, and touch outside of the container, I can scroll vertically. I'll wait for your instructions to test. Once done, I'll upload the changes to the test project I used and let you know how the tests turn out. Thanks! |
This is what it looks like. Is there any patch or quick fix? We got a blocker when trying to upgrade to Expo 49. |
Since my PR is no longer a draft, you can check if it works and doesn't break anything in your app. I'd like to merge it soon and it would be great to confirm that it solves issue and does not introduce any regression. |
@m-bert, I installed the version Thanks! |
Hi @GuestInCorle! Thanks for pointing this out! We do want to support all browsers, especially major ones. Dealing with scroll isn't that simple though, and it seems that somehow firefox implements it in a bit different way than chrome. Right now I'm testing slightly different approach, maybe this will help with other browsers. |
@m-bert The fix seems to only work in Chrome. We've received reports that Safari is having the same scrolling issue as Firefox. |
@m-bert There is also a problem with Chrome. In the same case reported in the original issue, the swipe gesture has now become significantly more difficult to perform with the mouse. The real touch screen works fine. |
Hi @GuestInCorle! I've made some changes in my PR, could you please check if scrolling works on safari? |
@m-bert Scrolling and swiping now work in Safari. I've tested the latest commit in 94f74117-fa2f-4d43-84c1-2800e276d479.mp4 |
I'm having the same issue using FlatList on my app, if I use an ScrollView with Gesture.Pan().simultaneousWithExternalGesture(scrollViewRef), the swipe and the list scroll works, but when using same code but with a Flatlist, the list scroll only works if pressed outside from the swipeable component, I'm using my own swipeable item component export const SwipeableItem = ({ item, onDismiss, scrollRef }: any) => {
const { width: SCREEN_WIDTH } = useWindowDimensions()
const TRANSLATE_X_THRESHOLD = -SCREEN_WIDTH * 0.3
const translateX = useSharedValue(0)
const itemHeight = useSharedValue(70)
const itemMarginVertical = useSharedValue(10)
const actionOpacity = useSharedValue(1)
const panGesture = Gesture
.Pan()
.simultaneousWithExternalGesture(scrollRef)
.onChange((event) => {
translateX.value = event.translationX
})
.onEnd(() => {
const shouldDismiss = translateX.value < TRANSLATE_X_THRESHOLD
if (shouldDismiss) {
translateX.value = withTiming(-SCREEN_WIDTH)
itemHeight.value = withTiming(0)
itemMarginVertical.value = withTiming(0)
actionOpacity.value = withTiming(0, undefined, (isFinished) => {
if (isFinished) {
runOnJS(onDismiss)(item.id)
}
})
} else {
translateX.value = withTiming(0)
}
})
const reanimatedStyle = useAnimatedStyle(() => ({
transform: [{ translateX: translateX.value }]
}))
const reanimatedIconContainerStyle = useAnimatedStyle(() => {
const opacity = withTiming(translateX.value < TRANSLATE_X_THRESHOLD ? 1 : 0)
return { opacity }
})
const reanimatedTaskContainerStyle = useAnimatedStyle(() => {
return {
height: itemHeight.value,
marginVertical: itemMarginVertical.value,
opacity: actionOpacity.value
}
})
return (
<Container style={[reanimatedTaskContainerStyle]}>
<Animated.View style={[{ width: 60, height: 70, backgroundColor: "red", position: "absolute", right: "10%" }, reanimatedIconContainerStyle]}>
<Text>Icon</Text>
</Animated.View>
<GestureDetector gesture={panGesture}>
<Animated.View style={[{ width: "90%", height: 70, backgroundColor: "blue" }, reanimatedStyle]}>
<Text>{item.title}</Text>
</Animated.View>
</GestureDetector>
</Container>
)
} |
Hi @echarbeto, @GuestInCorle, @LucasLFurini! I know it's been a while, but we decided to change our approach to this problem and hopefully this time we will be able to make everything work fine. Could you please check if #2788 fixes this problem? |
## Description This is a follow-up PR to #2787 that is meant to fix scrolling of swipeable elements. It overrides `shouldHandlerBeCancelledBy` method so that **_active_** `NativeViewGestureHandler` that is _**not a button**_, will cancel other handler. Keep in mind that on web, if scroll has already started we cannot cancel it by calling `preventDefault`, hence it makes sense to cancel other handlers in that case (but we may want to limit it just to `Pan`). Fixes #2617 ## Test plan Tested on - Swipeable example in our example app - Transformations example with added text to achieve scrolling <details> <summary> Modified code from #2617 </summary> ```jsx import React from 'react'; import { View, Text } from 'react-native'; import { FlatList, GestureHandlerRootView } from 'react-native-gesture-handler'; import Swipeable from 'react-native-gesture-handler/Swipeable'; export default function Home() { type ItemProps = { item: { text: string; }; }; const data = Array.from({ length: 50 }, (_, i) => ({ id: i, text: `Item ${i}`, })); const Item = ({ item }: ItemProps) => { return ( <View style={{ margin: 10 }}> <Swipeable renderRightActions={() => ( <View style={{ justifyContent: 'center', }}> <Text style={{ color: 'white', textAlign: 'center' }}> Delete </Text> </View> )}> <View style={{ height: 50, backgroundColor: 'white', justifyContent: 'center', }}> <Text>{item.text}</Text> </View> </Swipeable> </View> ); }; return ( <GestureHandlerRootView> <FlatList data={data} keyExtractor={(item) => item.id.toString()} renderItem={({ item }) => <Item item={item} />} style={{ maxHeight: 400 }} /> </GestureHandlerRootView> ); } ``` </details>
Description
Hello, I'm experiencing an issue with the
FlatList
component fromreact-native-gesture-handler
when it's used in conjunction with theSwipeable
component. Specifically, theFlatList
component does not scroll vertically on touch in mobile responsive mode.Steps to reproduce
The issue occurs when trying to scroll vertically in mobile view. The FlatList component does not respond to vertical scrolling actions.
Snack or a link to a repository
https://github.com/echarbeto/tamagui_test/tree/TEST/flatlist_with_swipeable_elements
Gesture Handler version
2.13.1
React Native version
0.72.5
Platforms
Web
JavaScript runtime
None
Workflow
Expo managed workflow
Architecture
None
Build type
Debug mode
Device
None
Device model
No response
Acknowledgements
Yes
The text was updated successfully, but these errors were encountered: