Skip to content

Commit c9d032a

Browse files
authored
Merge pull request #8 from NativeScript/updates
Updates
2 parents 5d7be2d + 2233f6f commit c9d032a

File tree

108 files changed

+22361
-3428
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+22361
-3428
lines changed

CanvasNative.podspec

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Pod::Spec.new do |s|
22

33
s.name = "CanvasNative"
44

5-
s.version = "0.9.1"
5+
s.version = "0.9.2"
66

77
s.summary = "A Canvas library"
88

@@ -11,25 +11,17 @@ Pod::Spec.new do |s|
1111

1212
s.license = { :type => "MIT", :file => "LICENSE" }
1313

14-
1514
s.author = { "Osei Fortune" => "[email protected]" }
1615

17-
s.platform = :ios, "10.0"
16+
s.platform = :ios, "11.0"
1817

1918
s.source = { :git => "https://github.com/nativescript/canvas.git", :tag => "#{s.version}" }
2019

21-
s.source_files = 'packages/canvas/src-native/canvas-ios/CanvasNative/**/*.{swift,m,mm,h,c}'
2220
s.pod_target_xcconfig = {
23-
'USER_HEADER_SEARCH_PATHS' => '"${PODS_ROOT}/CanvasNative/include" "${PODS_ROOT}/CanvasNative/CanvasNative/include"',
24-
'HEADER_SEARCH_PATHS' => '"${PODS_ROOT}/CanvasNative/include" "${PODS_ROOT}/CanvasNative/CanvasNative/include"',
25-
'CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES' => 'YES',
26-
'ENABLE_BITCODE' => 'NO',
27-
'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => '"arm64" "i386"' ,
28-
'GCC_PREPROCESSOR_DEFINITIONS' => 'GLES_SILENCE_DEPRECATION=1'
21+
'FRAMEWORK_SEARCH_PATHS' => '$(inherited) "${PODS_ROOT}/CanvasNative/frameworks"',
22+
'ENABLE_BITCODE' => 'YES',
2923
}
30-
s.user_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => '"arm64" "i386"' }
3124
s.swift_versions = ['4.0','4.2', '5.0']
32-
s.vendored_libraries = 'packages/canvas/src-native/canvas-ios/CanvasNative/libs/*.a'
33-
s.public_header_files = 'packages/canvas/src-native/canvas-ios/CanvasNative/include/*.h'
34-
s.libraries = 'c++'
25+
s.vendored_frameworks = 'packages/canvas/src-native/canvas-ios/CanvasNative/Dist/CanvasNative.xcframework'
26+
s.preserve_paths = 'CanvasNative.xcframework'
3527
end

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,5 @@
8383
"**/*": [
8484
"nx format:write --files"
8585
]
86-
},
87-
"dependencies": {
88-
"xmldom-qsa": "^1.0.3"
8986
}
9087
}
Lines changed: 49 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
import {Element} from "./Element";
2-
import {knownFolders, path, File, ImageSource} from "@nativescript/core";
3-
import {ImageAsset} from '@nativescript/canvas';
1+
import { Element } from './Element';
2+
import { knownFolders, path, File, ImageSource } from '@nativescript/core';
3+
import { ImageAsset } from '@nativescript/canvas';
44

55
const background_queue = global.isIOS ? dispatch_get_global_queue(qos_class_t.QOS_CLASS_DEFAULT, 0) : undefined;
66
const main_queue = global.isIOS ? dispatch_get_current_queue() : undefined;
77
declare var NSUUID, java, NSData, android;
88
const b64Extensions = {
9-
"/": "jpg",
10-
i: "png",
11-
R: "gif",
12-
U: "webp",
9+
'/': 'jpg',
10+
i: 'png',
11+
R: 'gif',
12+
U: 'webp',
1313
};
1414

1515
function b64WithoutPrefix(b64) {
16-
return b64.split(",")[1];
16+
return b64.split(',')[1];
1717
}
1818

