discussions-and-proposals icon indicating copy to clipboard operation
discussions-and-proposals copied to clipboard

How to get view related to nativeId

Open MikePendo opened this issue 2 years ago • 1 comments

Is it possible to add the prop nativeID to a view like follows: <View nativeID="viewId">...</View> And then use that id to locate the view in my native android and iOS code so I could apply some native method on it. If it is then an example would be appreciated.

I did find the following method on the IOS:

/**
 * Finds a view that is tagged with nativeID as its nativeID prop
 * with the associated rootTag root tag view hierarchy. Returns the
 * view if found, nil otherwise.
 *
 * @param nativeID the id reference to native component relative to root view.
 * @param rootTag the react tag of root view hierarchy from which to find the view.
 */
- (UIView *)viewForNativeID:(NSString *)nativeID withRootTag:(NSNumber *)rootTag;

But the implementation seems to append nativeId with root tag (as key ) and then get it from Map so I am not sure the description of the rootTag param is correct. In case I done have the root tag how would I start get the rootView?

MikePendo avatar Dec 01 '21 11:12 MikePendo

Not sure if it's still valid, but you can take a look on how I did it in our project.

https://github.com/tonlabs/UIKit/blob/development/kit/inputs/ios/UIInputAccessoryView%2BScrollView.m#L196

Basically every view has access to a rootTag AFAIR.

PS. It's probably not a good idea anymore to depend on UIManager, as (if I'm not mistaken) it's going to be deprecated in Fabric.

savelichalex avatar Feb 14 '22 12:02 savelichalex