[android] Fix SVG.toDataURL exception #948

This commit is contained in:
Mikael Sand
2019-03-18 20:45:26 +02:00
parent 0bea45b5e7
commit 0e48d439f1
@@ -14,6 +14,7 @@ import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.UiThreadUtil;
class SvgViewModule extends ReactContextBaseJavaModule {
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) {
SvgView svg = SvgViewManager.getSvgViewByTag(tag);
UiThreadUtil.runOnUiThread(
new Runnable() {
@Override
public void run() {
SvgView svg = SvgViewManager.getSvgViewByTag(tag);
if (svg == null) {
SvgViewManager.runWhenViewIsAvailable(tag, new Runnable() {
@Override
public void run() {
SvgView svg = SvgViewManager.getSvgViewByTag(tag);
if (svg == null) { // Should never happen
return;
}
svg.setToDataUrlTask(new Runnable() {
@Override
public void run() {
toDataURL(tag, options, successCallback, attempt + 1);
if (svg == null) {
SvgViewManager.runWhenViewIsAvailable(tag, new Runnable() {
@Override
public void run() {
SvgView svg = SvgViewManager.getSvgViewByTag(tag);
if (svg == null) { // Should never happen
return;
}
svg.setToDataUrlTask(new Runnable() {
@Override
public void run() {
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