mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-04 23:54:53 +00:00
[android] Fix SVG.toDataURL exception #948
This commit is contained in:
@@ -14,6 +14,7 @@ import com.facebook.react.bridge.ReactApplicationContext;
|
|||||||
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||||
import com.facebook.react.bridge.ReactMethod;
|
import com.facebook.react.bridge.ReactMethod;
|
||||||
import com.facebook.react.bridge.ReadableMap;
|
import com.facebook.react.bridge.ReadableMap;
|
||||||
|
import com.facebook.react.bridge.UiThreadUtil;
|
||||||
|
|
||||||
class SvgViewModule extends ReactContextBaseJavaModule {
|
class SvgViewModule extends ReactContextBaseJavaModule {
|
||||||
SvgViewModule(ReactApplicationContext reactContext) {
|
SvgViewModule(ReactApplicationContext reactContext) {
|
||||||
@@ -26,43 +27,50 @@ class SvgViewModule extends ReactContextBaseJavaModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static public void toDataURL(final int tag, final ReadableMap options, final Callback successCallback, final int attempt) {
|
static public void toDataURL(final int tag, final ReadableMap options, final Callback successCallback, final int attempt) {
|
||||||
SvgView svg = SvgViewManager.getSvgViewByTag(tag);
|
UiThreadUtil.runOnUiThread(
|
||||||
|
new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
SvgView svg = SvgViewManager.getSvgViewByTag(tag);
|
||||||
|
|
||||||
if (svg == null) {
|
if (svg == null) {
|
||||||
SvgViewManager.runWhenViewIsAvailable(tag, new Runnable() {
|
SvgViewManager.runWhenViewIsAvailable(tag, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
SvgView svg = SvgViewManager.getSvgViewByTag(tag);
|
SvgView svg = SvgViewManager.getSvgViewByTag(tag);
|
||||||
if (svg == null) { // Should never happen
|
if (svg == null) { // Should never happen
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
svg.setToDataUrlTask(new Runnable() {
|
svg.setToDataUrlTask(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
toDataURL(tag, options, successCallback, attempt + 1);
|
toDataURL(tag, options, successCallback, attempt + 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else if (!svg.isRendered()) {
|
||||||
|
svg.setToDataUrlTask(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
toDataURL(tag, options, successCallback, attempt + 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
if (options != null) {
|
||||||
|
successCallback.invoke(
|
||||||
|
svg.toDataURL(
|
||||||
|
options.getInt("width"),
|
||||||
|
options.getInt("height")
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
successCallback.invoke(svg.toDataURL());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
} else if (!svg.isRendered()) {
|
|
||||||
svg.setToDataUrlTask(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
toDataURL(tag, options, successCallback, attempt + 1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
if (options != null) {
|
|
||||||
successCallback.invoke(
|
|
||||||
svg.toDataURL(
|
|
||||||
options.getInt("width"),
|
|
||||||
options.getInt("height")
|
|
||||||
)
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
successCallback.invoke(svg.toDataURL());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReactMethod
|
@ReactMethod
|
||||||
|
|||||||
Reference in New Issue
Block a user