Async-ify decoding of image source http responses on iOS

This commit is contained in:
Yavor Georgiev
2015-10-08 17:26:49 +03:00
parent 06cd4952a6
commit c2e1cc5529

View File

@ -65,6 +65,19 @@ export function request(options: http.HttpRequestOptions): Promise<http.HttpResp
return utils.parseJSON(NSDataToString(data));
},
toImage: () => {
if (UIImage.imageWithData["async"]) {
return UIImage.imageWithData["async"](UIImage, [data])
.then(image => {
if (!image) {
throw new Error("Response content may not be converted to an Image");
}
var source = new imageSource.ImageSource();
source.setNativeSource(image);
return source;
});
}
return new Promise<imageSource.ImageSource>((resolveImage, rejectImage) => {
var img = imageSource.fromData(data);
if (img instanceof imageSource.ImageSource) {