add toDataURL method for svg elements

Add toDataURL method for svg elements to get data64 data  of svg.(iOS)
Add example for this.
This commit is contained in:
Horcrux
2016-08-10 16:54:48 +08:00
parent f118ae2d67
commit 76a3e8e32d
5 changed files with 89 additions and 13 deletions
+16
View File
@@ -6,6 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
#import "RCTBridge.h"
#import "RCTUIManager.h"
#import "RNSVGSvgViewManager.h"
#import "RNSVGSvgView.h"
@@ -18,4 +20,18 @@ RCT_EXPORT_MODULE()
return [RNSVGSvgView new];
}
RCT_EXPORT_METHOD(toDataURL:(nonnull NSNumber *)reactTag callback:(RCTResponseSenderBlock)callback)
{
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *,UIView *> *viewRegistry) {
UIView *view = viewRegistry[reactTag];
if (![view isKindOfClass:[RNSVGSvgView class]]) {
RCTLogError(@"Invalid svg returned frin registry, expecting RNSVGSvgView, got: %@", view);
} else {
RNSVGSvgView *svg = view;
callback(@[[svg getDataURL]]);
}
}];
}
@end