Skip to content

Commit 142433e

Browse files
committed
refactor: update private imports from ng animations
1 parent aa8e8f2 commit 142433e

File tree

4 files changed

+65
-18
lines changed

4 files changed

+65
-18
lines changed

Diff for: nativescript-angular/animations/private-imports/dsl/element_instruction_map.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ export class ElementInstructionMap {
3333
has(element: any): boolean { return this._map.has(element); }
3434

3535
clear() { this._map.clear(); }
36-
}
36+
}

Diff for: nativescript-angular/animations/private-imports/render/shared.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
98
/* tslint:disable */
9+
1010
import {AUTO_STYLE, AnimationEvent, AnimationPlayer, NoopAnimationPlayer, ɵAnimationGroupPlayer, ɵPRE_STYLE as PRE_STYLE, ɵStyleData} from '@angular/animations';
1111

1212
import {AnimationStyleNormalizer} from "@angular/animations/browser/src/dsl/style_normalization/animation_style_normalizer";
@@ -24,7 +24,7 @@ export function optimizeGroupPlayer(players: AnimationPlayer[]): AnimationPlayer
2424
}
2525

2626
export function normalizeKeyframes(
27-
_driver: AnimationDriver, normalizer: AnimationStyleNormalizer, _element: any,
27+
driver: AnimationDriver, normalizer: AnimationStyleNormalizer, element: any,
2828
keyframes: ɵStyleData[], preStyles: ɵStyleData = {},
2929
postStyles: ɵStyleData = {}): ɵStyleData[] {
3030
const errors: string[] = [];
@@ -122,11 +122,11 @@ export function parseTimelineCommand(command: string): [string, string] {
122122
return [id, action];
123123
}
124124

125-
let _contains: (elm1: any, elm2: any) => boolean = (_elm1: any, _elm2: any) => false;
126-
let _matches: (element: any, selector: string) => boolean = (_element: any, _selector: string) =>
125+
let _contains: (elm1: any, elm2: any) => boolean = (elm1: any, elm2: any) => false;
126+
let _matches: (element: any, selector: string) => boolean = (element: any, selector: string) =>
127127
false;
128128
let _query: (element: any, selector: string, multi: boolean) => any[] =
129-
(_element: any, _selector: string, _multi: boolean) => {
129+
(element: any, selector: string, multi: boolean) => {
130130
return [];
131131
};
132132

@@ -161,4 +161,4 @@ if (typeof Element != 'undefined') {
161161

162162
export const matchesElement = _matches;
163163
export const containsElement = _contains;
164-
export const invokeQuery = _query;
164+
export const invokeQuery = _query;

Diff for: nativescript-angular/animations/private-imports/render/transition_animation_engine.ts

+57-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
98
/* tslint:disable */
109
import {AUTO_STYLE, AnimationOptions, AnimationPlayer, NoopAnimationPlayer, ɵPRE_STYLE as PRE_STYLE, ɵStyleData} from '@angular/animations';
1110

@@ -23,6 +22,11 @@ import {AnimationDriver} from '@angular/animations/browser/src/render/animation_
2322

2423
import {getOrSetAsInMap, listenOnPlayer, makeAnimationEvent, normalizeKeyframes, optimizeGroupPlayer} from "../render/shared";
2524

25+
const QUEUED_CLASSNAME = 'ng-animate-queued';
26+
const QUEUED_SELECTOR = '.ng-animate-queued';
27+
const DISABLED_CLASSNAME = 'ng-animate-disabled';
28+
const DISABLED_SELECTOR = '.ng-animate-disabled';
29+
2630
const EMPTY_PLAYER_ARRAY: TransitionAnimationPlayer[] = [];
2731
const NULL_REMOVAL_STATE: ElementAnimationState = {
2832
namespaceId: '',
@@ -205,6 +209,16 @@ export class AnimationTransitionNamespace {
205209
return player;
206210
}
207211

212+
const isRemoval = toState.value === VOID_VALUE;
213+
214+
// normally this isn't reached by here, however, if an object expression
215+
// is passed in then it may be a new object each time. Comparing the value
216+
// is important since that will stay the same despite there being a new object.
217+
// The removal arc here is special cased because the same element is triggered
218+
// twice in the event that it contains animations on the outer/inner portions
219+
// of the host container
220+
if (!isRemoval && fromState.value === toState.value) return;
221+
208222
const playersOnElement: TransitionAnimationPlayer[] =
209223
getOrSetAsInMap(this._engine.playersByElement, element, []);
210224
playersOnElement.forEach(player => {
@@ -230,12 +244,11 @@ export class AnimationTransitionNamespace {
230244
{element, triggerName, transition, fromState, toState, player, isFallbackTransition});
231245

232246
if (!isFallbackTransition) {
233-
addClass(element, NG_ANIMATING_CLASSNAME);
247+
addClass(element, QUEUED_CLASSNAME);
248+
player.onStart(() => { removeClass(element, QUEUED_CLASSNAME); });
234249
}
235250

236251
player.onDone(() => {
237-
removeClass(element, NG_ANIMATING_CLASSNAME);
238-
239252
let index = this.players.indexOf(player);
240253
if (index >= 0) {
241254
this.players.splice(index, 1);
@@ -259,7 +272,7 @@ export class AnimationTransitionNamespace {
259272
deregister(name: string) {
260273
delete this._triggers[name];
261274

262-
this._engine.statesByElement.forEach((stateMap, _element) => { delete stateMap[name]; });
275+
this._engine.statesByElement.forEach((stateMap, element) => { delete stateMap[name]; });
263276

264277
this._elementListeners.forEach((listeners, element) => {
265278
this._elementListeners.set(
@@ -392,7 +405,7 @@ export class AnimationTransitionNamespace {
392405
}
393406
}
394407

395-
insertNode(element: any, _parent: any): void { addClass(element, this._hostClassName); }
408+
insertNode(element: any, parent: any): void { addClass(element, this._hostClassName); }
396409

397410
drainQueuedTransitions(microtaskId: number): QueueInstruction[] {
398411
const instructions: QueueInstruction[] = [];
@@ -464,6 +477,8 @@ export class TransitionAnimationEngine {
464477
public playersByElement = new Map<any, TransitionAnimationPlayer[]>();
465478
public playersByQueriedElement = new Map<any, TransitionAnimationPlayer[]>();
466479
public statesByElement = new Map<any, {[triggerName: string]: StateValue}>();
480+
public disabledNodes = new Set<any>();
481+
467482
public totalAnimations = 0;
468483
public totalQueuedPlayers = 0;
469484

@@ -477,7 +492,7 @@ export class TransitionAnimationEngine {
477492
public collectedLeaveElements: any[] = [];
478493

479494
// this method is designed to be overridden by the code that uses this engine
480-
public onRemovalComplete = (_element: any, _context: any) => {};
495+
public onRemovalComplete = (element: any, context: any) => {};
481496

482497
_onRemovalComplete(element: any, context: any) { this.onRemovalComplete(element, context); }
483498

@@ -605,6 +620,18 @@ export class TransitionAnimationEngine {
605620

606621
collectEnterElement(element: any) { this.collectedEnterElements.push(element); }
607622

623+
markElementAsDisabled(element: any, value: boolean) {
624+
if (value) {
625+
if (!this.disabledNodes.has(element)) {
626+
this.disabledNodes.add(element);
627+
addClass(element, DISABLED_CLASSNAME);
628+
}
629+
} else if (this.disabledNodes.has(element)) {
630+
this.disabledNodes.delete(element);
631+
removeClass(element, DISABLED_CLASSNAME);
632+
}
633+
}
634+
608635
removeNode(namespaceId: string, element: any, context: any, doNotRecurse?: boolean): void {
609636
if (!isElementNode(element)) {
610637
this._onRemovalComplete(element, context);
@@ -702,6 +729,14 @@ export class TransitionAnimationEngine {
702729
}
703730
this._onRemovalComplete(element, details.setForRemoval);
704731
}
732+
733+
if (this.driver.matchesElement(element, DISABLED_SELECTOR)) {
734+
this.markElementAsDisabled(element, false);
735+
}
736+
737+
this.driver.query(element, DISABLED_SELECTOR, true).forEach(node => {
738+
this.markElementAsDisabled(element, false);
739+
});
705740
}
706741

707742
flush(microtaskId: number = -1) {
@@ -759,6 +794,14 @@ export class TransitionAnimationEngine {
759794
const allPreStyleElements = new Map<any, Set<string>>();
760795
const allPostStyleElements = new Map<any, Set<string>>();
761796

797+
const disabledElementsSet = new Set<any>();
798+
this.disabledNodes.forEach(node => {
799+
const nodesThatAreDisabled = this.driver.query(node, QUEUED_SELECTOR, true);
800+
for (let i = 0; i < nodesThatAreDisabled.length; i++) {
801+
disabledElementsSet.add(nodesThatAreDisabled[i]);
802+
}
803+
});
804+
762805
const bodyNode = getBodyNode();
763806
const allEnterNodes: any[] = this.collectedEnterElements.length ?
764807
this.collectedEnterElements.filter(createIsRootFilterFn(this.collectedEnterElements)) :
@@ -808,7 +851,7 @@ export class TransitionAnimationEngine {
808851
}
809852

810853
const instruction = this._buildInstruction(entry, subTimelines) !;
811-
if ((<any>instruction).errors && (<any>instruction).errors.length) {
854+
if (instruction.errors && instruction.errors.length) {
812855
erroneousTransitions.push(instruction);
813856
return;
814857
}
@@ -864,7 +907,7 @@ export class TransitionAnimationEngine {
864907
let msg = `Unable to process animations due to the following failed trigger transitions\n`;
865908
erroneousTransitions.forEach(instruction => {
866909
msg += `@${instruction.triggerName} has failed due to:\n`;
867-
(<any>instruction).errors !.forEach(error => { msg += `- ${error}\n`; });
910+
instruction.errors !.forEach(error => { msg += `- ${error}\n`; });
868911
});
869912

870913
allPlayers.forEach(player => player.destroy());
@@ -919,6 +962,11 @@ export class TransitionAnimationEngine {
919962
// this means that it was never consumed by a parent animation which
920963
// means that it is independent and therefore should be set for animation
921964
if (subTimelines.has(element)) {
965+
if (disabledElementsSet.has(element)) {
966+
skippedPlayers.push(player);
967+
return;
968+
}
969+
922970
const innerPlayer = this._buildAnimation(
923971
player.namespaceId, instruction, allPreviousPlayersMap, skippedPlayersMap, preStylesMap,
924972
postStylesMap);

Diff for: nativescript-angular/animations/private-imports/util.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
98
/* tslint:disable */
109
import {AnimateTimings, AnimationMetadata, AnimationOptions, sequence, ɵStyleData} from '@angular/animations';
1110

@@ -218,4 +217,4 @@ export function dashCaseToCamelCase(input: string): string {
218217

219218
export function allowPreviousPlayerStylesMerge(duration: number, delay: number) {
220219
return duration === 0 || delay === 0;
221-
}
220+
}

0 commit comments

Comments
 (0)