Skip to content

Commit bb9b535

Browse files
adapted plugin for ns 7
1 parent aa9dbab commit bb9b535

9 files changed

+6615
-406
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ but updated for better stability and angular, vue and react compatibility (still
1010
Use the install command:
1111

1212
```javascript
13-
tns plugin add nativescript-cscreenshot
13+
tns plugin add @enduco/nativescript-cscreenshot
1414
```
1515

1616
## Usage
@@ -20,8 +20,8 @@ Just import the plugin in your project and use it like this
2020
using Typescript:
2121

2222
```typescript
23-
import { Cscreenshot } from 'nativescript-cscreenshot';
24-
import { ImageSource } from "tns-core-modules/image-source";
23+
import { Cscreenshot } from "@enduco/nativescript-cscreenshot";
24+
import { ImageSource } from "@nativescript/core";
2525

2626
// then in your take a screenshot method
2727
let screen = new Cscreenshot();

src/cscreenshot.android.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import { Common } from './cscreenshot.common';
2-
import { ViewBase } from 'tns-core-modules/ui/core/view';
3-
import { ImageSource } from "tns-core-modules/image-source";
1+
import { Common } from "./cscreenshot.common";
2+
import { ImageSource, ViewBase } from "@nativescript/core";
43

54
export class Cscreenshot extends Common {
6-
constructor(){
5+
constructor() {
76
super();
87
}
9-
take(view: ViewBase, callback: any){
8+
9+
take(view: ViewBase, callback: any) {
1010
let androidView = view.android;
1111
let bmp: android.graphics.Bitmap = android.graphics.Bitmap.createBitmap(androidView.getWidth(), androidView.getHeight(), android.graphics.Bitmap.Config.ARGB_8888);
1212
let c: android.graphics.Canvas = new android.graphics.Canvas(bmp);
1313
androidView.draw(c);
1414
let native: ImageSource = new ImageSource();
1515
native.setNativeSource(bmp);
16-
16+
1717
callback(native);
1818
}
19-
}
19+
}

src/cscreenshot.common.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
import { Observable } from 'tns-core-modules/data/observable';
2-
import { ViewBase } from 'tns-core-modules/ui/core/view';
1+
import { ViewBase, Observable } from "@nativescript/core";
32

43
export class Common extends Observable implements screenShot {
5-
public fileImage: File;
6-
constructor() {
7-
super();
8-
}
9-
take(view: ViewBase, callback: any){}
4+
public fileImage: File;
5+
6+
constructor() {
7+
super();
8+
}
9+
10+
take(view: ViewBase, callback: any) {
11+
}
1012
}
1113

12-
export interface screenShot{
13-
take(view: ViewBase, callback: any);
14-
}
14+
export interface screenShot {
15+
take(view: ViewBase, callback: any);
16+
}

src/cscreenshot.ios.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { Common } from './cscreenshot.common';
2-
import { ViewBase } from 'tns-core-modules/ui/core/view';
3-
import { ImageSource, fromData } from "tns-core-modules/image-source";
1+
import { Common } from "./cscreenshot.common";
2+
import { ImageSource, ViewBase } from "@nativescript/core";
3+
import { fromData } from "@nativescript/core/image-source";
44

55
export class Cscreenshot extends Common {
6-
take(view: ViewBase, callback: any){
6+
take(view: ViewBase, callback: any) {
77
let iosView = view.ios.view ? view.ios.view : view.ios;
88
UIGraphicsBeginImageContextWithOptions(iosView.frame.size, false, 0);
99
iosView.drawViewHierarchyInRectAfterScreenUpdates(CGRectMake(0, 0, iosView.frame.size.width, iosView.frame.size.height), true);
10-
var imageFromCurrentImageContext = UIGraphicsGetImageFromCurrentImageContext();
10+
const imageFromCurrentImageContext = UIGraphicsGetImageFromCurrentImageContext();
1111
UIGraphicsEndImageContext();
1212
callback(<ImageSource>fromData(UIImagePNGRepresentation(imageFromCurrentImageContext)));
1313
}

src/index.d.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import { Common } from './cscreenshot.common';
2-
import { ViewBase } from 'tns-core-modules/ui/core/view';
1+
import { Common } from "./cscreenshot.common";
2+
import { ViewBase } from "@nativescript/core";
3+
34
export declare class Cscreenshot extends Common {
4-
constructor();
5-
take(view: ViewBase, callback: any): void;
5+
constructor();
6+
7+
take(view: ViewBase, callback: any): void;
68
}

0 commit comments

Comments
 (0)