You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Today I used patch-package to patch nativescript-screenshot@0.0.2 for the project I'm working on.
I revised the package to be compatible with the breaking changes in NativeScript 7 and 8: changing the import statement, replacing "exports." with "export", and modifying the ImageSource instantiation on iOS. It turns out ImageSource.fromData now returns a promise, so I modified the Android code to likewise return a promise. This means anyone invoking screenshot.getImage must now expect a promise, but their code would be broken on iOS anyway if they didn't.
Here is the diff that solved my problem:
diff --git a/node_modules/nativescript-screenshot/index.js b/node_modules/nativescript-screenshot/index.js
index 8be9bef..6c67b19 100644
--- a/node_modules/nativescript-screenshot/index.js+++ b/node_modules/nativescript-screenshot/index.js@@ -1,20 +1,20 @@-var imageSource = require("image-source");+import { ImageSource } from '@nativescript/core';-exports.getImage = function(view) {+export function getImage(view) {
if (view.ios) {
UIGraphicsBeginImageContextWithOptions(view.ios.frame.size, false, 0);
view.ios.drawViewHierarchyInRectAfterScreenUpdates(CGRectMake(0, 0, view.ios.frame.size.width, view.ios.frame.size.height), true);
var imageFromCurrentImageContext = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
- return imageSource.fromData(UIImagePNGRepresentation(imageFromCurrentImageContext));+ return ImageSource.fromData(UIImagePNGRepresentation(imageFromCurrentImageContext)); // returns Promise
} else if (view.android) {
view.android.setDrawingCacheEnabled(true);
var bmp = android.graphics.Bitmap.createBitmap(view.android.getDrawingCache());
view.android.setDrawingCacheEnabled(false);
- var source = new imageSource.ImageSource();+ var source = new ImageSource;
source.setNativeSource(bmp);
- return source;+ return Promise.resolve(source);
}
return undefined;
}
\ No newline at end of file
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch
nativescript-screenshot@0.0.2
for the project I'm working on.I revised the package to be compatible with the breaking changes in NativeScript 7 and 8: changing the import statement, replacing "exports." with "export", and modifying the ImageSource instantiation on iOS. It turns out ImageSource.fromData now returns a promise, so I modified the Android code to likewise return a promise. This means anyone invoking screenshot.getImage must now expect a promise, but their code would be broken on iOS anyway if they didn't.
Here is the diff that solved my problem:
This issue body was partially generated by patch-package.
The text was updated successfully, but these errors were encountered: