Skip to content

Commit afa6ea9

Browse files
committed
Merge remote-tracking branch 'origin/main' into feat/angular-15
2 parents 8d2bcb4 + 5099170 commit afa6ea9

File tree

15 files changed

+12052
-67
lines changed

15 files changed

+12052
-67
lines changed

.github/workflows/build.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Build
2+
3+
env:
4+
NX_BRANCH: ${{ github.event.number || github.ref_name }}
5+
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
6+
7+
on:
8+
push:
9+
branches: [ "main" ]
10+
pull_request:
11+
branches: [ "main" ]
12+
13+
jobs:
14+
build:
15+
name: Build affected projects
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v3
21+
with:
22+
fetch-depth: 0
23+
- uses: actions/setup-node@v3
24+
with:
25+
node-version: lts/*
26+
cache: 'yarn'
27+
- uses: nrwl/nx-set-shas@v3
28+
- name: Setup global dependencies
29+
run: npm i -g yarn
30+
- name: yarn install
31+
run: yarn
32+
- name: Build.all affected
33+
run: yarn nx affected --target=build --exclude nativescript-demo-ng

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,4 @@ packages/angular/dist
4545
Thumbs.db
4646

4747
.angular
48+
/.env

.husky/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh
22
. "$(dirname "$0")/_/husky.sh"
33

4-
npx lint-staged
4+
npx lint-staged --allow-empty --relative

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
## [14.2.6](https://github.com/NativeScript/angular/compare/14.2.5...14.2.6) (2022-11-23)
2+
3+
4+
### Bug Fixes
5+
6+
* read navigation extras from the router navigation instead of using stored values ([#88](https://github.com/NativeScript/angular/issues/88)) ([2e475f9](https://github.com/NativeScript/angular/commit/2e475f95f31d023c1d49f870e7c1d1290341840a))
7+
* use changeDetectorRef.detectChanges() instead of detectChanges() private api ([#99](https://github.com/NativeScript/angular/issues/99)) ([4e33561](https://github.com/NativeScript/angular/commit/4e335613e6fd23ed541a89691c0842975ab789c1))
8+
* use correct EnvironmentalInjector in page-router-outlet ([#94](https://github.com/NativeScript/angular/issues/94)) ([6623002](https://github.com/NativeScript/angular/commit/66230021603140cb352a335057687b1bd49438f6))
9+
10+
11+
112
## [14.2.5](https://github.com/NativeScript/angular/compare/14.2.4...14.2.5) (2022-10-04)
213

314

apps/nativescript-demo-ng/src/test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
2+
/// <reference path="../../../node_modules/webpack/module.d.ts" />
13
import { runTestApp } from '@nativescript/unit-test-runner';
24
// import other polyfills here
35

4-
declare let require: any;
6+
// polyfills required for latest karma
7+
global.addEventListener ??= () => {
8+
// do nothing as there`s no global event listener
9+
};
10+
global.queueMicrotask ??= (fn: () => unknown) => Promise.resolve().then(fn);
511

612
runTestApp({
713
runTests: () => {

apps/nativescript-demo-ng/src/tests/ns-location-strategy.spec.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// make sure you import mocha-config before @angular/core
22
import { DefaultUrlSerializer, UrlTree } from '@angular/router';
3-
import { FrameService, LocationState, NSLocationStrategy, Outlet } from '@nativescript/angular';
3+
import { FrameService, LocationState, NavigationOptions, NSLocationStrategy, Outlet } from '@nativescript/angular';
44
import { BackstackEntry, Frame, NavigationEntry, Page, View } from '@nativescript/core';
55

66
export class FakeFrameService extends FrameService {
@@ -134,13 +134,13 @@ function createState(url: string, outletName: string, isPageNav: boolean = false
134134
};
135135
}
136136

137-
function simulatePageNavigation(strategy: NSLocationStrategy, url: string, frame: any, outletName?: string) {
137+
function simulatePageNavigation(strategy: NSLocationStrategy, url: string, frame: any, outletName?: string, options?: NavigationOptions) {
138138
outletName = outletName || 'primary';
139139
strategy.pushState(null, null, url, null);
140140

141141
const outlet: Outlet = strategy.findOutlet(outletName);
142142
outlet.frames.push(frame);
143-
strategy._beginPageNavigation(frame);
143+
strategy._beginPageNavigation(frame, options);
144144
}
145145

146146
function simulatePageBack(strategy: NSLocationStrategy, frame: any) {
@@ -479,8 +479,7 @@ describe('NSLocationStrategy', () => {
479479
const frame = new FakeFrame();
480480
const outletName = 'primary';
481481
// Act
482-
strategy._setNavigationOptions({ clearHistory: true });
483-
simulatePageNavigation(strategy, '/cleared', frame, outletName);
482+
simulatePageNavigation(strategy, '/cleared', frame, outletName, { clearHistory: true });
484483
const outlet: Outlet = strategy.findOutlet(outletName);
485484
// Assert
486485
assertStatesEqual(outlet.states, [createState('/cleared', outletName, true)]);
@@ -494,8 +493,7 @@ describe('NSLocationStrategy', () => {
494493
const outletName2 = 'test2';
495494

496495
// Act
497-
strategy._setNavigationOptions({ clearHistory: true });
498-
simulatePageNavigation(strategy, '/(test1:cleared//test2:test2)', frame, outletName);
496+
simulatePageNavigation(strategy, '/(test1:cleared//test2:test2)', frame, outletName, { clearHistory: true });
499497
simulatePageNavigation(strategy, '/(test1:cleared//test2:test2)', frame2, outletName2);
500498
const expectedStatesTest1: Array<LocationState> = [createState('/(test1:cleared//test2:test2)', outletName, true)];
501499
const expectedStatesTest2: Array<LocationState> = [createState('/(test1:cleared//test2:test2)', outletName2, true)];

nx.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
{
22
"npmScope": "nativescript",
33
"affected": {
4-
"defaultBase": "master"
4+
"defaultBase": "main"
55
},
66
"tasksRunnerOptions": {
77
"default": {
8-
"runner": "nx/tasks-runners/default",
8+
"runner": "@nrwl/nx-cloud",
99
"options": {
1010
"useDaemonProcess": false,
1111
"cacheableOperations": ["build", "lint", "test", "e2e"],
1212
"canTrackAnalytics": false,
1313
"showUsageWarnings": true,
14-
"parallel": 1
14+
"parallel": 2,
15+
"accessToken": "NWJjY2UzMjctM2Q2Yy00ODZlLWExYjktNzE3YTRmMzRmMWQwfHJlYWQ="
1516
}
1617
}
1718
},

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-angular",
3-
"version": "14.2.5",
3+
"version": "14.2.6",
44
"license": "MIT",
55
"private": true,
66
"scripts": {
@@ -46,6 +46,7 @@
4646
"@nativescript/core": "next",
4747
"@nativescript/theme": "~3.0.2",
4848
"@ngx-translate/core": "~14.0.0",
49+
"@nrwl/nx-cloud": "^15.0.2",
4950
"nativescript-ngx-fonticon": "~7.0.0",
5051
"rxjs": "^7.5.6",
5152
"zone.js": "~0.12.0"
@@ -112,9 +113,8 @@
112113
"framework": "angular"
113114
},
114115
"lint-staged": {
115-
"**/*.{js,ts,scss,html,json}": [
116-
"prettier --write",
117-
"git add"
116+
"**/*.{js,ts,scss,json,html}": [
117+
"nx format:write --files"
118118
]
119119
}
120120
}

