1
- import { AndroidActionBarSettings as AndroidActionBarSettingsDefinition , AndroidActionItemSettings } from "." ;
1
+ import { AndroidActionItemSettings , AndroidActionBarSettings as AndroidActionBarSettingsDefinition , ActionItem as ActionItemDefinition } from "." ;
2
2
import {
3
3
ActionItemBase , ActionBarBase , isVisible ,
4
4
View , layout , colorProperty , flatProperty , Color ,
5
- traceMissingIcon , androidContentInsetLeftProperty , androidContentInsetRightProperty , Length
5
+ traceMissingIcon , androidContentInsetLeftProperty , androidContentInsetRightProperty
6
6
} from "./action-bar-common" ;
7
7
import { RESOURCE_PREFIX , isFontIconURI } from "../../utils/utils" ;
8
8
import { fromFileOrResource , fromFontIconCode } from "../../image-source" ;
@@ -22,6 +22,31 @@ function generateItemId(): number {
22
22
return actionItemIdGenerator ;
23
23
}
24
24
25
+ function loadActionIconDrawableOrResourceId ( item : ActionItemDefinition ) : any {
26
+ const itemIcon = item . icon ;
27
+ const itemStyle = item . style ;
28
+ let drawableOrId = null ;
29
+
30
+ if ( isFontIconURI ( itemIcon ) ) {
31
+ const fontIconCode = itemIcon . split ( "//" ) [ 1 ] ;
32
+ const font = itemStyle . fontInternal ;
33
+ const color = itemStyle . color ;
34
+ const is = fromFontIconCode ( fontIconCode , font , color ) ;
35
+
36
+ if ( is && is . android ) {
37
+ drawableOrId = new android . graphics . drawable . BitmapDrawable ( appResources , is . android ) ;
38
+ }
39
+ } else {
40
+ drawableOrId = getDrawableOrResourceId ( itemIcon , appResources ) ;
41
+ }
42
+
43
+ if ( ! drawableOrId ) {
44
+ traceMissingIcon ( itemIcon ) ;
45
+ }
46
+
47
+ return drawableOrId ;
48
+ }
49
+
25
50
interface MenuItemClickListener {
26
51
new ( owner : ActionBar ) : androidx . appcompat . widget . Toolbar . OnMenuItemClickListener ;
27
52
}
@@ -231,21 +256,9 @@ export class ActionBar extends ActionBarBase {
231
256
}
232
257
}
233
258
else if ( navButton . icon ) {
234
- if ( isFontIconURI ( navButton . icon ) ) {
235
- const fontIconCode = navButton . icon . split ( "//" ) [ 1 ] ;
236
- const font = navButton . style . fontInternal ;
237
- const color = navButton . style . color ;
238
- const is = fromFontIconCode ( fontIconCode , font , color ) ;
239
-
240
- if ( is && is . android ) {
241
- const drawable = new android . graphics . drawable . BitmapDrawable ( appResources , is . android ) ;
242
- this . nativeViewProtected . setNavigationIcon ( drawable ) ;
243
- }
244
- } else {
245
- let drawableOrId = getDrawableOrResourceId ( navButton . icon , appResources ) ;
246
- if ( drawableOrId ) {
247
- this . nativeViewProtected . setNavigationIcon ( drawableOrId ) ;
248
- }
259
+ const drawableOrId = loadActionIconDrawableOrResourceId ( navButton ) ;
260
+ if ( drawableOrId ) {
261
+ this . nativeViewProtected . setNavigationIcon ( drawableOrId ) ;
249
262
}
250
263
}
251
264
@@ -275,6 +288,8 @@ export class ActionBar extends ActionBarBase {
275
288
let drawableOrId = getDrawableOrResourceId ( icon , appResources ) ;
276
289
if ( drawableOrId ) {
277
290
this . nativeViewProtected . setLogo ( drawableOrId ) ;
291
+ } else {
292
+ traceMissingIcon ( icon ) ;
278
293
}
279
294
}
280
295
else {
@@ -327,21 +342,9 @@ export class ActionBar extends ActionBarBase {
327
342
}
328
343
}
329
344
else if ( item . icon ) {
330
- if ( isFontIconURI ( item . icon ) ) {
331
- const fontIconCode = item . icon . split ( "//" ) [ 1 ] ;
332
- const font = item . style . fontInternal ;
333
- const color = item . style . color ;
334
- const is = fromFontIconCode ( fontIconCode , font , color ) ;
335
-
336
- if ( is && is . android ) {
337
- const drawable = new android . graphics . drawable . BitmapDrawable ( appResources , is . android ) ;
338
- menuItem . setIcon ( drawable ) ;
339
- }
340
- } else {
341
- let drawableOrId = getDrawableOrResourceId ( item . icon , appResources ) ;
342
- if ( drawableOrId ) {
343
- menuItem . setIcon ( drawableOrId ) ;
344
- }
345
+ const drawableOrId = loadActionIconDrawableOrResourceId ( item ) ;
346
+ if ( drawableOrId ) {
347
+ menuItem . setIcon ( drawableOrId ) ;
345
348
}
346
349
}
347
350
@@ -468,10 +471,10 @@ let defaultTitleTextColor: number;
468
471
469
472
function getDrawableOrResourceId ( icon : string , resources : android . content . res . Resources ) : any {
470
473
if ( typeof icon !== "string" ) {
471
- return undefined ;
474
+ return null ;
472
475
}
473
476
474
- let result = undefined ;
477
+ let result = null ;
475
478
if ( icon . indexOf ( RESOURCE_PREFIX ) === 0 ) {
476
479
let resourceId : number = resources . getIdentifier ( icon . substr ( RESOURCE_PREFIX . length ) , "drawable" , application . android . packageName ) ;
477
480
if ( resourceId > 0 ) {
@@ -480,7 +483,6 @@ function getDrawableOrResourceId(icon: string, resources: android.content.res.Re
480
483
}
481
484
else {
482
485
let drawable : android . graphics . drawable . BitmapDrawable ;
483
-
484
486
let is = fromFileOrResource ( icon ) ;
485
487
if ( is ) {
486
488
drawable = new android . graphics . drawable . BitmapDrawable ( appResources , is . android ) ;
@@ -489,10 +491,6 @@ function getDrawableOrResourceId(icon: string, resources: android.content.res.Re
489
491
result = drawable ;
490
492
}
491
493
492
- if ( ! result ) {
493
- traceMissingIcon ( icon ) ;
494
- }
495
-
496
494
return result ;
497
495
}
498
496
0 commit comments