1919
function getMIMEforBase64String(b64) {
2020
let input = b64;
21-
if (b64.includes(",")) {
21+
if (b64.includes(',')) {
2222
input = b64WithoutPrefix(b64);
2323
}
2424
const first = input.charAt(0);
2525
const mime = b64Extensions[first];
2626
if (!mime) {
27-
throw new Error("Unknown Base64 MIME type: " + b64);
27+
throw new Error('Unknown Base64 MIME type: ' + b64);
2828
}
2929
return mime;
3030
}
@@ -69,20 +69,18 @@ export class HTMLImageElement extends Element {
6969
set complete(value) {
7070
this._complete = value;
7171
if (value) {
72-
this.emitter.emit("load", this);
72+
this.emitter.emit('load', this);
7373
this.onload();
7474
}
7575
}
7676

77-
7877
constructor(props?) {
79-
super("image");
78+
super('image');
8079
this._asset = new ImageAsset();
8180
this.__id = getUUID();
8281
// this._load = this._load.bind(this);
83-
this._onload = () => {
84-
};
85-
if (props !== null && typeof props === "object") {
82+
this._onload = () => {};
83+
if (props !== null && typeof props === 'object') {
8684
this.src = props.localUri;
8785
this.width = props.width;
8886
this.height = props.height;
@@ -92,14 +90,10 @@ export class HTMLImageElement extends Element {
9290

9391
_load() {
9492
if (this.src) {
95-
if (
96-
typeof this.src === "string" &&
97-
this.src.startsWith &&
98-
this.src.startsWith("data:")
99-
) {
93+
if (typeof this.src === 'string' && this.src.startsWith && this.src.startsWith('data:')) {
10094
// is base64 - convert and try again;
10195
this._base64 = this.src;
102-
const base64result = this.src.split(",")[1];
96+
const base64result = this.src.split(',')[1];
10397
if (!base64result) {
10498
return;
10599
}
@@ -109,25 +103,16 @@ export class HTMLImageElement extends Element {
109103
const dir = knownFolders.documents().path;
110104
if (global.isIOS) {
111105
dispatch_async(background_queue, () => {
112-
this.localUri = path.join(
113-
dir,
114-
`${getUUID()}-b64image.${MIME}`
115-
);
106+
this.localUri = path.join(dir, `${getUUID()}-b64image.${MIME}`);
116107
const file = File.fromPath(this.localUri);
117-
const toWrite = NSData.alloc().initWithBase64EncodedStringOptions(
118-
base64result,
119-
0
120-
);
108+
const toWrite = NSData.alloc().initWithBase64EncodedStringOptions(base64result, 0);
121109
let hasError = false;
122110
file.writeSync(toWrite, (error) => {
123111
hasError = true;
124112
if ((global as any).__debug_browser_polyfill_image) {
125-
console.log(
126-
`nativescript-browser-polyfill: Error:`,
127-
error.message
128-
);
113+
console.log(`nativescript-browser-polyfill: Error:`, error.message);
129114
}
130-
this.emitter.emit("error", {target: this, error});
115+
this.emitter.emit('error', { target: this, error });
131116
});
132117
if (!hasError) {
133118
dispatch_async(main_queue, () => {
@@ -138,33 +123,34 @@ export class HTMLImageElement extends Element {
138123
}
139124
if (global.isAndroid) {
140125
const ref = new WeakRef(this);
141-
(com as any).github.triniwiz.async.Async.base64ToFile(base64result, dir + '/', new (com as any).github.triniwiz.async.Async.Callback({
142-
success(response) {
143-
const owner = ref.get();
144-
if (owner) {
145-
owner.localUri = response.toString();
146-
owner._load();
147-
}
148-
},
149-
error(error, message) {
150-
if ((global as any).__debug_browser_polyfill_image) {
151-
console.log(
152-
`nativescript-browser-polyfill: Error:`,
153-
message,
154-
);
155-
}
156-
ref.get()?.emitter.emit("error", {target: ref.get(), message});
157-
}
158-
}))
126+
(com as any).github.triniwiz.async.Async2.Base64.base64ToFile(
127+
base64result,
128+
dir + '/',
129+
new (com as any).github.triniwiz.async.Async2.Base64.Callback({
130+
success(response) {
131+
const owner = ref.get();
132+
if (owner) {
133+
owner.localUri = response.toString();
134+
owner._load();
135+
}
136+
},
137+
error(error, message) {
138+
if ((global as any).__debug_browser_polyfill_image) {
139+
console.log(`nativescript-browser-polyfill: Error:`, message);
140+
}
141+
const owner = ref.get();
142+
if (owner) {
143+
owner.emitter.emit('error', { target: ref.get(), message });
144+
}
145+
},
146+
})
147+
);
159148
}
160149
} catch (error) {
161150
if ((global as any).__debug_browser_polyfill_image) {
162-
console.log(
163-
`nativescript-browser-polyfill: Error:`,
164-
error.message
165-
);
151+
console.log(`nativescript-browser-polyfill: Error:`, error.message);
166152
}
167-
this.emitter.emit("error", {target: this, error});
153+
this.emitter.emit('error', { target: this, error });
168154
}
169155
})();
170156
return;
@@ -181,14 +167,15 @@ export class HTMLImageElement extends Element {
181167
.catch(e => {
182168
this.emitter.emit("error", {target: this});
183169
});*/
184-
this._asset.loadFileAsync(this.src)
170+
this._asset
171+
.loadFileAsync(this.src)
185172
.then(() => {
186173
this.width = this._asset.width;
187174
this.height = this._asset.height;
188175
this.complete = true;
189176
})
190-
.catch(e => {
191-
this.emitter.emit("error", {target: this});
177+
.catch((e) => {
178+
this.emitter.emit('error', { target: this });
192179
});
193180
} else {
194181
/*ImageSource.fromFile(this.src)
@@ -201,8 +188,7 @@ export class HTMLImageElement extends Element {
201188
.catch(e => {
202189
this.emitter.emit("error", {target: this});
203190
});*/
204-
205-
/* this._asset.loadFileAsync(this.src)
191+
/* this._asset.loadFileAsync(this.src)
206192
.then(() => {
207193
this.width = this._asset.width;
208194
this.height = this._asset.height;
@@ -216,4 +202,3 @@ export class HTMLImageElement extends Element {
216202
}
217203
}
218204
}
219-
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
declare var com;
2+
3+
export class FileManager {
4+
5+
public static writeFile(bytes: any, path: string, callback: (...args) => void) {
6+
const listener = new com.github.triniwiz.async.Async2.FileManager.Callback({
7+
onError(param0: string, param1: java.lang.Exception): void {
8+
callback(param0, null);
9+
},
10+
onComplete(param0: any): void {
11+
callback(null, param0);
12+
}
13+
});
14+
if (bytes instanceof java.nio.ByteBuffer) {
15+
com.github.triniwiz.async.Async2.FileManager.writeFile(bytes.array(), path, listener);
16+
} else if (bytes instanceof ArrayBuffer) {
17+
if ((bytes as any).nativeObject) {
18+
com.github.triniwiz.async.Async2.FileManager.writeFile((bytes as any).nativeObject.array(), path, listener);
19+
}
20+
} else {
21+
com.github.triniwiz.async.Async2.FileManager.writeFile(bytes, path, listener);
22+
}
23+
24+
}
25+
26+
public static readFile(path: string, options: Options = {asStream: false}, callback: (...args) => void) {
27+
//const opts = new com.github.triniwiz.async.Async2.FileManager.Options();
28+
//opts.asStream = options.asStream;
29+
com.github.triniwiz.async.Async2.FileManager.readFile(path, null, new com.github.triniwiz.async.Async2.FileManager.Callback({
30+
onError(param0: string, param1: java.lang.Exception): void {
31+
callback(param0, null);
32+
},
33+
onComplete(param0: any): void {
34+
callback(null, param0);
35+
}
36+
}));
37+
}
38+
39+
public static deleteFile(path: string, options: Options = {asStream: false}, callback: (...args) => void) {
40+
// TODO
41+
callback(null, true);
42+
}
43+
}
44+
45+
export interface Options {
46+
asStream?: boolean;
47+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export interface Options {
2+
asStream?: boolean;
3+
}
4+
5+
export class FileManager {
6+
public static writeFile(bytes: any, path: string, callback: (...args) => void);
7+
8+
public static readFile(path: string, options: Options, callback: (...args) => void);
9+
10+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
const background_queue = dispatch_get_global_queue(qos_class_t.QOS_CLASS_DEFAULT, 0);
2+
const main_queue = dispatch_get_current_queue();
3+
export class FileManager {
4+
5+
public static writeFile(bytes: any, path: string, callback: (...args) => void) {
6+
dispatch_async(background_queue, () => {
7+
try {
8+
if (bytes instanceof NSData) {
9+
bytes.writeToFileAtomically(path, true);
10+
} else if (bytes instanceof ArrayBuffer) {
11+
NSData.dataWithData(bytes as any).writeToFileAtomically(path, true);
12+
}
13+
dispatch_async(main_queue, ()=>{
14+
callback(null, path);
15+
});
16+
} catch (e) {
17+
dispatch_async(main_queue, ()=>{
18+
callback(e, null);
19+
});
20+
}
21+
});
22+
}
23+
24+
public static readFile(path: string, options: Options = {asStream: false}, callback: (...args) => void) {
25+
dispatch_async(background_queue, () => {
26+
try {
27+
const data = NSData.dataWithContentsOfFile(path);
28+
dispatch_async(main_queue, ()=>{
29+
callback(null, data);
30+
});
31+
} catch (e) {
32+
dispatch_async(main_queue, ()=>{
33+
callback(e, null);
34+
});
35+
}
36+
});
37+
}
38+
39+
public static deleteFile(path: string, options: Options = {asStream: false}, callback: (...args) => void) {
40+
dispatch_async(background_queue, () => {
41+
try {
42+
NSFileManager.defaultManager.removeItemAtPathError(path);
43+
dispatch_async(main_queue, ()=>{
44+
callback(null, true);
45+
});
46+
} catch (e) {
47+
dispatch_async(main_queue, ()=>{
48+
callback(e, false);
49+
});
50+
}
51+
});
52+
}
53+
}
54+
55+
export interface Options {
56+
asStream?: boolean;
57+
}

0 commit comments

Comments
 (0)