packages/angular/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/angular",
3-
"version": "14.2.6-alpha.0",
3+
"version": "14.2.6",
44
"homepage": "https://nativescript.org/",
55
"repository": {
66
"type": "git",

packages/angular/src/lib/cdk/dialog/native-modal-ref.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { ApplicationRef, ComponentFactoryResolver, ComponentRef, EmbeddedViewRef, Injector, Optional, ViewContainerRef, ɵdetectChanges as detectChanges } from '@angular/core';
2-
import { ContentView, View, Application, Frame } from '@nativescript/core';
1+
import { ApplicationRef, ComponentFactoryResolver, ComponentRef, EmbeddedViewRef, Injector, Optional, ViewContainerRef } from '@angular/core';
2+
import { Application, ContentView, Frame, View } from '@nativescript/core';
33
import { fromEvent, Subject } from 'rxjs';
44
import { take } from 'rxjs/operators';
55
import { AppHostAsyncView, AppHostView } from '../../app-host-view';
66
import { NSLocationStrategy } from '../../legacy/router/ns-location-strategy';
77
import { once } from '../../utils/general';
8+
import { NgViewRef } from '../../view-refs';
89
import { DetachedLoader } from '../detached-loader';
910
import { ComponentPortal, TemplatePortal } from '../portal/common';
1011
import { NativeScriptDomPortalOutlet } from '../portal/nsdom-portal-outlet';
1112
import { NativeDialogConfig } from './dialog-config';
12-
import { NgViewRef } from '../../view-refs';
1313

1414
export class NativeModalRef {
1515
_id: string;
@@ -103,7 +103,7 @@ export class NativeModalRef {
103103
const targetView = new ContentView();
104104
this.portalOutlet = new NativeScriptDomPortalOutlet(targetView, this._config.componentFactoryResolver || this._injector.get(ComponentFactoryResolver), this._injector.get(ApplicationRef), this._injector);
105105
const componentRef = this.portalOutlet.attach(portal);
106-
detectChanges(componentRef.instance);
106+
componentRef.changeDetectorRef.detectChanges();
107107
this.modalViewRef = new NgViewRef(componentRef);
108108
if (this.modalViewRef.firstNativeLikeView !== this.modalViewRef.view) {
109109
(<any>this.modalViewRef.view)._ngDialogRoot = this.modalViewRef.firstNativeLikeView;

packages/angular/src/lib/legacy/directives/dialogs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ApplicationRef, ComponentFactoryResolver, ComponentRef, Injectable, Injector, NgModuleRef, NgZone, Type, ViewContainerRef, ɵdetectChanges as detectChanges } from '@angular/core';
1+
import { ApplicationRef, ComponentFactoryResolver, ComponentRef, Injectable, Injector, NgModuleRef, NgZone, Type, ViewContainerRef } from '@angular/core';
22
import { Application, ContentView, Frame, ShowModalOptions, View, ViewBase } from '@nativescript/core';
33
import { Subject } from 'rxjs';
44
import { AppHostAsyncView, AppHostView } from '../../app-host-view';
@@ -169,7 +169,7 @@ export class ModalDialogService {
169169
const portal = new ComponentPortal(options.type);
170170
portalOutlet = new NativeScriptDomPortalOutlet(targetView, options.resolver, this.appRef, childInjector);
171171
const componentRef = portalOutlet.attach(portal);
172-
detectChanges(componentRef.instance);
172+
componentRef.changeDetectorRef.detectChanges();
173173
componentViewRef = new NgViewRef(componentRef);
174174
if (options.useContextAsComponentProps && options.context) {
175175
for (const key in options.context) {

packages/angular/src/lib/legacy/router/ns-location-strategy.ts

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { Inject, Injectable, Optional } from '@angular/core';
21
import { LocationChangeEvent, LocationStrategy } from '@angular/common';
3-
import { DefaultUrlSerializer, UrlSegmentGroup, UrlTree, ActivatedRouteSnapshot, Params } from '@angular/router';
2+
import { Inject, Injectable, Optional } from '@angular/core';
3+
import { ActivatedRouteSnapshot, DefaultUrlSerializer, Params, UrlSegmentGroup, UrlTree } from '@angular/router';
44
import { Frame } from '@nativescript/core';
5+
import { START_PATH } from '../../tokens';
56
import { NativeScriptDebug } from '../../trace';
6-
import { isPresent } from '../../utils/lang-facade';
77
import { FrameService } from '../frame.service';
8-
import { Outlet, NavigationOptions, LocationState, defaultNavOptions } from './ns-location-utils';
9-
import { START_PATH } from '../../tokens';
8+
import { defaultNavOptions, LocationState, NavigationOptions, Outlet } from './ns-location-utils';
109

1110
@Injectable({
1211
providedIn: 'root',
@@ -16,7 +15,6 @@ export class NSLocationStrategy extends LocationStrategy {
1615
private currentOutlet: Outlet;
1716

1817
private popStateCallbacks = new Array<(_: any) => any>();
19-
private _currentNavigationOptions: NavigationOptions;
2018
private currentUrlTree: UrlTree;
2119

2220
public _modalNavigationDepth = 0;
@@ -42,8 +40,8 @@ export class NSLocationStrategy extends LocationStrategy {
4240
return '/';
4341
}
4442

45-
let tree = this.currentUrlTree;
46-
let changedOutlet = this.getSegmentGroupByOutlet(this.currentOutlet);
43+
const tree = this.currentUrlTree;
44+
const changedOutlet = this.getSegmentGroupByOutlet(this.currentOutlet);
4745

4846
// Handle case where the user declares a component at path "/".
4947
// The url serializer doesn't parse this url as having a primary outlet.
@@ -110,7 +108,7 @@ export class NSLocationStrategy extends LocationStrategy {
110108
currentSegmentGroup.root = urlTreeRoot;
111109

112110
const outletPath = this.getSegmentGroupFullPath(currentTree);
113-
let outletKey = this.getOutletKey(outletPath, outletName);
111+
const outletKey = this.getOutletKey(outletPath, outletName);
114112
let outlet = this.findOutlet(outletKey);
115113

116114
const parentOutletName = currentTree.outlet || '';
@@ -188,7 +186,7 @@ export class NSLocationStrategy extends LocationStrategy {
188186
}
189187
this.callPopState(state, true);
190188
} else {
191-
let state = this.currentOutlet.peekState();
189+
const state = this.currentOutlet.peekState();
192190
if (state && state.isPageNavigation) {
193191
// This was a page navigation - so navigate through frame.
194192
if (NativeScriptDebug.isLogEnabled()) {
@@ -237,7 +235,7 @@ export class NSLocationStrategy extends LocationStrategy {
237235
private callPopState(state: LocationState, pop: boolean = true, outlet?: Outlet) {
238236
outlet = outlet || this.currentOutlet;
239237
const urlSerializer = new DefaultUrlSerializer();
240-
let changedOutlet = this.getSegmentGroupByOutlet(outlet);
238+
const changedOutlet = this.getSegmentGroupByOutlet(outlet);
241239

242240
if (state && changedOutlet) {
243241
this.updateSegmentGroup(this.currentUrlTree.root, changedOutlet, state.segmentGroup);
@@ -249,7 +247,7 @@ export class NSLocationStrategy extends LocationStrategy {
249247

250248
const url = urlSerializer.serialize(this.currentUrlTree);
251249
const change: LocationChangeEvent = { state, type: 'popstate' };
252-
for (let fn of this.popStateCallbacks) {
250+
for (const fn of this.popStateCallbacks) {
253251
fn(change);
254252
}
255253
}
@@ -359,7 +357,7 @@ export class NSLocationStrategy extends LocationStrategy {
359357
}
360358
}
361359

362-
public _beginPageNavigation(frame: Frame): NavigationOptions {
360+
public _beginPageNavigation(frame: Frame, options?: NavigationOptions): NavigationOptions {
363361
if (NativeScriptDebug.isLogEnabled()) {
364362
NativeScriptDebug.routerLog('NSLocationStrategy._beginPageNavigation()');
365363
}
@@ -371,31 +369,17 @@ export class NSLocationStrategy extends LocationStrategy {
371369
lastState.isPageNavigation = true;
372370
}
373371

374-
const navOptions = this._currentNavigationOptions || defaultNavOptions;
372+
const navOptions = options || defaultNavOptions;
373+
375374
if (navOptions.clearHistory) {
376375
if (NativeScriptDebug.isLogEnabled()) {
377376
NativeScriptDebug.routerLog('NSLocationStrategy._beginPageNavigation clearing states history');
378377
}
379378
this.currentOutlet.states = [lastState];
380379
}
381-
382-
this._currentNavigationOptions = undefined;
383380
return navOptions;
384381
}
385382

386-
public _setNavigationOptions(options: NavigationOptions) {
387-
this._currentNavigationOptions = {
388-
clearHistory: isPresent(options.clearHistory) ? options.clearHistory : false,
389-
animated: isPresent(options.animated) ? options.animated : true,
390-
transition: options.transition,
391-
replaceUrl: options.replaceUrl,
392-
};
393-
394-
if (NativeScriptDebug.isLogEnabled()) {
395-
NativeScriptDebug.routerLog('NSLocationStrategy._setNavigationOptions(' + `${JSON.stringify(this._currentNavigationOptions)})`);
396-
}
397-
}
398-
399383
public _getOutlets(): Array<Outlet> {
400384
return this.outlets;
401385
}
@@ -501,7 +485,7 @@ export class NSLocationStrategy extends LocationStrategy {
501485

502486
findOutlet(outletKey: string, activatedRouteSnapshot?: ActivatedRouteSnapshot): Outlet {
503487
let outlet: Outlet = this.outlets.find((currentOutlet) => {
504-
let equalModalDepth = currentOutlet.modalNavigationDepth === this._modalNavigationDepth;
488+
const equalModalDepth = currentOutlet.modalNavigationDepth === this._modalNavigationDepth;
505489
return equalModalDepth && currentOutlet.outletKeys.indexOf(outletKey) > -1;
506490
});
507491

@@ -510,7 +494,7 @@ export class NSLocationStrategy extends LocationStrategy {
510494
if (!outlet && activatedRouteSnapshot) {
511495
const pathByOutlets = this.getPathByOutlets(activatedRouteSnapshot);
512496
outlet = this.outlets.find((currentOutlet) => {
513-
let equalModalDepth = currentOutlet.modalNavigationDepth === this._modalNavigationDepth;
497+
const equalModalDepth = currentOutlet.modalNavigationDepth === this._modalNavigationDepth;
514498
return equalModalDepth && currentOutlet.pathByOutlets === pathByOutlets;
515499
});
516500
}
@@ -520,7 +504,7 @@ export class NSLocationStrategy extends LocationStrategy {
520504

521505
private findOutletByModal(modalNavigation: number, isShowingModal?: boolean): Outlet {
522506
return this.outlets.find((outlet) => {
523-
let equalModalDepth = outlet.modalNavigationDepth === modalNavigation;
507+
const equalModalDepth = outlet.modalNavigationDepth === modalNavigation;
524508
return isShowingModal ? equalModalDepth && outlet.showingModal : equalModalDepth;
525509
});
526510
}

packages/angular/src/lib/legacy/router/page-router-outlet.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export class PageRouterOutlet implements OnDestroy, RouterOutletContract {
135135
@Inject(PAGE_FACTORY) private pageFactory: PageFactory,
136136
private routeReuseStrategy: NSRouteReuseStrategy,
137137
private ngZone: NgZone,
138+
private router: Router,
138139
elRef: ElementRef,
139140
viewUtil: ViewUtil,
140141
private environmentInjector: EnvironmentInjector
@@ -409,8 +410,8 @@ export class PageRouterOutlet implements OnDestroy, RouterOutletContract {
409410
}
410411
});
411412

412-
this.locationStrategy._beginPageNavigation(this.frame);
413413
const navOptions = { ...defaultNavOptions, ...(this.router.getCurrentNavigation().extras || {}) } as ExtendedNavigationExtras;
414+
this.locationStrategy._beginPageNavigation(this.frame, navOptions);
414415
const isReplace = navOptions.replaceUrl && !navOptions.clearHistory;
415416

416417
// Clear refCache if navigation with clearHistory

0 commit comments

Comments
 (0)