How would I get the coordinates of my touch event. So I tap anywhere within the display and I can retrieve the X, Y positioning of where it happened.
标签:
react-native
相关问题
- React Native Inline style for multiple Text in sin
- How Do I Convert Image URI into Byte Expo
- ApolloClient from apollo-boost attemped to assign
- Implementing ssl pinning in a react-native applica
- React-Native: Enable Performance Monitor in produc
相关文章
- Why do we have to call `.done()` at the end of a p
- Remove expo from react native
- React Native - Dynamic Image Source
- “Unfortunately, app has stopped” error with buildi
- eslint Parsing error: Unexpected token =
- How to determine JS bottlenecks in React Native co
- How to override navigation options in functional c
- PanResponder snaps Animated.View back to original
You will need to wrap your view object with TouchableOpacity or one of the other Touchable components. With TouchableOpacity you have the onPress prop that is passed a press event. From this press event you have access to the x,y coordinates of the press.
pseudo code would look like this:
Put it on your view tag and you can get all coordinates
For example
However this event only work with tag. so you can set view according to your requirement.
If you want more flexibility than what is offered by a button such as TouchableOpacity (eg. if you want gesture move events), then you'll need to make use of the gesture responder system. This allows components to subscribe to touch events.
I've included example implementations for all of the gesture response event handlers, but have commented out most of them on my View to just provide the basic functionality: subscribing to all touch and move events. I demonstrate arrow syntax for the boolean functions, and use the old-fashioned
bind()
syntax for calling my customonTouchEvent(name, ev)
function.If this is still not enough functionality for you (eg. if you need multi-touch info), refer to PanResponder.