In my class that implements the RCTBridgeModule protocol in Xcode, I am trying to write an RCT_EXPORT_MEATHOD that I can expose to React Native code to consume image data. Currently, I can write an image to disk in React Native, and then pass the path through to the native method, but I'm wondering if there is a better technique to pass image data directly for better performance?
So instead of this:
RCT_EXPORT_METHOD(scanImage:(NSString *)path) {
UIImage *sampleImage = [[UIImage alloc] initWithContentsOfFile:path];
[self processImage: UIImage];
}
Something more like this:
RCT_EXPORT_METHOD(scanImage:(NSData *)imageData) {
[self processImageWithData: imageData];
}
You can use
[RCTConvert UIImage:icon]method from#import <React/RCTConvert.h>You need to specify "schema" as "data". For more details look at the source code bellow: https://github.com/facebook/react-native/blob/master/React/Base/RCTConvert.m#L762