1- import { AndroidActionBarSettings as AndroidActionBarSettingsDefinition , AndroidActionItemSettings } from "." ;
1+ import { AndroidActionItemSettings , AndroidActionBarSettings as AndroidActionBarSettingsDefinition , ActionItem as ActionItemDefinition } from "." ;
22import {
33 ActionItemBase , ActionBarBase , isVisible ,
44 View , layout , colorProperty , flatProperty , Color ,
5- traceMissingIcon , androidContentInsetLeftProperty , androidContentInsetRightProperty , Length
5+ traceMissingIcon , androidContentInsetLeftProperty , androidContentInsetRightProperty
66} from "./action-bar-common" ;
77import { RESOURCE_PREFIX , isFontIconURI } from "../../utils/utils" ;
88import { fromFileOrResource , fromFontIconCode } from "../../image-source" ;
@@ -22,6 +22,31 @@ function generateItemId(): number {
2222 return actionItemIdGenerator ;
2323}
2424
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+
2550interface MenuItemClickListener {
2651 new ( owner : ActionBar ) : androidx . appcompat . widget . Toolbar . OnMenuItemClickListener ;
2752}
@@ -231,21 +256,9 @@ export class ActionBar extends ActionBarBase {
231256 }
232257 }
233258 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 ) ;
249262 }
250263 }
251264
@@ -275,6 +288,8 @@ export class ActionBar extends ActionBarBase {
275288 let drawableOrId = getDrawableOrResourceId ( icon , appResources ) ;
276289 if ( drawableOrId ) {
277290 this . nativeViewProtected . setLogo ( drawableOrId ) ;
291+ } else {
292+ traceMissingIcon ( icon ) ;
278293 }
279294 }
280295 else {
@@ -327,21 +342,9 @@ export class ActionBar extends ActionBarBase {
327342 }
328343 }
329344 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 ) ;
345348 }
346349 }
347350
@@ -468,10 +471,10 @@ let defaultTitleTextColor: number;
468471
469472function getDrawableOrResourceId ( icon : string , resources : android . content . res . Resources ) : any {
470473 if ( typeof icon !== "string" ) {
471- return undefined ;
474+ return null ;
472475 }
473476
474- let result = undefined ;
477+ let result = null ;
475478 if ( icon . indexOf ( RESOURCE_PREFIX ) === 0 ) {
476479 let resourceId : number = resources . getIdentifier ( icon . substr ( RESOURCE_PREFIX . length ) , "drawable" , application . android . packageName ) ;
477480 if ( resourceId > 0 ) {
@@ -480,7 +483,6 @@ function getDrawableOrResourceId(icon: string, resources: android.content.res.Re
480483 }
481484 else {
482485 let drawable : android . graphics . drawable . BitmapDrawable ;
483-
484486 let is = fromFileOrResource ( icon ) ;
485487 if ( is ) {
486488 drawable = new android . graphics . drawable . BitmapDrawable ( appResources , is . android ) ;
@@ -489,10 +491,6 @@ function getDrawableOrResourceId(icon: string, resources: android.content.res.Re
489491 result = drawable ;
490492 }
491493
492- if ( ! result ) {
493- traceMissingIcon ( icon ) ;
494- }
495-
496494 return result ;
497495}
498496
0 commit comments