mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 12:57:42 +08:00
Merge pull request #97 from NativeScript/tab-icons
Fixed: TabViewItem does not get the right resource image #91
This commit is contained in:
@ -5,8 +5,10 @@ import view = require("ui/core/view");
|
|||||||
import trace = require("trace");
|
import trace = require("trace");
|
||||||
import imageSource = require("image-source");
|
import imageSource = require("image-source");
|
||||||
import types = require("utils/types");
|
import types = require("utils/types");
|
||||||
|
import app = require("application");
|
||||||
|
|
||||||
var VIEWS_STATES = "_viewStates";
|
var VIEWS_STATES = "_viewStates";
|
||||||
|
var RESOURCE_PREFIX = "res://";
|
||||||
|
|
||||||
// merge the exports of the common file with the exports of this file
|
// merge the exports of the common file with the exports of this file
|
||||||
declare var exports;
|
declare var exports;
|
||||||
@ -357,12 +359,13 @@ export class TabView extends common.TabView {
|
|||||||
var length = newItems.length;
|
var length = newItems.length;
|
||||||
var item: definition.TabViewItem;
|
var item: definition.TabViewItem;
|
||||||
var tab: android.app.ActionBar.Tab;
|
var tab: android.app.ActionBar.Tab;
|
||||||
|
var androidApp = app.android;
|
||||||
|
var resources = androidApp.context.getResources();
|
||||||
for (i; i < length; i++) {
|
for (i; i < length; i++) {
|
||||||
item = newItems[i];
|
item = newItems[i];
|
||||||
tab = actionBar.newTab();
|
tab = actionBar.newTab();
|
||||||
tab.setText(item.title);
|
tab.setText(item.title);
|
||||||
this._setIcon(item.iconSource, tab);
|
this._setIcon(item.iconSource, tab, resources, androidApp.packageName);
|
||||||
|
|
||||||
tab.setTabListener(this._tabListener);
|
tab.setTabListener(this._tabListener);
|
||||||
|
|
||||||
@ -372,11 +375,18 @@ export class TabView extends common.TabView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _setIcon(iconSource: string, tab: android.app.ActionBar.Tab): void {
|
private _setIcon(iconSource: string, tab: android.app.ActionBar.Tab, resources: android.content.res.Resources, packageName: string): void {
|
||||||
if (!iconSource) {
|
if (!iconSource) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (iconSource.indexOf(RESOURCE_PREFIX) === 0 && resources) {
|
||||||
|
var resourceId: number = resources.getIdentifier(iconSource.substr(RESOURCE_PREFIX.length), 'drawable', packageName);
|
||||||
|
if (resourceId > 0) {
|
||||||
|
tab.setIcon(resourceId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
var drawable: android.graphics.drawable.BitmapDrawable;
|
var drawable: android.graphics.drawable.BitmapDrawable;
|
||||||
drawable = this._iconsCache[iconSource];
|
drawable = this._iconsCache[iconSource];
|
||||||
if (!drawable) {
|
if (!drawable) {
|
||||||
@ -391,6 +401,7 @@ export class TabView extends common.TabView {
|
|||||||
tab.setIcon(drawable);
|
tab.setIcon(drawable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public _removeTabs(oldItems: Array<definition.TabViewItem>) {
|
public _removeTabs(oldItems: Array<definition.TabViewItem>) {
|
||||||
trace.write("TabView._removeTabs(" + oldItems + ");", common.traceCategory);
|
trace.write("TabView._removeTabs(" + oldItems + ");", common.traceCategory);
|
||||||
|
Reference in New Issue
Block a user