@@ -5,6 +5,7 @@ import * as app from '@nativescript/core/application';
55import * as TKUnit from '../tk-unit' ;
66import { Font } from '@nativescript/core/ui/styling/font' ;
77import { Color } from '@nativescript/core/color' ;
8+ import * as utils from '@nativescript/core/utils' ;
89
910const imagePath = '~/assets/logo.png' ;
1011const splashscreenPath = '~/assets/splashscreen.png' ;
@@ -20,6 +21,36 @@ export function testFromResource() {
2021 TKUnit . assert ( img . height > 0 , 'image.fromResource failed' ) ;
2122}
2223
24+ export function testDrawableSetNativeSource ( ) {
25+ if ( global . isAndroid ) {
26+ const context = utils . ad . getApplicationContext ( ) as android . content . Context ;
27+ const rDrawable = `${ context . getPackageName ( ) } .R$drawable` ;
28+ const rClazz = java . lang . Class . forName ( `${ rDrawable } ` ) ;
29+ const iconId = rClazz . getDeclaredField ( 'icon' ) . get ( null ) as java . lang . Integer ;
30+ const splashScreenId = rClazz . getDeclaredField ( 'splash_screen' ) . get ( null ) as java . lang . Integer ;
31+
32+ const icon = androidx . appcompat . content . res . AppCompatResources . getDrawable ( context , iconId ?. intValue ?.( ) ?? 0 ) ;
33+ const splashScreen = androidx . appcompat . content . res . AppCompatResources . getDrawable ( context , splashScreenId ?. intValue ?.( ) ?? 0 ) ;
34+
35+ let type = icon ?. getClass ?.( ) . toString ?.( ) ?? '' ;
36+
37+ // >> imagesource-setNativeSource
38+ const img = new ImageSource ( ) ;
39+ img . setNativeSource ( icon ) ;
40+ // << imagesource-setNativeSource
41+
42+ TKUnit . assert ( img . height > 0 , `image ${ type } setNativeSource failed` ) ;
43+
44+ type = splashScreen ?. getClass ?.( ) . toString ?.( ) ?? '' ;
45+
46+ // >> imagesource-setNativeSource
47+ img . setNativeSource ( splashScreen ) ;
48+ // << imagesource-setNativeSource
49+
50+ TKUnit . assert ( img . height > 0 , `image ${ type } setNativeSource failed` ) ;
51+ }
52+ }
53+
2354export function testFromUrl ( done ) {
2455 let result : ImageSource ;
2556
0 commit comments