Skip to content

Commit

Permalink
chore: updates
Browse files Browse the repository at this point in the history
  • Loading branch information
triniwiz committed Oct 10, 2023
1 parent ac4a1c4 commit 32c3011
Show file tree
Hide file tree
Showing 19 changed files with 402 additions and 266 deletions.
5 changes: 2 additions & 3 deletions packages/canvas-polyfill/async/file/file.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ export class FileManager {
//const opts = new com.github.triniwiz.async.Async2.FileManager.Options();
//opts.asStream = options.asStream;
if (this._readFile === undefined) {
//this._readFile = global?.CanvasModule?.readFile;
this._readFile = !!global?.CanvasModule?.readFile;
}
if (global?.CanvasModule?.readFile) {
global?.CanvasModule?.readFile(path, (error, buffer) => {
console.log(buffer);
global?.CanvasModule?.readFile(path, (error, buffer: ArrayBuffer) => {
if (error) {
callback(new Error(error), null);
} else {
Expand Down
9 changes: 9 additions & 0 deletions packages/canvas/Canvas/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,18 @@ export const ignorePixelScalingProperty = new Property<CanvasBase, boolean>({
valueConverter: booleanConverter,
});

export const upscaleProperty = new Property<CanvasBase, boolean>({
name: 'upscale',
defaultValue: false,
valueConverter: booleanConverter,
});

let pointerId = 0;
@CSSType('Canvas')
export abstract class CanvasBase extends View implements ICanvasBase {
public static readyEvent = 'ready';
ignorePixelScaling: boolean;
upscaleProperty: boolean;
_isCustom: boolean = false;

_classList: Set<any>;
Expand Down Expand Up @@ -693,3 +700,5 @@ export abstract class CanvasBase extends View implements ICanvasBase {
}

ignorePixelScalingProperty.register(CanvasBase);

upscaleProperty.register(CanvasBase);
6 changes: 5 additions & 1 deletion packages/canvas/Canvas/index.android.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CanvasBase, ignorePixelScalingProperty } from './common';
import { CanvasBase, ignorePixelScalingProperty, upscaleProperty } from './common';
import { DOMMatrix } from '../Canvas2D';
import { CanvasRenderingContext2D } from '../Canvas2D/CanvasRenderingContext2D';
import { WebGLRenderingContext } from '../WebGL/WebGLRenderingContext';
Expand Down Expand Up @@ -48,6 +48,10 @@ export class Canvas extends CanvasBase {
(global as any).__canvasLoaded = true;
}

[upscaleProperty.setNative](value: boolean) {
this._canvas.setUpscale(value);
}

[ignorePixelScalingProperty.setNative](value: boolean) {
this._canvas.setIgnorePixelScaling(value);
}
Expand Down
21 changes: 13 additions & 8 deletions packages/canvas/ImageBitmap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Canvas } from '../Canvas';
import { ImageSource } from '@nativescript/core';

import { Helpers } from '../helpers';

export class ImageBitmap {
static {
Helpers.initialize();
Expand Down Expand Up @@ -37,8 +38,10 @@ export class ImageBitmap {
}

static createFrom(source: any, options: any) {
return new Promise((resolve, reject) => {
return new Promise(function (resolve, reject) {
let realSource;
let isBuffer = false;
const id = Date.now();
if (source instanceof Canvas) {
realSource = (source as any).native;
} else if (source instanceof ImageBitmap) {
Expand All @@ -50,6 +53,7 @@ export class ImageBitmap {
} else if (source instanceof Blob) {
const bytes = (Blob as any).InternalAccessor.getBuffer(source) as Uint8Array;
realSource = bytes;
isBuffer = true;
} else if (source && typeof source === 'object' && typeof source.tagName === 'string') {
if (source.tagName === 'IMG' || source.tagName === 'IMAGE') {
realSource = source._asset.native;
Expand All @@ -62,18 +66,19 @@ export class ImageBitmap {
if (global.isAndroid) {
realSource = source.android; // todo
}

if (global.isIOS) {
realSource = source.ios; // todo
}
}

global.CanvasModule.createImageBitmap(realSource, options, (error, value) => {
if (value) {
resolve(ImageBitmap.fromNative(value));
} else {
reject(new Error(error));
}
setTimeout(() => {
global.CanvasModule.createImageBitmap(realSource, options, (error, value) => {
if (value) {
resolve(ImageBitmap.fromNative(value));
} else {
reject(new Error(error));
}
});
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/canvas/SVG/SVG.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class Svg extends View {
super();
if (global.isAndroid) {
const activity = Application.android.foregroundActivity || Application.android.startActivity;
this._svg = new org.nativescript.canvas.TNSSVG(activity);
this._svg = new org.nativescript.canvas.NSCSVG(activity);
} else if (global.isIOS) {
this._svg = TNSSVG.alloc().initWithFrame(CGRectZero);
this._svg.backgroundColor = UIColor.clearColor;
Expand Down
Binary file modified packages/canvas/platforms/android/canvas-release.aar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@



<!--<org.nativescript.canvas.TNSSVG-->
<!-- android:id="@+id/svgView"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="match_parent"-->
<!-- tools:layout_editor_absoluteX="8dp"-->
<!-- tools:layout_editor_absoluteY="8dp"-->
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
<!-- app:layout_constraintEnd_toEndOf="parent"-->
<!-- app:layout_constraintStart_toStartOf="parent"-->
<!-- app:layout_constraintTop_toTopOf="parent" />-->
<org.nativescript.canvas.NSCSVG
android:id="@+id/svgView"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />


</androidx.constraintlayout.widget.ConstraintLayout>
Loading

0 comments on commit 32c3011

Please sign in to comment.