mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 04:41:36 +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,23 +375,31 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
var drawable: android.graphics.drawable.BitmapDrawable;
|
if (iconSource.indexOf(RESOURCE_PREFIX) === 0 && resources) {
|
||||||
drawable = this._iconsCache[iconSource];
|
var resourceId: number = resources.getIdentifier(iconSource.substr(RESOURCE_PREFIX.length), 'drawable', packageName);
|
||||||
if (!drawable) {
|
if (resourceId > 0) {
|
||||||
var is = imageSource.fromFileOrResource(iconSource);
|
tab.setIcon(resourceId);
|
||||||
if (is) {
|
|
||||||
drawable = new android.graphics.drawable.BitmapDrawable(is.android);
|
|
||||||
this._iconsCache[iconSource] = drawable;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
if (drawable) {
|
var drawable: android.graphics.drawable.BitmapDrawable;
|
||||||
tab.setIcon(drawable);
|
drawable = this._iconsCache[iconSource];
|
||||||
|
if (!drawable) {
|
||||||
|
var is = imageSource.fromFileOrResource(iconSource);
|
||||||
|
if (is) {
|
||||||
|
drawable = new android.graphics.drawable.BitmapDrawable(is.android);
|
||||||
|
this._iconsCache[iconSource] = drawable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (drawable) {
|
||||||
|
tab.setIcon(drawable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user