1

In React Native I have a component like this,

<View nativeID="myView" />

https://reactnative.dev/docs/view#nativeid

Now, how can I call/select this View with myView id?

I've checked this: How can i identify a view in objective c with given nativeID(given in react-native)

But unfortunately this isn't work for me.

Please help! Thanks in advance.

Encrypted
  • 628
  • 1
  • 10
  • 22

1 Answers1

1

Since I started with React and even react native I never had to use a field like your nativeID. Instead, react and react-native allow the use of references. Many times while coding it is used something like:

this.doSomething_specified()

Well, it is possible to pass the reference "this" as prop while using a React component:

<MyReactComp called={this} ... />

and use methods or functions related to "this" within the declaration of MyReactComp .

Jose Cabrera Zuniga
  • 2,348
  • 3
  • 31
  • 56
  • Thank you. But could you please provide an example. I don't understand how to implement this from your answer. I just need to call a specific `` component and get it's x-y co-ordinate positions. – Encrypted Sep 17 '20 at 10:48
  • Please, look into https://stackoverflow.com/questions/46216325/reactnative-get-the-absolute-position-of-a-view-relative-to-the-screen?rq=1 – Jose Cabrera Zuniga Sep 17 '20 at 12:46
  • Actually, this is to get the position of element on loading. But I need the position of element after dragging end. This is exactly what I need. Please have a look: https://stackoverflow.com/questions/63924996/react-native-get-actual-x-y-co-ordinates-of-an-element-after-finish-dragging-r – Encrypted Sep 17 '20 at 16:57
  • I used the library https://www.npmjs.com/package/react-native-draggable and this one talks about the onDragRelease callback. What you are asking might be related to the component you are using. So, I suggest you to write to the respective creators (issues section of their github) and tell them which call back and props to use. – Jose Cabrera Zuniga Sep 17 '20 at 17:43
  • Thanks for your reference. I actually posted there. https://github.com/software-mansion/react-native-gesture-handler/issues/1192 But no response :( Could you please confirm me that I could do what I want here https://stackoverflow.com/questions/63924996/react-native-get-actual-x-y-co-ordinates-of-an-element-after-finish-dragging-r with your suggested https://www.npmjs.com/package/react-native-draggable package? – Encrypted Sep 17 '20 at 19:22
  • The best answer I found is located at: https://github.com/tongyy/react-native-draggable/issues/77 – Jose Cabrera Zuniga Sep 17 '20 at 22:08
  • https://github.com/tongyy/react-native-draggable/issues/52 – Jose Cabrera Zuniga Sep 17 '20 at 22:16