@@ -37,23 +37,23 @@ function getSDK() {
37
37
return SDK_INT ;
38
38
}
39
39
40
- function createArrayBuffer ( length : number , useInts = false ) {
40
+ export function createArrayBuffer ( length : number , useInts = false ) {
41
41
let bb : java . nio . ByteBuffer ;
42
42
if ( useInts ) {
43
43
bb = java . nio . ByteBuffer . allocateDirect ( length ) ;
44
44
} else {
45
45
bb = java . nio . ByteBuffer . allocateDirect ( length * 4 ) . order ( java . nio . ByteOrder . LITTLE_ENDIAN ) ;
46
46
}
47
- // var bb = java.nio.ByteBuffer.allocateDirect(length * 4).order(java.nio.ByteOrder.LITTLE_ENDIAN);
48
47
const result = ( ArrayBuffer as any ) . from ( bb ) ;
49
- // result.bb = bb;
50
- return result ;
48
+ return useInts ? new Int8Array ( result ) : new Float32Array ( result ) ;
51
49
}
52
- function pointsFromBuffer ( buffer : ArrayBuffer , useInts = false ) {
50
+ export function pointsFromBuffer ( typedArray : Float32Array | Int8Array , useInts = false ) {
53
51
if ( useInts ) {
52
+ const buffer = typedArray . buffer ;
54
53
return ( ( buffer as any ) . nativeObject as java . nio . ByteBuffer ) . array ( ) ;
55
54
}
56
- const length = buffer . byteLength / 4 ;
55
+ const buffer = typedArray . buffer ;
56
+ const length = typedArray . length ;
57
57
const testArray = Array . create ( 'float' , length ) ;
58
58
( ( buffer as any ) . nativeObject as java . nio . ByteBuffer ) . asFloatBuffer ( ) . get ( testArray , 0 , length ) ;
59
59
return testArray as number [ ] ;
@@ -64,11 +64,9 @@ export function arrayToNativeArray(array, useInts = false) {
64
64
return array ;
65
65
}
66
66
const length = array . length ;
67
- const buffer = createArrayBuffer ( length , useInts ) ;
68
- const arrayBuffer = useInts ? new Int8Array ( buffer ) : new Float32Array ( buffer ) ;
69
- arrayBuffer . set ( array ) ;
67
+ const typedArray = createArrayBuffer ( length , useInts ) ;
70
68
71
- return pointsFromBuffer ( buffer , useInts ) ;
69
+ return pointsFromBuffer ( typedArray , useInts ) ;
72
70
}
73
71
74
72
export function parseDashEffect ( value : string ) {
@@ -226,7 +224,7 @@ export class Paint {
226
224
native . setLinearText ( true ) ; // ensure we are drawing fonts correctly
227
225
return new Proxy ( this , {
228
226
get ( target , name , receiver ) {
229
- if ( native [ name ] ) {
227
+ if ( native && native [ name ] ) {
230
228
return function ( ...args ) {
231
229
const methodName = name ;
232
230
for ( let index = 0 ; index < args . length ; index ++ ) {
@@ -372,7 +370,7 @@ export class DashPathEffect {
372
370
}
373
371
get ( target , name , receiver ) {
374
372
const native = this . _native ;
375
- if ( native [ name ] ) {
373
+ if ( native && native [ name ] ) {
376
374
return function ( ...args ) {
377
375
const methodName = name ;
378
376
return native [ methodName ] ( ...args ) ;
@@ -394,7 +392,7 @@ export class Path {
394
392
}
395
393
get ( target , name , receiver ) {
396
394
const native = this . _native ;
397
- if ( native [ name ] ) {
395
+ if ( native && native [ name ] ) {
398
396
return function ( ...args ) {
399
397
const methodName = name ;
400
398
for ( let index = 0 ; index < args . length ; index ++ ) {
@@ -423,7 +421,7 @@ export class RadialGradient {
423
421
}
424
422
get ( target , name , receiver ) {
425
423
const native = this . _native ;
426
- if ( native [ name ] ) {
424
+ if ( native && native [ name ] ) {
427
425
return function ( ...args ) {
428
426
const methodName = name ;
429
427
return native [ methodName ] ( ...args ) ;
@@ -463,7 +461,7 @@ export class LinearGradient {
463
461
}
464
462
get ( target , name , receiver ) {
465
463
const native = this . _native ;
466
- if ( native [ name ] ) {
464
+ if ( native && native [ name ] ) {
467
465
return function ( ...args ) {
468
466
const methodName = name ;
469
467
return native [ methodName ] ( ...args ) ;
@@ -488,7 +486,7 @@ export class BitmapShader {
488
486
}
489
487
get ( target , name , receiver ) {
490
488
const native = this . _native ;
491
- if ( native [ name ] ) {
489
+ if ( native && native [ name ] ) {
492
490
return function ( ...args ) {
493
491
const methodName = name ;
494
492
return native [ methodName ] ( ...args ) ;
@@ -517,7 +515,7 @@ export class StaticLayout {
517
515
}
518
516
get ( target , name , receiver ) {
519
517
const native = this . _native ;
520
- if ( native [ name ] ) {
518
+ if ( native && native [ name ] ) {
521
519
return function ( ...args ) {
522
520
const methodName = name ;
523
521
for ( let index = 0 ; index < args . length ; index ++ ) {
0 commit comments