@@ -3,7 +3,7 @@ import { FontStyle, FontWeight } from '@nativescript/core/ui/styling/font';
33import { android as androidApp } from '@nativescript/core/application' ;
44import lazy from '@nativescript/core/utils/lazy' ;
55import { layout } from '@nativescript/core/utils/utils' ;
6- import { Canvas as ICanvas , Paint as IPaint } from './canvas' ;
6+ import { Canvas as ICanvas , Paint as IPaint , TypedArray } from './canvas' ;
77import { CanvasBase , hardwareAcceleratedProperty } from './canvas.common' ;
88
99declare global {
@@ -60,7 +60,7 @@ export function createArrayBufferOrNativeArray(length: number, useInts = false)
6060 return createArrayBuffer ( length , useInts ) ;
6161 }
6262}
63- export function createArrayBuffer ( length : number , useInts = false ) {
63+ export function createArrayBuffer ( length : number , useInts = false ) : TypedArray {
6464 if ( ! supportsDirectArrayBuffers ( ) ) {
6565 let bb : java . nio . ByteBuffer ;
6666 if ( useInts ) {
@@ -69,11 +69,13 @@ export function createArrayBuffer(length: number, useInts = false) {
6969 bb = java . nio . ByteBuffer . allocateDirect ( length * 4 ) . order ( java . nio . ByteOrder . LITTLE_ENDIAN ) ;
7070 }
7171 const result = ( ArrayBuffer as any ) . from ( bb ) ;
72+ //@ts -ignore
7273 return useInts ? new Int8Array ( result ) : new Float32Array ( result ) ;
7374 }
75+ //@ts -ignore
7476 return useInts ? new Int8Array ( length ) : new Float32Array ( length ) ;
7577}
76- export function pointsFromBuffer ( typedArray : Float32Array | Int8Array , useInts = false ) {
78+ export function pointsFromBuffer ( typedArray : TypedArray , useInts = false ) {
7779 if ( ! supportsDirectArrayBuffers ( ) ) {
7880 if ( useInts ) {
7981 const buffer = typedArray . buffer ;
@@ -88,12 +90,12 @@ export function pointsFromBuffer(typedArray: Float32Array | Int8Array, useInts =
8890 return typedArray ;
8991}
9092
91- export function arrayToNativeArray ( array , useInts = false ) {
93+ export function arrayToNativeArray ( array : number [ ] | TypedArray , useInts = false ) {
9294 if ( ! Array . isArray ( array ) ) {
9395 return array ;
9496 }
9597 const length = array . length ;
96- const typedArray = createArrayBuffer ( length , useInts ) ;
98+ const typedArray = ArrayBuffer . isView ( array ) ? ( array as any as TypedArray ) : createArrayBuffer ( length , useInts ) ;
9799
98100 return pointsFromBuffer ( typedArray , useInts ) ;
99101}
@@ -289,7 +291,7 @@ export class Paint extends ProxyClass<android.graphics.Paint> {
289291 if ( paint ) {
290292 this . mNative = new android . graphics . Paint ( paint . getNative ( ) ) ;
291293 } else {
292- this . mNative = new android . graphics . Paint ( 1 ) ; //android.graphics.Paint.ANTI_ALIAS_FLAG
294+ this . mNative = new android . graphics . Paint ( 1 ) ; //android.graphics.Paint.ANTI_ALIAS_FLAG
293295 }
294296 this . mNative . setLinearText ( true ) ; // ensure we are drawing fonts correctly
295297 return this ;
0 commit comments