Skip to content

Commit

Permalink
adding androidNavBar height
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshDSommer committed Jun 17, 2016
1 parent 8cb5319 commit bf3d842
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ A repo for all those functions you copy and paste between projects.

**`pluckChildViewsFromLayout`** accepts any layout and removes all it's child views and returns them in an array.

**`getScreenHeight`** returns an object of type IScreenHeight with the properties `portrait` and `landscape` dimensions.
**`getScreenHeight`** returns an object of type `IScreenHeight` with the properties `portrait` and `landscape` dimensions. `IScreenHeight` also has the properties `androidStatusBar` and `androidNavBar` which are android specific properties that will return the Nav bar and Status bar heights as well. if accessed on iOS they will have a value of 0. These can come in handy since the `portrait` and `landscape` dimensions do not take these into account.

* ActionBar Utilities

Expand Down
19 changes: 19 additions & 0 deletions nativescript-swiss-army-knife.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface IScreenHeight {
portrait: number;
landscape: number;
androidStatusBar: number;
androidNavBar: number;
}

export class SwissArmyKnife {
Expand Down Expand Up @@ -79,10 +80,12 @@ export class SwissArmyKnife {
let height1 = Platform.screen.mainScreen.heightDIPs;
let height2 = Platform.screen.mainScreen.widthDIPs;
let statusbar = this.getStatusBarHeight();
let navbar = this.getNavBarHeight();
return {
portrait: height1,
landscape: height2,
androidStatusBar: statusbar,
androidNavBar: navbar,
};
}

Expand All @@ -99,6 +102,20 @@ export class SwissArmyKnife {
}
}

private static getNavBarHeight(): number {
if (app.android) {
let result = 0;
let resourceId = app.android.currentContext.getResources().getIdentifier('navigation_bar_height', 'dimen', 'android');
if (resourceId > 0) {
result = app.android.currentContext.getResources().getDimensionPixelSize(resourceId);
}
return result;
} else {
return 0;
}
}


/** ActionBar Utilities */
/**
* Programmatically set title
Expand Down Expand Up @@ -136,6 +153,8 @@ export class SwissArmyKnife {
let window = app.android.startActivity.getWindow();
// check for status bar
window.addFlags(LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(new Color('pink'));
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nativescript-swiss-army-knife",
"version": "1.0.0",
"version": "1.0.1",
"description": "Nativescript Swiss Army Knife",
"main": "nativescript-swiss-army-knife.js",
"nativescript": {
Expand Down

0 comments on commit bf3d842

Please sign in to comment.