Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions tns-core-modules/ui/bottom-navigation/bottom-navigation.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { CSSType, Color } from "../core/view";
import { Frame, View } from "../frame";
import { RESOURCE_PREFIX, ad, layout } from "../../utils/utils";
import { fromFileOrResource } from "../../image-source";
import * as application from "../../application";

// TODO: Impl trace
// import { isEnabled as traceEnabled, write as traceWrite } from "../../../trace";

Expand Down Expand Up @@ -159,34 +161,35 @@ function initializeNativeClasses() {
}

function createTabItemSpec(tabStripItem: TabStripItem): org.nativescript.widgets.TabItemSpec {
const result = new org.nativescript.widgets.TabItemSpec();
result.title = tabStripItem.title;

if (tabStripItem.backgroundColor instanceof Color) {
result.backgroundColor = tabStripItem.backgroundColor.android;
}

if (tabStripItem.iconSource) {
if (tabStripItem.iconSource.indexOf(RESOURCE_PREFIX) === 0) {
result.iconId = ad.resources.getDrawableId(tabStripItem.iconSource.substr(RESOURCE_PREFIX.length));
if (result.iconId === 0) {
let iconSource;
const tabItemSpec = new org.nativescript.widgets.TabItemSpec();

// Image and Label children of TabStripItem
// take priority over its `iconSource` and `title` properties
iconSource = tabStripItem.image ? tabStripItem.image.src : tabStripItem.iconSource;
tabItemSpec.title = tabStripItem.label ? tabStripItem.label.text : tabStripItem.title;

if (iconSource) {
if (iconSource.indexOf(RESOURCE_PREFIX) === 0) {
tabItemSpec.iconId = ad.resources.getDrawableId(iconSource.substr(RESOURCE_PREFIX.length));
if (tabItemSpec.iconId === 0) {
// TODO:
// traceMissingIcon(tabStripItem.iconSource);
// traceMissingIcon(iconSource);
}
} else {
const is = fromFileOrResource(tabStripItem.iconSource);
if (is) {
// TODO: Make this native call that accepts string so that we don't load Bitmap in JS.
// tslint:disable-next-line:deprecation
result.iconDrawable = new android.graphics.drawable.BitmapDrawable(is.android);
tabItemSpec.iconDrawable = new android.graphics.drawable.BitmapDrawable(application.android.context.getResources(), is.android);
} else {
// TODO:
// traceMissingIcon(tabStripItem.iconSource);
// traceMissingIcon(iconSource);
}
}
}

return result;
return tabItemSpec;
}

function setElevation(grid: org.nativescript.widgets.GridLayout, bottomNavigationBar: org.nativescript.widgets.BottomNavigationBar) {
Expand Down Expand Up @@ -471,7 +474,7 @@ export class BottomNavigation extends TabNavigationBase {
}

this._currentFragment = fragment;

const tabItems = this.items;
const tabItem = tabItems ? tabItems[position] : null;
if (tabItem) {
Expand Down
26 changes: 17 additions & 9 deletions tns-core-modules/ui/bottom-navigation/bottom-navigation.ios.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Types
// Types
import { TabContentItem } from "../tab-navigation-base/tab-content-item";
import { TabStripItem } from "../tab-navigation-base/tab-strip-item";
import { TextTransform } from "../text-base";
Expand Down Expand Up @@ -500,15 +500,9 @@ export class BottomNavigation extends TabNavigationBase {
items.forEach((item, i) => {
const controller = this.getViewController(item);

let icon = null;
let title = "";

if (this.tabStrip && this.tabStrip.items && this.tabStrip.items[i]) {
const tabStripItem = <TabStripItem>this.tabStrip.items[i];
icon = this._getIcon(tabStripItem.iconSource);
title = tabStripItem.title;

const tabBarItem = UITabBarItem.alloc().initWithTitleImageTag((title || ""), icon, i);
const tabBarItem = this.createTabBarItem(tabStripItem, i);
updateTitleAndIconPositions(tabStripItem, tabBarItem, controller);

applyStatesToItem(tabBarItem, states);
Expand All @@ -528,6 +522,20 @@ export class BottomNavigation extends TabNavigationBase {
this._ios.moreNavigationController.delegate = this._moreNavigationControllerDelegate;
}

private createTabBarItem(item: TabStripItem, index: number): UITabBarItem {
let image: UIImage;
let title: string;

// Image and Label children of TabStripItem
// take priority over its `iconSource` and `title` properties
image = item.image ? this._getIcon(item.image.src) : this._getIcon(item.iconSource);
title = item.label ? item.label.text : item.title;

const tabBarItem = UITabBarItem.alloc().initWithTitleImageTag(title, image, index);

return tabBarItem;
}

private _getIconRenderingMode(): UIImageRenderingMode {
return UIImageRenderingMode.AlwaysOriginal;
}
Expand Down Expand Up @@ -632,4 +640,4 @@ function applyStatesToItem(item: UITabBarItem, states: TabStates) {

item.setTitleTextAttributesForState(states.normalState, UIControlState.Normal);
item.setTitleTextAttributesForState(states.selectedState, UIControlState.Selected);
}
}
5 changes: 0 additions & 5 deletions tns-core-modules/ui/tabs/tabs.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,6 @@ class UIPageViewControllerDelegateImpl extends NSObject implements UIPageViewCon
// } else {
// owner.selectedIndex++;
// }
console.log("test");
//
}

public pageViewControllerDidFinishAnimatingPreviousViewControllersTransitionCompleted(pageViewController: UIPageViewController, didFinishAnimating: boolean, previousViewControllers: NSArray<UIViewController>, transitionCompleted: boolean): void {
Expand All @@ -364,9 +362,6 @@ class UIPageViewControllerDelegateImpl extends NSObject implements UIPageViewCon
owner.selectedIndex = nextViewControllerIndex;
owner._canSelectItem = true;
}

console.log("test");
//
}
}

Expand Down