Skip to content

fix(animations): set nodeType 'element' to newly created views #720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions nativescript-angular/animations/animation-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
setStyles,
} from "./dom-utils";

const MARKED_FOR_ANIMATION = "ng-animate";
const MARKED_FOR_ANIMATION_CLASSNAME = "ng-animating";
const MARKED_FOR_ANIMATION_SELECTOR = ".ng-animating";

interface QueuedAnimationTransitionTuple {
element: NgView;
Expand Down Expand Up @@ -50,9 +51,9 @@ export class NativeScriptAnimationEngine extends DomAnimationEngine {
// we first run this so that the previous animation player
// data can be passed into the successive animation players
let totalTime = 0;
const players = instruction.timelines.map(timelineInstruction => {
const players = instruction.timelines.map((timelineInstruction, i) => {
totalTime = Math.max(totalTime, timelineInstruction.totalTime);
return (<any>this)._buildPlayer(element, timelineInstruction, previousPlayers);
return (<any>this)._buildPlayer(element, timelineInstruction, previousPlayers, i);
});

previousPlayers.forEach(previousPlayer => previousPlayer.destroy());
Expand Down Expand Up @@ -91,7 +92,7 @@ export class NativeScriptAnimationEngine extends DomAnimationEngine {
// them out by destroying each of them.
let elms = [];
(<any>element)._eachChildView(child => {
if (cssClasses(<NgView>child).get(MARKED_FOR_ANIMATION)) {
if (cssClasses(<NgView>child).get(MARKED_FOR_ANIMATION_SELECTOR)) {
elms.push(child);
}

Expand Down Expand Up @@ -129,8 +130,8 @@ export class NativeScriptAnimationEngine extends DomAnimationEngine {
(<any>this)._queuedTransitionAnimations.push(tuple);
player.init();

cssClasses(element).set(MARKED_FOR_ANIMATION, true);
player.onDone(() => cssClasses(element).set(MARKED_FOR_ANIMATION, false));
cssClasses(element).set(MARKED_FOR_ANIMATION_CLASSNAME, true);
player.onDone(() => cssClasses(element).set(MARKED_FOR_ANIMATION_CLASSNAME, false));
}

private _getElementAnimation(element: NgView) {
Expand Down
1 change: 1 addition & 0 deletions nativescript-angular/element-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface ViewClassMeta {
}

export interface ViewExtensions {
nodeType: number;
nodeName: string;
templateParent: NgView;
ngCssClasses: Map<string, boolean>;
Expand Down
8 changes: 8 additions & 0 deletions nativescript-angular/view-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { platformNames, Device } from "platform";
import { rendererLog as traceLog, styleError } from "./trace";

const XML_ATTRIBUTES = Object.freeze(["style", "rows", "columns", "fontAttributes"]);
const ELEMENT_NODE_TYPE = 1;
const whiteSpaceSplitter = /\s+/;

export type ViewExtensions = ViewExtensions;
Expand Down Expand Up @@ -144,6 +145,13 @@ export class ViewUtil {
view.nodeName = name;
view.meta = getViewMeta(name);

// we're setting the node type of the view
// to 'element' because of checks done in the
// dom animation engine:
// tslint:disable-next-line:max-line-length
// https://github.com/angular/angular/blob/master/packages/animations/browser/src/render/dom_animation_engine.ts#L70-L81
view.nodeType = ELEMENT_NODE_TYPE;

return view;
}

Expand Down
1 change: 1 addition & 0 deletions tests/app/tests/property-sets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {createDevice} from "./test-utils";

class TestView extends View implements ViewExtensions {
public nodeName: string = "TestView";
public nodeType: number = 1;
public templateParent: NgView = null;
public meta: ViewClassMeta = { skipAddToDom: false };
public ngCssClasses: Map<string, boolean> = new Map<string, boolean>();
Expand Down