FlingGestureHandler reports wrong coordinates on iOS
See original GitHub issueI’m trying to implement swipe detection using FlingGestureHandler and, while working correctly on Android, I’m unable to get it to work on iOS as the nativeEvent
’s properties absoluteX
and absoluteY
are always 0, and x
and y
always contain the same coordinates regardless of the state (if I swipe from left to right, for example, I would expect a different x value when the status
is ACTIVE
and when it’s END
).
RN Version: 0.63.4 iOS Version: 14.3
function handleFling(event) {
console.log(event.nativeEvent.x, event.nativeEvent.absoluteX, event.nativeEvent.status)
// Always the same x, absoluteX always 0!
}
return (
<FlingGestureHandler
direction={Directions.LEFT | Directions.RIGHT}
onGestureEvent={handleFling}
onHandlerStateChange={handleFling}>
<View style={{height: 300, width: 300, backgroundColor: 'red'}} />
</FlingGestureHandler>
)
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:13
Top Results From Across the Web
FlingGestureHandler reports wrong coordinates on iOS
I'm trying to implement swipe detection using FlingGestureHandler and, while working correctly on Android, I'm unable to get it to work on ...
Read more >How to fix react-native-gesture-handler error not working
You should paste import 'react-native-gesture-handler'; on the top of index.js which is standard in react native out of the box.
Read more >GestureHandler - Expo Documentation
This library provides an API that exposes mobile platform specific native capabilities of touch & gesture handling and recognition.
Read more >FlingGestureHandler | React Native Gesture Handler
A discrete gesture handler that activates when the movement is sufficiently long and fast.
Read more >Tapping or typing works for some iOS devices but fails for others
Apps running in scaled or compatibility mode can cause incorrect coordinate calculations and result in test failures when tapping or ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
hi team! +1 here, I experience the same issue as @gianmarcotoso, i would like to add that adding logging to my handler like
yields the following on recognized flings:
Note that
State.ACTIVE === 4 && State.END === 5
notice how
State.BEGAN
norState.FAILED
never fire, onlyState.ACTIVE
andState.END
as expected. Hope this is useful, thanks!Edit: Just logged out the entire
nativeEvent
, and looks likex
andy
work, just not theabsolute
versions of themHowever, this is not enough information for my use case where I record the touch start coordinates on
State.BEGAN
, and then onceState.ACTIVE
is recognized, we determine which direction the swipe was going for implementing “swipe to next/previous”Thanks!
Edit again: Found a workaround for my use case by using two
FlingGestureHandlers
for each of the directions we support, since we only care about which direction a swipe was done.@gianmarcotoso hopefully you find this useful.
@ShivamJoker ah! sorry i completely missed the
Input
part ofTextInput
– i tried it out, but youre right, it does not work, i reckon the problem is due to theTextInput
element having its touch handlers getting priority over theFlingGestureRecognizer
i tried it with
editable={false} scrollEnabled={false}
too but no luck, sorry i dont know how to resolve that specific limitation youre encountering!