Skip to content

Commit 607ea98

Browse files
committed
refactor: always set camelCase props for animations
1 parent 94eed63 commit 607ea98

File tree

3 files changed

+38
-15
lines changed

3 files changed

+38
-15
lines changed

Diff for: nativescript-angular/animations/animation-driver.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import { AnimationDriver } from "@angular/animations/browser";
33
import { eachDescendant } from "tns-core-modules/ui/core/view";
44

55
import { NativeScriptAnimationPlayer } from "./animation-player";
6-
import { Keyframe } from "./utils";
6+
import {
7+
Keyframe,
8+
dashCaseToCamelCase,
9+
} from "./utils";
710
import { NgView } from "../element-registry";
811
import { animationsLog as traceLog } from "../trace";
912

@@ -59,7 +62,8 @@ export class NativeScriptAnimationDriver implements AnimationDriver {
5962
`element: ${element}, prop: ${prop}`
6063
);
6164

62-
return element.style[`css-${prop}`];
65+
const camelCaseProp = dashCaseToCamelCase(prop);
66+
return element.style[camelCaseProp];
6367
}
6468

6569
animate(

Diff for: nativescript-angular/animations/transition-animation-engine.ts

+27-13
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1+
import { AUTO_STYLE, ɵPRE_STYLE as PRE_STYLE, AnimationPlayer, ɵStyleData } from "@angular/animations";
2+
import { AnimationDriver } from "@angular/animations/browser";
3+
import { AnimationTransitionInstruction } from "@angular/animations/browser/src/dsl/animation_transition_instruction";
4+
import { unsetValue } from "tns-core-modules/ui/core/view";
5+
16
import {
27
TransitionAnimationEngine,
38
TransitionAnimationPlayer,
49
QueuedTransition,
510
ElementAnimationState,
611
REMOVAL_FLAG,
712
} from "./private-imports/render/transition_animation_engine";
8-
import { AUTO_STYLE, ɵPRE_STYLE as PRE_STYLE, AnimationPlayer, ɵStyleData } from "@angular/animations";
9-
import { AnimationDriver } from "@angular/animations/browser";
10-
1113
import { ElementInstructionMap } from "./private-imports/dsl/element_instruction_map";
12-
import { AnimationTransitionInstruction } from "@angular/animations/browser/src/dsl/animation_transition_instruction";
14+
import { getOrSetAsInMap, optimizeGroupPlayer } from "./private-imports/render/shared";
1315
import {
1416
ENTER_CLASSNAME,
1517
LEAVE_CLASSNAME,
1618
NG_ANIMATING_SELECTOR,
17-
setStyles,
1819
} from "./private-imports/util";
19-
import { getOrSetAsInMap, optimizeGroupPlayer } from "./private-imports/render/shared";
20-
import { unsetValue } from "tns-core-modules/ui/core/view";
2120

21+
import { dashCaseToCamelCase } from "./utils";
2222
import { NgView } from "../element-registry";
2323

2424
const NULL_REMOVED_QUERIED_STATE: ElementAnimationState = {
@@ -29,11 +29,25 @@ const NULL_REMOVED_QUERIED_STATE: ElementAnimationState = {
2929
};
3030

3131
function eraseStylesOverride(element: NgView, styles: ɵStyleData) {
32-
if (element["style"]) {
33-
Object.keys(styles).forEach(prop => {
34-
element.style[prop] = unsetValue;
35-
});
32+
if (!element.style) {
33+
return;
3634
}
35+
36+
Object.keys(styles).forEach(prop => {
37+
const camelCaseProp = dashCaseToCamelCase(prop);
38+
element.style[camelCaseProp] = unsetValue;
39+
});
40+
}
41+
42+
function setStylesOverride(element: NgView, styles: ɵStyleData) {
43+
if (!element.style) {
44+
return;
45+
}
46+
47+
Object.keys(styles).forEach(prop => {
48+
const camelCaseProp = dashCaseToCamelCase(prop);
49+
element.style[camelCaseProp] = styles[prop];
50+
})
3751
}
3852

3953
// extending Angular's TransitionAnimationEngine
@@ -137,7 +151,7 @@ export class NSTransitionAnimationEngine extends TransitionAnimationEngine {
137151
// an animation and cancel the previously running animations.
138152
if (entry.isFallbackTransition) {
139153
player.onStart(() => eraseStylesOverride(element, instruction.fromStyles));
140-
player.onDestroy(() => setStyles(element, instruction.toStyles));
154+
player.onDestroy(() => setStylesOverride(element, instruction.toStyles));
141155
skippedPlayers.push(player);
142156
return;
143157
}
@@ -261,7 +275,7 @@ export class NSTransitionAnimationEngine extends TransitionAnimationEngine {
261275
}
262276
} else {
263277
eraseStylesOverride(element, instruction.fromStyles);
264-
player.onDestroy(() => setStyles(element, instruction.toStyles));
278+
player.onDestroy(() => setStylesOverride(element, instruction.toStyles));
265279
subPlayers.push(player);
266280
}
267281
});

Diff for: nativescript-angular/animations/utils.ts

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ export interface Keyframe {
1212
offset: number;
1313
}
1414

15+
const DASH_CASE_REGEXP = /-+([a-z0-9])/g;
16+
export function dashCaseToCamelCase(input: string): string {
17+
return input.replace(DASH_CASE_REGEXP, (...m: any[]) => m[1].toUpperCase());
18+
}
19+
1520
export function createKeyframeAnimation(
1621
styles: Keyframe[],
1722
duration: number,

0 commit comments

Comments
 (0)