Skip to content

Commit 2eabf23

Browse files
ADjenkovADjenkov
ADjenkov
authored and
ADjenkov
committed
Merge branch 'djenkov/location-strategy' of github.com:NativeScript/nativescript-angular into djenkov/location-strategy
2 parents 60c795d + 273d1a7 commit 2eabf23

File tree

9 files changed

+85
-44
lines changed

9 files changed

+85
-44
lines changed

Diff for: .github/ISSUE_TEMPLATE.md

+24-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
1-
PSST! Want to get faster responses to bug reports and important issues? Help us keep the issue tracker organized by:
1+
### Make sure to check the existing issues in this repository
22

3-
- Reporting bugs. Please include all details about the problem and provide a sample app (consider using the [playground](https://play.nativescript.org) for this.
4-
- Proposing features and enhancements.
5-
- Discussing implementation details.
3+
### If there is no issue for your problem, tell us about it
4+
Please, ensure your title is less than 63 characters long and starts with a capital
5+
letter.
66

7-
Please move all other content to the [forums](https://discourse.nativescript.org/).
7+
### Which platform(s) does your issue occur on?
8+
- iOS/Android/Both
9+
- iOS/Android versions
10+
- emulator or device. What type of device?
11+
12+
### Please, provide the following version numbers that your issue occurs with:
13+
14+
- CLI: (run `tns --version` to fetch it)
15+
- Cross-platform modules: (check the 'version' attribute in the
16+
`node_modules/tns-core-modules/package.json` file in your project)
17+
- Runtime(s): (look for the `"tns-android"` and `"tns-ios"` properties in the `package.json` file of your project)
18+
- Plugin(s): (look for the version numbers in the `package.json` file of your
19+
project and paste your dependencies and devDependencies here)
20+
21+
### Please, tell us how to recreate the issue in as much detail as possible.
22+
Describe the steps to reproduce it.
23+
24+
### Is there any code involved?
25+
- provide a code example to recreate the problem
26+
- (EVEN BETTER) consider using the [playground](https://play.nativescript.org) to provide an application where the problem is reproducible. If this is not possible, provide a .zip with application or refer to a repository with application where the problem is reproducible.

Diff for: e2e/modal-navigation-ng/app/app.css

+3
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ of writing your own CSS rules. For a full list of class names in the theme
1010
refer to http://docs.nativescript.org/ui/theme.
1111
*/
1212
@import '~nativescript-theme-core/css/core.light.css';
13+
Button {
14+
font-size: 10px;
15+
}

Diff for: e2e/modal-navigation-ng/app/home/home.component.html

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<ActionBar class="action-bar">
2-
<Label class="action-bar-title" text="Home"></Label>
2+
<Label class="action-bar-title" text="Home Component"></Label>
33
</ActionBar>
44

5-
<StackLayout>
5+
<WrapLayout>
66
<Button text="Show Modal Without Frame" (tap)="onModalNoFrame()"></Button>
77
<Button text="Show Modal Page With Frame" (tap)="onModalFrame()"></Button>
88
<Button text="Navigate To Second Page" (tap)="onNavigateSecond()"></Button>
@@ -14,5 +14,4 @@
1414

1515
<Button text="show shared modal" (tap)="onRootModalTap()"></Button>
1616
<Button text="go to second (to open shared modal)" [nsRouterLink]="['/modal-shared-second-host']"></Button>
17-
<Label text="home component" verticalAlignment="bottom"></Label>
18-
</StackLayout>
17+
</WrapLayout>

Diff for: e2e/modal-navigation-ng/app/layout.component.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
<StackLayout>
2-
<Label text="Home" horizontalAlignment="center"></Label>
1+
<WrapLayout>
2+
<Label text="Home Component" horizontalAlignment="center"></Label>
33
<Button text="Show Modal Without Frame" (tap)="onModalNoFrame()"></Button>
44
<Button text="Show Modal Page With Frame" (tap)="onModalFrame()"></Button>
55
<Button text="Reset Named Frame Root View" (tap)="onNamedFrameRootViewReset()"></Button>
66
<Button text="Reset Frame Root View" (tap)="onFrameRootViewReset()"></Button>
77
<Button text="Reset Tab Root View" (tap)="onTabRootViewReset()"></Button>
88
<Button text="Reset Layout Root View" (tap)="onLayoutRootViewReset()"></Button>
99
<Button text="Show Dialog" (tap)="onShowDialog()"></Button>
10-
</StackLayout>
10+
</WrapLayout>

Diff for: e2e/modal-navigation-ng/e2e/modal.shared.e2e-spec.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { AppiumDriver, createDriver, SearchOptions } from "nativescript-dev-appium";
22
import { assert } from "chai";
33

4+
const homeComponent = "Home Component";
5+
46
describe("Shared modal from home and back", () => {
57
let driver: AppiumDriver;
68

@@ -22,7 +24,7 @@ describe("Shared modal from home and back", () => {
2224
});
2325

2426
it ("should find home component", async () => {
25-
await assertComponent(driver, "home component");
27+
await assertComponent(driver, homeComponent);
2628
});
2729

2830
it("should open/close shared modal from home component", async () => {
@@ -31,7 +33,7 @@ describe("Shared modal from home and back", () => {
3133
});
3234

3335
it ("should find home component again", async () => {
34-
await assertComponent(driver, "home component");
36+
await assertComponent(driver, homeComponent);
3537
});
3638
});
3739

@@ -56,7 +58,7 @@ describe("Shared modal from second and back", () => {
5658
});
5759

5860
it ("should find home component", async () => {
59-
await assertComponent(driver, "home component");
61+
await assertComponent(driver, homeComponent);
6062
});
6163

6264
it ("should navigate to second component", async() => {
@@ -98,7 +100,7 @@ describe("Shared modal from different components", () => {
98100
});
99101

100102
it ("should find home component", async () => {
101-
await assertComponent(driver, "home component");
103+
await assertComponent(driver, homeComponent);
102104
});
103105

104106
it("should open/close shared modal from home component", async () => {
@@ -107,7 +109,7 @@ describe("Shared modal from different components", () => {
107109
});
108110

109111
it ("should find home component again", async () => {
110-
await assertComponent(driver, "home component");
112+
await assertComponent(driver, homeComponent);
111113
});
112114

113115
it ("should navigate to second component", async() => {
@@ -129,7 +131,7 @@ describe("Shared modal from different components", () => {
129131

130132
it ("should navigate back to home component", async () => {
131133
await goBack(driver);
132-
await assertComponent(driver, "home component");
134+
await assertComponent(driver, homeComponent);
133135
});
134136

135137
it("should open/close shared modal from home component after manipulations with second", async () => {
@@ -138,7 +140,7 @@ describe("Shared modal from different components", () => {
138140
});
139141

140142
it ("should find home component again", async () => {
141-
await assertComponent(driver, "home component");
143+
await assertComponent(driver, homeComponent);
142144
});
143145
});
144146

Diff for: e2e/modal-navigation-ng/e2e/screen.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { AppiumDriver } from "nativescript-dev-appium";
22
import { assert } from "chai";
33

4-
const home = "Home"
4+
const home = "Home Component"
55
const first = "First"
66
const modal = "Modal";
77
const modalFirst = "Modal First";

Diff for: nativescript-angular/directives/dialogs.ts

+19-13
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,25 @@ export class ModalDialogService {
7878

7979
this.location._beginModalNavigation(frame);
8080

81-
return new Promise(resolve => {
82-
setTimeout(() => this._showDialog({
83-
containerRef: viewContainerRef,
84-
context,
85-
doneCallback: resolve,
86-
fullscreen,
87-
animated,
88-
stretched,
89-
pageFactory,
90-
parentView,
91-
resolver,
92-
type,
93-
}), 10);
81+
return new Promise((resolve, reject) => {
82+
setTimeout(() => {
83+
try {
84+
this._showDialog({
85+
containerRef: viewContainerRef,
86+
context,
87+
doneCallback: resolve,
88+
fullscreen,
89+
animated,
90+
stretched,
91+
pageFactory,
92+
parentView,
93+
resolver,
94+
type,
95+
});
96+
} catch (err) {
97+
reject(err);
98+
}
99+
}, 10);
94100
});
95101
}
96102

Diff for: nativescript-angular/platform-providers.ts

+18-7
Original file line numberDiff line numberDiff line change
@@ -95,25 +95,36 @@ export class FrameService {
9595
this.frames = this.frames.filter(currentFrame => currentFrame.frame !== frame);
9696
}
9797

98-
findFrame(frame: Frame, name?: string) {
98+
containsOutlet(name: string) {
99+
let nameFound = false;
100+
101+
for (let i = 0; i < this.frames.length; i++) {
102+
const currentFrame = this.frames[i];
103+
104+
if (name && currentFrame.name === name) {
105+
nameFound = true;
106+
break;
107+
}
108+
}
109+
110+
return nameFound;
111+
}
112+
113+
findFrame(frame: Frame) {
99114
let cachedFrame;
100115
let cachedFrameRootOutlet;
101-
let hasDuplicateOutletName = false;
102116

103117
for (let i = 0; i < this.frames.length; i++) {
104118
const currentFrame = this.frames[i];
105119

106120
if (currentFrame.frame === frame) {
107121
cachedFrame = currentFrame;
108122
cachedFrameRootOutlet = currentFrame.rootOutlet;
109-
}
110-
111-
if (name && currentFrame.name === name) {
112-
hasDuplicateOutletName = true;
123+
break;
113124
}
114125
}
115126

116-
return { cachedFrame, cachedFrameRootOutlet, hasDuplicateOutletName };
127+
return { cachedFrame, cachedFrameRootOutlet };
117128
}
118129

119130
// Return the latest navigated frame from the given outlet branch.

Diff for: nativescript-angular/router/ns-location-strategy.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,11 @@ export class NSLocationStrategy extends LocationStrategy {
292292
}
293293
this._isPageNavigationBack = true;
294294

295-
let { cachedFrame, hasDuplicateOutletName } = this.frameService.findFrame(frame, name);
295+
let { cachedFrame } = this.frameService.findFrame(frame);
296296

297297
if (cachedFrame) {
298298
this.currentOutlet = cachedFrame.rootOutlet;
299-
} else if (!hasDuplicateOutletName) {
299+
} else if (!this.frameService.containsOutlet(name)) {
300300
this.currentOutlet = name;
301301
}
302302
}
@@ -348,12 +348,13 @@ export class NSLocationStrategy extends LocationStrategy {
348348
public _beginPageNavigation(name: string, frame: Frame): NavigationOptions {
349349
routerLog("NSLocationStrategy._beginPageNavigation()");
350350

351-
let { cachedFrame, hasDuplicateOutletName } = this.frameService.findFrame(frame, name);
351+
let { cachedFrame } = this.frameService.findFrame(frame);
352352

353353
if (cachedFrame) {
354354
this.currentOutlet = cachedFrame.rootOutlet;
355355
} else {
356-
if (!hasDuplicateOutletName && this.statesByOutlet[name]) {
356+
// Changing the current outlet only if navigating in non-cached root outlet.
357+
if (!this.frameService.containsOutlet(name) && this.statesByOutlet[name] /* ensure root outlet exists */) {
357358
this.currentOutlet = name;
358359
}
359360

0 commit comments

Comments
 (0)