mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-07 16:54:52 +00:00
[android] Make SvgView.drawChildren synchronized
Fix race-condition https://github.com/react-native-community/react-native-svg/issues/948 Refactor toDataUrl
This commit is contained in:
@@ -26,27 +26,21 @@ class SvgViewModule extends ReactContextBaseJavaModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ReactMethod
|
|
||||||
public void toDataURL(int tag, Callback successCallback) {
|
|
||||||
SvgView svg = SvgViewManager.getSvgViewByTag(tag);
|
|
||||||
|
|
||||||
if (svg != null) {
|
|
||||||
successCallback.invoke(svg.toDataURL());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@ReactMethod
|
@ReactMethod
|
||||||
public void toDataURL(int tag, ReadableMap options, Callback successCallback) {
|
public void toDataURL(int tag, ReadableMap options, Callback successCallback) {
|
||||||
SvgView svg = SvgViewManager.getSvgViewByTag(tag);
|
SvgView svg = SvgViewManager.getSvgViewByTag(tag);
|
||||||
|
|
||||||
if (svg != null) {
|
if (svg != null) {
|
||||||
successCallback.invoke(
|
if (options != null) {
|
||||||
svg.toDataURL(
|
successCallback.invoke(
|
||||||
options.getInt("width"),
|
svg.toDataURL(
|
||||||
options.getInt("height")
|
options.getInt("width"),
|
||||||
)
|
options.getInt("height")
|
||||||
);
|
)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
successCallback.invoke(svg.toDataURL());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-5
@@ -54,11 +54,7 @@ export default class Svg extends Shape {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const handle = findNodeHandle(this.root);
|
const handle = findNodeHandle(this.root);
|
||||||
if (options) {
|
RNSVGSvgViewManager.toDataURL(handle, options, callback);
|
||||||
RNSVGSvgViewManager.toDataURL(handle, options, callback);
|
|
||||||
} else {
|
|
||||||
RNSVGSvgViewManager.toDataURL(handle, callback);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|||||||
@@ -30,39 +30,31 @@ RCT_EXPORT_VIEW_PROPERTY(align, NSString)
|
|||||||
RCT_EXPORT_VIEW_PROPERTY(meetOrSlice, RNSVGVBMOS)
|
RCT_EXPORT_VIEW_PROPERTY(meetOrSlice, RNSVGVBMOS)
|
||||||
RCT_EXPORT_VIEW_PROPERTY(tintColor, UIColor)
|
RCT_EXPORT_VIEW_PROPERTY(tintColor, UIColor)
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(toDataURL:(nonnull NSNumber *)reactTag callback:(RCTResponseSenderBlock)callback)
|
|
||||||
{
|
|
||||||
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *,UIView *> *viewRegistry) {
|
|
||||||
__kindof UIView *view = viewRegistry[reactTag];
|
|
||||||
if ([view isKindOfClass:[RNSVGSvgView class]]) {
|
|
||||||
RNSVGSvgView *svg = view;
|
|
||||||
callback(@[[svg getDataURL]]);
|
|
||||||
} else {
|
|
||||||
RCTLogError(@"Invalid svg returned frin registry, expecting RNSVGSvgView, got: %@", view);
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(toDataURL:(nonnull NSNumber *)reactTag options:(NSDictionary *)options callback:(RCTResponseSenderBlock)callback)
|
RCT_EXPORT_METHOD(toDataURL:(nonnull NSNumber *)reactTag options:(NSDictionary *)options callback:(RCTResponseSenderBlock)callback)
|
||||||
{
|
{
|
||||||
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *,UIView *> *viewRegistry) {
|
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *,UIView *> *viewRegistry) {
|
||||||
__kindof UIView *view = viewRegistry[reactTag];
|
__kindof UIView *view = viewRegistry[reactTag];
|
||||||
if ([view isKindOfClass:[RNSVGSvgView class]]) {
|
if ([view isKindOfClass:[RNSVGSvgView class]]) {
|
||||||
RNSVGSvgView *svg = view;
|
RNSVGSvgView *svg = view;
|
||||||
id width = [options objectForKey:@"width"];
|
if (options == nil) {
|
||||||
id height = [options objectForKey:@"height"];
|
RNSVGSvgView *svg = view;
|
||||||
if (![width isKindOfClass:NSNumber.class] ||
|
callback(@[[svg getDataURL]]);
|
||||||
![height isKindOfClass:NSNumber.class]) {
|
} else {
|
||||||
RCTLogError(@"Invalid width or height given to toDataURL");
|
id width = [options objectForKey:@"width"];
|
||||||
return;
|
id height = [options objectForKey:@"height"];
|
||||||
}
|
if (![width isKindOfClass:NSNumber.class] ||
|
||||||
NSNumber* w = width;
|
![height isKindOfClass:NSNumber.class]) {
|
||||||
NSInteger wi = (NSInteger)[w intValue];
|
RCTLogError(@"Invalid width or height given to toDataURL");
|
||||||
NSNumber* h = height;
|
return;
|
||||||
NSInteger hi = (NSInteger)[h intValue];
|
}
|
||||||
|
NSNumber* w = width;
|
||||||
|
NSInteger wi = (NSInteger)[w intValue];
|
||||||
|
NSNumber* h = height;
|
||||||
|
NSInteger hi = (NSInteger)[h intValue];
|
||||||
|
|
||||||
CGSize bounds = CGSizeMake(wi, hi);
|
CGSize bounds = CGSizeMake(wi, hi);
|
||||||
callback(@[[svg getDataURLwithBounds:bounds]]);
|
callback(@[[svg getDataURLwithBounds:bounds]]);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
RCTLogError(@"Invalid svg returned frin registry, expecting RNSVGSvgView, got: %@", view);
|
RCTLogError(@"Invalid svg returned frin registry, expecting RNSVGSvgView, got: %@", view);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user