mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
Merge pull request #907 from NativeScript/fealebenpae/http-image-async
Async-ify decoding of image source http responses
This commit is contained in:
@ -65,6 +65,19 @@ export function request(options: http.HttpRequestOptions): Promise<http.HttpResp
|
|||||||
return utils.parseJSON(NSDataToString(data));
|
return utils.parseJSON(NSDataToString(data));
|
||||||
},
|
},
|
||||||
toImage: () => {
|
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) => {
|
return new Promise<imageSource.ImageSource>((resolveImage, rejectImage) => {
|
||||||
var img = imageSource.fromData(data);
|
var img = imageSource.fromData(data);
|
||||||
if (img instanceof imageSource.ImageSource) {
|
if (img instanceof imageSource.ImageSource) {
|
||||||
|
Reference in New Issue
Block a user