Not able to drag using onGestureEvent
See original GitHub issueHere is a minimal reproducible example, lmk if there are any details I’m leaving out. I was trying to recreate the pan gesture example from the course. I’m using the iOS simulator, but I click on the box, drag, and nothing happens. I’m able to log thePanGestureHandler
events (onGestureEvent
and onHandlerStateChange
) and see that it is detecting the pan gesture, but the box doesn’t move. When I use the example from react-native-gesture-handler
, it works. I think it might be something to do with the onGestureEvent
helper function, but I’m new to the Animated and gesture libraries, and I realize the two examples use different Animated libraries.
package.json
...
"react": "~16.12.0",
"react-dom": "~16.12.0",
"react-native": "~0.61.5",
"react-native-gesture-handler": "^1.6.0",
"react-native-reanimated": "^1.7.0",
"react-native-redash": "^9.6.0",
...
repro
import React from 'react'
import { StyleSheet, View } from 'react-native'
import Animated, { Value } from 'react-native-reanimated'
import {
PanGestureHandler,
State
} from 'react-native-gesture-handler'
import { onGestureEvent } from 'react-native-redash'
function Draggable (props) {
const state = new Value(State.UNDETERMINED)
const translationX = new Value(0)
const translationY = new Value(0)
const gestureHandler = onGestureEvent({
state,
translationX,
translationY
})
const translateX = translationX
const translateY = translationY
return (
<PanGestureHandler
{...gestureHandler}
>
<Animated.View
style={{
backgroundColor: 'blue',
height: 100,
width: 100,
transform: [
{ translateX },
{ translateY }
]
}}
/>
</PanGestureHandler>
)
}
export default Draggable
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Does onGestureEvent of TapGestureHandler never fire?
This is very confusing since examples using TapGestureHandler in Reanimated appear to use onGestureEvent, but I have found that handling the ...
Read more >PanGestureHandler | React Native Gesture Handler
A continuous gesture handler that can recognize a panning (dragging) gesture and track its movement. The handler activates when a finger is placed...
Read more >How to use the react-native-redash.onGestureEvent function ...
Use Snyk Code to scan source code in minutes - no build needed - and fix issues ... translationY, velocityY }); // Make...
Read more >Gesture Responder System - React Native
Cancel-ability - when making an action, the user should be able to abort it mid-touch by dragging their finger away. These features make...
Read more >Using the Gesture Handler in React Native | by SaidHayani
PanGestureHandler has many props but for now, we only need to use OnGestureEvent props to pass the gesture event, a callback function.
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 Free
Top 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
@wcandillon thanks for the quick response! That is actually good news, so I’m theoretically doing it right! I am running this in a storybook app so I’m not sure about re-rendering. I used the
useValues()
helper function and now it appears to work, so you must be correct about that. Thanks for your help, here is the fix:Thanks @JBaczuk Ran into the same issue following the course. Nothing worse than having exactly what is shown in the video and it not working. I had to modify the fix slightly to exclude the array.
const [state, translationX, translationY] = useValues(State.UNDETERMINED, 0, 0);