Skip to content

Commit c645ca8

Browse files
MartoYankovSvetoslavTsenov
authored andcommitted
feat(): add actionBarVisibility property to p-r-o (#1573)
1 parent 854a120 commit c645ca8

33 files changed

+275
-0
lines changed

Diff for: e2e/renderer/app/app-routing.module.ts

+37
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import { NativeScriptRouterModule } from "nativescript-angular/router";
44
import { ActionBarDynamicItemsComponent } from "./action-bar/action-bar-dynamic-items.component";
55
import { ActionBarExtensionComponent } from "./action-bar/action-bar-extension.component";
66

7+
import { ActionBarVisibilityAlwaysComponent } from "./page-router-outlet/action-bar-visibility-always.component";
8+
import { ActionBarVisibilityAutoComponent } from "./page-router-outlet/action-bar-visibility-auto.component"
9+
import { ActionBarVisibilityNeverComponent } from "./page-router-outlet/action-bar-visibility-never.component"
10+
import { NestedPageComponent } from "./page-router-outlet/nested-page.component"
11+
712
import { TabItemBindingComponent } from "./tab-view/tab-item-binding.component";
813

914
import { ListComponent } from "./list.component";
@@ -22,6 +27,33 @@ export const routes = [
2227
redirectTo: "/list",
2328
pathMatch: "full"
2429
},
30+
{
31+
path: "action-bar-visibility-always",
32+
component: ActionBarVisibilityAlwaysComponent,
33+
children: [{
34+
path: "nested",
35+
outlet: "nested",
36+
component: NestedPageComponent
37+
}]
38+
},
39+
{
40+
path: "action-bar-visibility-never",
41+
component: ActionBarVisibilityNeverComponent,
42+
children: [{
43+
path: "nested",
44+
outlet: "nested",
45+
component: NestedPageComponent
46+
}]
47+
},
48+
{
49+
path: "action-bar-visibility-auto",
50+
component: ActionBarVisibilityAutoComponent,
51+
children: [{
52+
path: "nested",
53+
outlet: "nested",
54+
component: NestedPageComponent
55+
}]
56+
},
2557
{
2658
path: "action-bar-dynamic",
2759
component: ActionBarDynamicItemsComponent,
@@ -76,6 +108,11 @@ export const navigatableComponents = [
76108
ActionBarDynamicItemsComponent,
77109
ActionBarExtensionComponent,
78110

111+
ActionBarVisibilityAlwaysComponent,
112+
ActionBarVisibilityNeverComponent,
113+
ActionBarVisibilityAutoComponent,
114+
NestedPageComponent,
115+
79116
TabItemBindingComponent,
80117

81118
ListComponent,

Diff for: e2e/renderer/app/list.component.ts

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import { Component } from "@angular/core";
55
<FlexboxLayout flexDirection="column">
66
<Button text="ActionBar dynamic" [nsRouterLink]="['/action-bar-dynamic']"></Button>
77
<Button text="ActionBarExtension" [nsRouterLink]="['/action-bar-extension']"></Button>
8+
<Button text="ActionBarVisibility Always" [nsRouterLink]="['/action-bar-visibility-always']"></Button>
9+
<Button text="ActionBarVisibility Never" [nsRouterLink]="['/action-bar-visibility-never']"></Button>
10+
<Button text="ActionBarVisibility Auto" [nsRouterLink]="['/action-bar-visibility-auto']"></Button>
811
<Button text="TabItem Binding" [nsRouterLink]="['/tab-item-binding']"></Button>
912
<Button text="NgFor" [nsRouterLink]="['/ngfor']"></Button>
1013
<Button text="NgForOf" [nsRouterLink]="['/ngforof']"></Button>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Component, OnInit } from "@angular/core";
2+
import { RouterExtensions } from "nativescript-angular/router";
3+
import { ActivatedRoute } from "@angular/router";
4+
5+
@Component({
6+
template: `
7+
<ActionBar title="Action Bar Visibility Always">
8+
</ActionBar>
9+
10+
<GridLayout rows="200, *" backgroundColor="salmon">
11+
<GridLayout row="1">
12+
<page-router-outlet name="nested" actionBarVisibility="always"></page-router-outlet>
13+
</GridLayout>
14+
</GridLayout>
15+
`
16+
})
17+
export class ActionBarVisibilityAlwaysComponent implements OnInit {
18+
constructor(
19+
private routerExtension: RouterExtensions,
20+
private activeRoute: ActivatedRoute) {
21+
}
22+
23+
ngOnInit(): void {
24+
this.routerExtension.navigate([{outlets: { nested: ["nested"]}}], { relativeTo: this.activeRoute });
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Component, OnInit } from "@angular/core";
2+
import { RouterExtensions } from "nativescript-angular/router";
3+
import { ActivatedRoute } from "@angular/router";
4+
5+
@Component({
6+
template: `
7+
<ActionBar title="Action Bar Visibility Auto">
8+
</ActionBar>
9+
10+
<GridLayout rows="200, *" backgroundColor="salmon">
11+
<GridLayout row="1">
12+
<page-router-outlet name="nested" actionBarVisibility="auto"></page-router-outlet>
13+
</GridLayout>
14+
</GridLayout>
15+
`
16+
})
17+
export class ActionBarVisibilityAutoComponent implements OnInit {
18+
constructor(
19+
private routerExtension: RouterExtensions,
20+
private activeRoute: ActivatedRoute) {
21+
}
22+
23+
ngOnInit(): void {
24+
this.routerExtension.navigate([{ outlets: { nested: ["nested"] } }], { relativeTo: this.activeRoute });
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Component, OnInit } from "@angular/core";
2+
import { RouterExtensions } from "nativescript-angular/router";
3+
import { ActivatedRoute } from "@angular/router";
4+
5+
@Component({
6+
template: `
7+
<ActionBar title="Action Bar Visibility Never">
8+
</ActionBar>
9+
10+
<GridLayout rows="200, *" backgroundColor="salmon">
11+
<GridLayout row="1">
12+
<page-router-outlet name="nested" actionBarVisibility="never"></page-router-outlet>
13+
</GridLayout>
14+
</GridLayout>
15+
`
16+
})
17+
export class ActionBarVisibilityNeverComponent implements OnInit {
18+
constructor(
19+
private routerExtension: RouterExtensions,
20+
private activeRoute: ActivatedRoute) {
21+
}
22+
23+
ngOnInit(): void {
24+
this.routerExtension.navigate([{ outlets: { nested: ["nested"] } }], { relativeTo: this.activeRoute });
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Component } from "@angular/core";
2+
3+
@Component({
4+
template: `
5+
<ActionBar title="Nested Page">
6+
</ActionBar>
7+
8+
<GridLayout backgroundColor="gold">
9+
<StackLayout>
10+
<Button text="ShowActionBar" (tap)="showActionBar($event)"></Button>
11+
<Button text="HideActionBar" (tap)="hideActionBar($event)"></Button>
12+
</StackLayout>
13+
</GridLayout>
14+
`
15+
})
16+
export class NestedPageComponent {
17+
showActionBar(args): void {
18+
args.object.page.actionBarHidden = false;
19+
}
20+
21+
hideActionBar(args): void {
22+
args.object.page.actionBarHidden = true;
23+
}
24+
}

Diff for: e2e/renderer/e2e/page-router-outlet.e2e-spec.ts

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import {
2+
AppiumDriver,
3+
createDriver,
4+
SearchOptions,
5+
UIElement
6+
} from "nativescript-dev-appium";
7+
import { assert } from "chai";
8+
9+
describe("page-router-outlet-scenario", () => {
10+
let driver: AppiumDriver;
11+
12+
describe("actionBarVisibility 'always' shows action bars", async () => {
13+
before(async () => {
14+
driver = await createDriver();
15+
await driver.driver.resetApp();
16+
});
17+
18+
it("should navigate to page", async () => {
19+
const navigationButton =
20+
await driver.findElementByText("ActionBarVisibility Always", SearchOptions.exact);
21+
await navigationButton.click();
22+
23+
await driver.findElementByText("ShowActionBar", SearchOptions.exact);
24+
});
25+
26+
it("should not hide action bar by default", async () => {
27+
const screenMatches = await driver.compareScreen("actionBarVisibility-always-default", 5);
28+
assert(screenMatches);
29+
});
30+
31+
it("should not hide action bar when hidden by page", async () => {
32+
const hideActionBarButton = await driver.findElementByText("HideActionBar");
33+
hideActionBarButton.click();
34+
35+
const screenMatches = await driver.compareScreen("actionBarVisibility-always-hidden", 5);
36+
assert(screenMatches);
37+
});
38+
39+
it("should not do anything when shown action bar by page", async () => {
40+
const showActionBarButton = await driver.findElementByText("ShowActionBar");
41+
showActionBarButton.click();
42+
43+
const screenMatches = await driver.compareScreen("actionBarVisibility-always-shown", 5);
44+
assert(screenMatches);
45+
});
46+
});
47+
48+
describe("actionBarVisibility 'never' doesn't show action bars", async () => {
49+
before(async () => {
50+
driver = await createDriver();
51+
await driver.driver.resetApp();
52+
});
53+
54+
it("should navigate to page", async () => {
55+
const navigationButton =
56+
await driver.findElementByText("ActionBarVisibility Never", SearchOptions.exact);
57+
await navigationButton.click();
58+
59+
await driver.findElementByText("ShowActionBar", SearchOptions.exact);
60+
});
61+
62+
it("should hide action bar by default", async () => {
63+
const screenMatches = await driver.compareScreen("actionBarVisibility-never-default", 5);
64+
assert(screenMatches);
65+
});
66+
67+
it("should not show action bar when shown by page", async () => {
68+
const showActionBarButton = await driver.findElementByText("ShowActionBar");
69+
showActionBarButton.click();
70+
71+
const screenMatches = await driver.compareScreen("actionBarVisibility-never-shown", 5);
72+
assert(screenMatches);
73+
});
74+
75+
it("should not do anything when hidden action bar by page", async () => {
76+
const hideActionBarButton = await driver.findElementByText("HideActionBar");
77+
hideActionBarButton.click();
78+
79+
const screenMatches = await driver.compareScreen("actionBarVisibility-never-hidden", 5);
80+
assert(screenMatches);
81+
});
82+
});
83+
84+
describe("actionBarVisibility 'auto' shows action bars based on page", async () => {
85+
before(async () => {
86+
driver = await createDriver();
87+
await driver.driver.resetApp();
88+
});
89+
90+
it("should navigate to page", async () => {
91+
const navigationButton =
92+
await driver.findElementByText("ActionBarVisibility Auto", SearchOptions.exact);
93+
await navigationButton.click();
94+
95+
await driver.findElementByText("ShowActionBar", SearchOptions.exact);
96+
});
97+
98+
it("should show action bar by default", async () => {
99+
const screenMatches = await driver.compareScreen("actionBarVisibility-auto-default", 5);
100+
assert(screenMatches);
101+
});
102+
103+
it("should hide action bar when hidden by page", async () => {
104+
const hideActionBarButton = await driver.findElementByText("HideActionBar");
105+
hideActionBarButton.click();
106+
107+
const screenMatches = await driver.compareScreen("actionBarVisibility-auto-hidden", 5);
108+
assert(screenMatches);
109+
});
110+
111+
it("should show action bar when shown by page", async () => {
112+
const showActionBarButton = await driver.findElementByText("ShowActionBar");
113+
showActionBarButton.click();
114+
115+
const screenMatches = await driver.compareScreen("actionBarVisibility-auto-shown", 5);
116+
assert(screenMatches);
117+
});
118+
});
119+
});
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

Diff for: nativescript-angular/router/page-router-outlet.ts

+14
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ export class PageRouterOutlet implements OnDestroy { // tslint:disable-line:dire
150150
private parentContexts: ChildrenOutletContexts,
151151
private location: ViewContainerRef,
152152
@Attribute("name") name: string,
153+
@Attribute("actionBarVisibility") actionBarVisibility: string,
153154
@Attribute("isEmptyOutlet") isEmptyOutlet: boolean,
154155
private locationStrategy: NSLocationStrategy,
155156
private componentFactoryResolver: ComponentFactoryResolver,
@@ -162,6 +163,7 @@ export class PageRouterOutlet implements OnDestroy { // tslint:disable-line:dire
162163
) {
163164
this.isEmptyOutlet = isEmptyOutlet;
164165
this.frame = elRef.nativeElement;
166+
this.setActionBarVisibility(actionBarVisibility);
165167
if (isLogEnabled()) {
166168
log(`PageRouterOutlet.constructor frame: ${this.frame}`);
167169
}
@@ -173,6 +175,18 @@ export class PageRouterOutlet implements OnDestroy { // tslint:disable-line:dire
173175
this.detachedLoaderFactory = resolver.resolveComponentFactory(DetachedLoader);
174176
}
175177

178+
setActionBarVisibility(actionBarVisibility: string): void {
179+
switch (actionBarVisibility) {
180+
case "always":
181+
case "never":
182+
this.frame.actionBarVisibility = actionBarVisibility;
183+
return;
184+
185+
default:
186+
this.frame.actionBarVisibility = "auto";
187+
}
188+
}
189+
176190
ngOnDestroy(): void {
177191
// Clear accumulated modal view page cache when page-router-outlet
178192
// destroyed on modal view closing

0 commit comments

Comments
 (0)