Skip to content

Commit f02747d

Browse files
Merge pull request #9 from bradmartin/master
Fix android translucent flags
2 parents 0a7d21b + 099adf0 commit f02747d

File tree

4 files changed

+69
-37
lines changed

4 files changed

+69
-37
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ the `<Slides:SlideContainer>` element also has a property called `loop` which is
6666

6767
the `<Slides:SlideContainer>` element also has a property called `interval` which is a integer value and the value is in milliseconds. The suggested use case would be for a Image Carousel or something of that nature which can change the image for every fixed intervals. In unloaded function call `page.getViewById("your_id").stopSlideshow()` to unregister it (your_id is the id given to `<Slides:SlideContainer>`), it can be restarted with `startSlidShow`.
6868

69-
#### Android Optional Attribute
70-
- `AndroidTransparentStatusBar`: boolean - If true, the Android status bar will be transparent on devices that support it. Typically this is API >=21 (Lollipop).
69+
#### Android Optional Attributes
70+
- `androidTranslucentStatusBar`: boolean - If true, the Android status bar will be translucent on devices that support it. (Android sdk >= 19).
71+
- `androidTranslucentNavBar`: boolean - If true, the Android navigation bar will be translucent on devices that support it. (Android sdk >= 19).
7172

7273
###Plugin Development Work Flow:
7374

demo/package.json

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
{
2-
"nativescript": {
3-
"id": "org.nativescript.demo",
4-
"tns-android": {
5-
"version": "2.0.0"
6-
},
7-
"tns-ios": {
8-
"version": "2.0.0"
9-
}
10-
},
11-
"dependencies": {
12-
"nativescript-slides": "file:..",
13-
"tns-core-modules": "2.0.0"
14-
},
15-
"devDependencies": {
16-
"babel-traverse": "6.9.0",
17-
"babel-types": "6.9.0",
18-
"babylon": "6.8.0",
19-
"filewalker": "0.1.2",
20-
"lazy": "1.0.11",
21-
"nativescript-dev-typescript": "^0.3.1",
22-
"typescript": "^1.8.7"
23-
}
24-
}
2+
"nativescript": {
3+
"id": "org.nativescript.demo",
4+
"tns-android": {
5+
"version": "2.0.0"
6+
},
7+
"tns-ios": {
8+
"version": "2.0.0"
9+
}
10+
},
11+
"dependencies": {
12+
"nativescript-slides": "file:..",
13+
"tns-core-modules": "^2.0.1"
14+
},
15+
"devDependencies": {
16+
"babel-traverse": "6.9.0",
17+
"babel-types": "6.9.0",
18+
"babylon": "6.8.0",
19+
"filewalker": "0.1.2",
20+
"lazy": "1.0.11",
21+
"nativescript-dev-typescript": "^0.3.1",
22+
"typescript": "^1.8.7"
23+
}
24+
}

nativescript-slides.d.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ export declare class SlideContainer extends AbsoluteLayout {
1515
private _pageWidth;
1616
private _loop;
1717
private _interval;
18-
private _AndroidTransparentStatusBar;
18+
private _androidTranslucentStatusBar;
19+
private _androidTranslucentNavBar;
1920
private timer_reference;
2021
interval: number;
2122
loop: boolean;
22-
AndroidTransparentStatusBar: boolean;
23+
androidTranslucentStatusBar: boolean;
24+
androidTranslucentNavBar: boolean;
2325
pageWidth: number;
2426
android: any;
2527
ios: any;
@@ -31,6 +33,7 @@ export declare class SlideContainer extends AbsoluteLayout {
3133
startSlideshow(): void;
3234
nextSlide(): void;
3335
previousSlide(): void;
36+
resetAndroidTranslucentFlags(): void;
3437
private setupLeftPanel();
3538
private setupRightPanel();
3639
private applySwipe(pageWidth);

nativescript-slides.ts

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import * as AnimationModule from 'ui/animation';
99
import * as gestures from 'ui/gestures';
1010
import {AnimationCurve} from 'ui/enums';
1111

12+
const LayoutParams = android.view.WindowManager.LayoutParams;
13+
1214
export class Slide extends StackLayout { }
1315

1416
enum direction {
@@ -31,7 +33,8 @@ export class SlideContainer extends AbsoluteLayout {
3133
private _pageWidth: number;
3234
private _loop: boolean;
3335
private _interval: number;
34-
private _AndroidTransparentStatusBar: boolean;
36+
private _androidTranslucentStatusBar: boolean;
37+
private _androidTranslucentNavBar: boolean;
3538
private timer_reference: number;
3639

3740
get interval() {
@@ -50,12 +53,20 @@ export class SlideContainer extends AbsoluteLayout {
5053
this._loop = value;
5154
}
5255

53-
get AndroidTransparentStatusBar() {
54-
return this._AndroidTransparentStatusBar;
56+
get androidTranslucentStatusBar() {
57+
return this._androidTranslucentStatusBar;
58+
}
59+
60+
set androidTranslucentStatusBar(value: boolean) {
61+
this._androidTranslucentStatusBar = value;
5562
}
5663

57-
set AndroidTransparentStatusBar(value: boolean) {
58-
this._AndroidTransparentStatusBar = value;
64+
get androidTranslucentNavBar() {
65+
return this._androidTranslucentNavBar;
66+
}
67+
68+
set androidTranslucentNavBar(value: boolean) {
69+
this._androidTranslucentNavBar = value;
5970
}
6071

6172
get pageWidth() {
@@ -93,12 +104,19 @@ export class SlideContainer extends AbsoluteLayout {
93104
if (!this._loaded) {
94105
this._loaded = true;
95106

96-
// Android Transparent Status Bar
97-
if (this.AndroidTransparentStatusBar === true && app.android && Platform.device.sdkVersion >= '21') {
98-
const View = android.view.View;
107+
// Android Translucent bars API >= 19 only
108+
if (this.androidTranslucentStatusBar === true || this._androidTranslucentNavBar === true && app.android && Platform.device.sdkVersion >= '19') {
99109
let window = app.android.startActivity.getWindow();
100-
// set the status bar to Color.Transparent
101-
window.setStatusBarColor(0x000000);
110+
111+
// check for status bar
112+
if (this._androidTranslucentStatusBar === true) {
113+
window.addFlags(LayoutParams.FLAG_TRANSLUCENT_STATUS);
114+
}
115+
116+
// check for nav bar
117+
if (this._androidTranslucentNavBar === true) {
118+
window.addFlags(LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
119+
}
102120
}
103121

104122
let slides: StackLayout[] = [];
@@ -172,6 +190,16 @@ export class SlideContainer extends AbsoluteLayout {
172190
});
173191
}
174192

193+
public resetAndroidTranslucentFlags(): void {
194+
if (this._androidTranslucentStatusBar === true) {
195+
let window = app.android.startActivity.getWindow();
196+
window.clearFlags(LayoutParams.FLAG_TRANSLUCENT_STATUS);
197+
}
198+
if (this._androidTranslucentNavBar === true) {
199+
window.clearFlags(LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
200+
}
201+
}
202+
175203
private setupLeftPanel(): void {
176204
this.direction = direction.none;
177205
this.transitioning = false;

0 commit comments

Comments
 (0)