| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,7 +9,13 @@ import { profile } from "../../profiling"; | |||
| 9 | 9 | ||
| 10 | 10 | export * from "../core/view"; | |
| 11 | 11 | ||
| 12 | - import { View, ViewBase, Property, unsetValue, booleanConverter, horizontalAlignmentProperty, verticalAlignmentProperty, CSSType } from "../core/view"; | ||
| 12 | + import { | ||
| 13 | + View, ViewBase, Property, | ||
| 14 | + unsetValue, booleanConverter, | ||
| 15 | + horizontalAlignmentProperty, | ||
| 16 | + verticalAlignmentProperty, CSSType, | ||
| 17 | + traceWrite, traceCategories, traceMessageType | ||
| 18 | + } from "../core/view"; | ||
| 13 | 19 | ||
| 14 | 20 | export module knownCollections { | |
| 15 | 21 | export var actionItems = "actionItems"; | |
@@ -334,6 +340,12 @@ function onVisibilityChanged(item: ActionItemBase, oldValue: string, newValue: s | |||
| 334 | 340 | item._onVisibilityChanged(newValue); | |
| 335 | 341 | } | |
| 336 | 342 | ||
| 343 | + export function traceMissingIcon(icon: string) { | ||
| 344 | + traceWrite("Could not load action bar icon: " + icon, | ||
| 345 | + traceCategories.Error, | ||
| 346 | + traceMessageType.error); | ||
| 347 | + } | ||
| 348 | + | ||
| 337 | 349 | export const textProperty = new Property<ActionItemBase, string>({ name: "text", defaultValue: "", valueChanged: onItemChanged }); | |
| 338 | 350 | textProperty.register(ActionItemBase); | |
| 339 | 351 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,9 @@ | |||
| 1 | 1 | import { AndroidActionBarSettings as AndroidActionBarSettingsDefinition, AndroidActionItemSettings } from "."; | |
| 2 | - import { ActionItemBase, ActionBarBase, isVisible, View, layout, colorProperty, flatProperty, Color } from "./action-bar-common"; | ||
| 2 | + import { | ||
| 3 | + ActionItemBase, ActionBarBase, isVisible, | ||
| 4 | + View, layout, colorProperty, flatProperty, | ||
| 5 | + Color, traceMissingIcon | ||
| 6 | + } from "./action-bar-common"; | ||
| 3 | 7 | import { RESOURCE_PREFIX } from "../../utils/utils"; | |
| 4 | 8 | import { fromFileOrResource } from "../../image-source"; | |
| 5 | 9 | import * as application from "../../application"; | |
@@ -18,7 +22,7 @@ function generateItemId(): number { | |||
| 18 | 22 | } | |
| 19 | 23 | ||
| 20 | 24 | interface MenuItemClickListener { | |
| 21 | - new (owner: ActionBar): android.support.v7.widget.Toolbar.OnMenuItemClickListener; | ||
| 25 | + new(owner: ActionBar): android.support.v7.widget.Toolbar.OnMenuItemClickListener; | ||
| 22 | 26 | } | |
| 23 | 27 | ||
| 24 | 28 | let appResources: android.content.res.Resources; | |
@@ -219,7 +223,9 @@ export class ActionBar extends ActionBarBase { | |||
| 219 | 223 | } | |
| 220 | 224 | else if (navButton.icon) { | |
| 221 | 225 | let drawableOrId = getDrawableOrResourceId(navButton.icon, appResources); | |
| 222 | - this.nativeViewProtected.setNavigationIcon(drawableOrId); | ||
| 226 | + if (drawableOrId) { | ||
| 227 | + this.nativeViewProtected.setNavigationIcon(drawableOrId); | ||
| 228 | + } | ||
| 223 | 229 | } | |
| 224 | 230 | ||
| 225 | 231 | // Set navigation content descripion, used by screen readers for the vision-impaired users | |
@@ -304,9 +310,6 @@ export class ActionBar extends ActionBarBase { | |||
| 304 | 310 | if (drawableOrId) { | |
| 305 | 311 | menuItem.setIcon(drawableOrId); | |
| 306 | 312 | } | |
| 307 | - else { | ||
| 308 | - throw new Error("Error loading icon from " + item.icon); | ||
| 309 | - } | ||
| 310 | 313 | } | |
| 311 | 314 | ||
| 312 | 315 | let showAsAction = getShowAsAction(item); | |
@@ -422,10 +425,11 @@ function getDrawableOrResourceId(icon: string, resources: android.content.res.Re | |||
| 422 | 425 | return undefined; | |
| 423 | 426 | } | |
| 424 | 427 | ||
| 428 | + let result = undefined; | ||
| 425 | 429 | if (icon.indexOf(RESOURCE_PREFIX) === 0) { | |
| 426 | 430 | let resourceId: number = resources.getIdentifier(icon.substr(RESOURCE_PREFIX.length), "drawable", application.android.packageName); | |
| 427 | 431 | if (resourceId > 0) { | |
| 428 | - return resourceId; | ||
| 432 | + result = resourceId; | ||
| 429 | 433 | } | |
| 430 | 434 | } | |
| 431 | 435 | else { | |
@@ -436,10 +440,14 @@ function getDrawableOrResourceId(icon: string, resources: android.content.res.Re | |||
| 436 | 440 | drawable = new android.graphics.drawable.BitmapDrawable(is.android); | |
| 437 | 441 | } | |
| 438 | 442 | ||
| 439 | - return drawable; | ||
| 443 | + result = drawable; | ||
| 444 | + } | ||
| 445 | + | ||
| 446 | + if (!result) { | ||
| 447 | + traceMissingIcon(icon); | ||
| 440 | 448 | } | |
| 441 | 449 | ||
| 442 | - return undefined; | ||
| 450 | + return result; | ||
| 443 | 451 | } | |
| 444 | 452 | ||
| 445 | 453 | function getShowAsAction(menuItem: ActionItem): number { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,13 +1,28 @@ | |||
| 1 | 1 | import { IOSActionItemSettings, ActionItem as ActionItemDefinition } from "."; | |
| 2 | - import { ActionItemBase, ActionBarBase, isVisible, View, colorProperty, backgroundColorProperty, backgroundInternalProperty, flatProperty, layout, Color } from "./action-bar-common"; | ||
| 3 | - import { ImageSource, fromFileOrResource } from "../../image-source"; | ||
| 2 | + import { | ||
| 3 | + ActionItemBase, ActionBarBase, isVisible, View, | ||
| 4 | + colorProperty, backgroundColorProperty, | ||
| 5 | + backgroundInternalProperty, flatProperty, | ||
| 6 | + layout, Color, traceMissingIcon } from "./action-bar-common"; | ||
| 7 | + import { fromFileOrResource } from "../../image-source"; | ||
| 4 | 8 | import { ios as iosUtils } from "../../utils/utils"; | |
| 9 | + import { write as traceWrite, categories, messageType } from "../../trace"; | ||
| 5 | 10 | ||
| 6 | 11 | export * from "./action-bar-common"; | |
| 7 | 12 | ||
| 8 | 13 | const majorVersion = iosUtils.MajorVersion; | |
| 9 | 14 | const UNSPECIFIED = layout.makeMeasureSpec(0, layout.UNSPECIFIED); | |
| 10 | 15 | ||
| 16 | + function loadActionIconFromFileOrResource(icon: string): UIImage { | ||
| 17 | + const img = fromFileOrResource(icon); | ||
| 18 | + if (img && img.ios) { | ||
| 19 | + return img.ios; | ||
| 20 | + } else { | ||
| 21 | + traceMissingIcon(icon); | ||
| 22 | + return null; | ||
| 23 | + } | ||
| 24 | + } | ||
| 25 | + | ||
| 11 | 26 | class TapBarItemHandlerImpl extends NSObject { | |
| 12 | 27 | private _owner: WeakRef<ActionItemDefinition>; | |
| 13 | 28 | ||
@@ -151,16 +166,16 @@ export class ActionBar extends ActionBarBase { | |||
| 151 | 166 | } | |
| 152 | 167 | ||
| 153 | 168 | // Set back button image | |
| 154 | - let img: ImageSource; | ||
| 169 | + let img: UIImage; | ||
| 155 | 170 | if (this.navigationButton && isVisible(this.navigationButton) && this.navigationButton.icon) { | |
| 156 | - img = fromFileOrResource(this.navigationButton.icon); | ||
| 171 | + img = loadActionIconFromFileOrResource(this.navigationButton.icon); | ||
| 157 | 172 | } | |
| 158 | 173 | ||
| 159 | 174 | // TODO: This could cause issue when canceling BackEdge gesture - we will change the backIndicator to | |
| 160 | 175 | // show the one from the old page but the new page will still be visible (because we canceled EdgeBackSwipe gesutre) | |
| 161 | 176 | // Consider moving this to new method and call it from - navigationControllerDidShowViewControllerAnimated. | |
| 162 | - if (img && img.ios) { | ||
| 163 | - let image = img.ios.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal); | ||
| 177 | + if (img) { | ||
| 178 | + let image = img.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal); | ||
| 164 | 179 | navigationBar.backIndicatorImage = image; | |
| 165 | 180 | navigationBar.backIndicatorTransitionMaskImage = image; | |
| 166 | 181 | } else { | |
@@ -226,12 +241,8 @@ export class ActionBar extends ActionBarBase { | |||
| 226 | 241 | ||
| 227 | 242 | barButtonItem = UIBarButtonItem.alloc().initWithBarButtonSystemItemTargetAction(id, tapHandler, "tap"); | |
| 228 | 243 | } else if (item.icon) { | |
| 229 | - const img = fromFileOrResource(item.icon); | ||
| 230 | - if (img && img.ios) { | ||
| 231 | - barButtonItem = UIBarButtonItem.alloc().initWithImageStyleTargetAction(img.ios, UIBarButtonItemStyle.Plain, tapHandler, "tap"); | ||
| 232 | - } else { | ||
| 233 | - throw new Error("Error loading icon from " + item.icon); | ||
| 234 | - } | ||
| 244 | + const img = loadActionIconFromFileOrResource(item.icon); | ||
| 245 | + barButtonItem = UIBarButtonItem.alloc().initWithImageStyleTargetAction(img, UIBarButtonItemStyle.Plain, tapHandler, "tap"); | ||
| 235 | 246 | } else { | |
| 236 | 247 | barButtonItem = UIBarButtonItem.alloc().initWithTitleStyleTargetAction(item.text + "", UIBarButtonItemStyle.Plain, tapHandler, "tap"); | |
| 237 | 248 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,8 @@ | |||
| 1 | 1 | import { TabView as TabViewDefinition, TabViewItem as TabViewItemDefinition, SelectedIndexChangedEventData } from "."; | |
| 2 | 2 | import { | |
| 3 | 3 | View, ViewBase, Style, Property, CssProperty, CoercibleProperty, | |
| 4 | - Color, isIOS, AddArrayFromBuilder, AddChildFromBuilder, EventData, CSSType | ||
| 4 | + Color, isIOS, AddArrayFromBuilder, AddChildFromBuilder, EventData, CSSType, | ||
| 5 | + traceWrite, traceCategories, traceMessageType | ||
| 5 | 6 | } from "../core/view"; | |
| 6 | 7 | ||
| 7 | 8 | export * from "../core/view"; | |
@@ -203,6 +204,10 @@ export interface TabViewBase { | |||
| 203 | 204 | on(event: "selectedIndexChanged", callback: (args: SelectedIndexChangedEventData) => void, thisArg?: any); | |
| 204 | 205 | } | |
| 205 | 206 | ||
| 207 | + export function traceMissingIcon(icon: string) { | ||
| 208 | + traceWrite("Could not load tab bar icon: " + icon, traceCategories.Error, traceMessageType.error); | ||
| 209 | + } | ||
| 210 | + | ||
| 206 | 211 | export const selectedIndexProperty = new CoercibleProperty<TabViewBase, number>({ | |
| 207 | 212 | name: "selectedIndex", defaultValue: -1, affectsLayout: isIOS, | |
| 208 | 213 | valueChanged: (target, oldValue, newValue) => { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,7 +6,7 @@ import { | |||
| 6 | 6 | tabTextColorProperty, tabBackgroundColorProperty, tabTextFontSizeProperty, selectedTabTextColorProperty, | |
| 7 | 7 | androidSelectedTabHighlightColorProperty, androidOffscreenTabLimitProperty, | |
| 8 | 8 | fontSizeProperty, fontInternalProperty, layout, traceCategory, traceEnabled, | |
| 9 | - traceWrite, Color | ||
| 9 | + traceWrite, Color, traceMissingIcon | ||
| 10 | 10 | } from "./tab-view-common" | |
| 11 | 11 | import { textTransformProperty, TextTransform, getTransformedText } from "../text-base"; | |
| 12 | 12 | import { fromFileOrResource } from "../../image-source"; | |
@@ -233,11 +233,16 @@ function createTabItemSpec(item: TabViewItem): org.nativescript.widgets.TabItemS | |||
| 233 | 233 | if (item.iconSource) { | |
| 234 | 234 | if (item.iconSource.indexOf(RESOURCE_PREFIX) === 0) { | |
| 235 | 235 | result.iconId = ad.resources.getDrawableId(item.iconSource.substr(RESOURCE_PREFIX.length)); | |
| 236 | + if (result.iconId === 0) { | ||
| 237 | + traceMissingIcon(item.iconSource); | ||
| 238 | + } | ||
| 236 | 239 | } else { | |
| 237 | 240 | const is = fromFileOrResource(item.iconSource); | |
| 238 | 241 | if (is) { | |
| 239 | 242 | // TODO: Make this native call that accepts string so that we don't load Bitmap in JS. | |
| 240 | 243 | result.iconDrawable = new android.graphics.drawable.BitmapDrawable(is.android); | |
| 244 | + } else { | ||
| 245 | + traceMissingIcon(item.iconSource); | ||
| 241 | 246 | } | |
| 242 | 247 | } | |
| 243 | 248 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,7 @@ import { ios as iosView, ViewBase } from "../core/view"; | |||
| 5 | 5 | import { | |
| 6 | 6 | TabViewBase, TabViewItemBase, itemsProperty, selectedIndexProperty, | |
| 7 | 7 | tabTextColorProperty, tabTextFontSizeProperty, tabBackgroundColorProperty, selectedTabTextColorProperty, iosIconRenderingModeProperty, | |
| 8 | - View, fontInternalProperty, layout, traceEnabled, traceWrite, traceCategories, Color | ||
| 8 | + View, fontInternalProperty, layout, traceEnabled, traceWrite, traceCategories, Color, traceMissingIcon | ||
| 9 | 9 | } from "./tab-view-common" | |
| 10 | 10 | import { textTransformProperty, TextTransform, getTransformedText } from "../text-base"; | |
| 11 | 11 | import { fromFileOrResource } from "../../image-source"; | |
@@ -451,6 +451,8 @@ export class TabView extends TabViewBase { | |||
| 451 | 451 | const originalRenderedImage = is.ios.imageWithRenderingMode(this._getIconRenderingMode()); | |
| 452 | 452 | this._iconsCache[iconSource] = originalRenderedImage; | |
| 453 | 453 | image = originalRenderedImage; | |
| 454 | + } else { | ||
| 455 | + traceMissingIcon(iconSource); | ||
| 454 | 456 | } | |
| 455 | 457 | } | |
| 456 | 458 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments