mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-03 15:14:18 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user