[React Native] Access Component in Native Code
1 min readJan 18, 2017
When I’m creating a native module, and I have to present something on a controller, I will use keyWindow.rootController
.
But when that “something” is a UIActivityController
and you’re running your RN app on an iPad, you will need to get a source view. I just found a way to achieve this purpose.
Javascript(TypeScript) part. event.target
gets the reactTag
of sender
<TouchableOpacity onPress={(e: NativeSyntheticEvent) => {
YourNativeModule.doSomethingCool(e.target);
}} />
Native part.
#import "RCTBridge.h"
#import "RCTUIManager.h"@implementation YourNativeModule@synthesize bridge = _bridge;RCT_EXPORT_MODULE();RCT_REMAP_METHOD(doSomethingCool, senderTag:(NSNumber * _Nonnull)reactTag) {
// ...
UIView *sender = [self.bridge.uiManager viewForReactTag:reactTag];
// ...
}@end
Yep, that’s it.