@@ -10,6 +10,8 @@ import {
10
10
import { NgView } from "../element-registry" ;
11
11
import { animationsLog as traceLog } from "../trace" ;
12
12
13
+ import { createSelector , SelectorCore } from "tns-core-modules/ui/styling/css-selector" ;
14
+
13
15
export class NativeScriptAnimationDriver implements AnimationDriver {
14
16
matchesElement ( _element : any , _selector : string ) : boolean {
15
17
// this method is never called since NG 4.2.5
@@ -34,28 +36,50 @@ export class NativeScriptAnimationDriver implements AnimationDriver {
34
36
return found ;
35
37
}
36
38
37
- // traverse children and check if they have the provided class
38
- query ( element : any , selector : string , multi : boolean ) : any [ ] {
39
+ query ( element : NgView , selector : string , multi : boolean ) : NgView [ ] {
39
40
traceLog (
40
41
`NativeScriptAnimationDriver.query ` +
41
42
`element: ${ element } , selector: ${ selector } ` +
42
43
`multi: ${ multi } `
43
44
) ;
44
45
46
+ const selectors = selector . split ( "," ) . map ( s => s . trim ( ) ) ;
47
+
48
+ const nsSelectors : SelectorCore [ ] = selectors . map ( createSelector ) ;
49
+ const classSelectors = selectors
50
+ . filter ( s => s . startsWith ( "." ) )
51
+ . map ( s => s . substring ( 1 ) ) ;
52
+
53
+ return this . visitDescendants ( element , nsSelectors , classSelectors , multi ) ;
54
+ }
55
+
56
+ private visitDescendants (
57
+ element : NgView ,
58
+ nsSelectors : SelectorCore [ ] ,
59
+ classSelectors : string [ ] ,
60
+ multi : boolean ) : NgView [ ] {
61
+
45
62
let results = [ ] ;
46
- element . eachChild ( child => {
47
- if ( child [ selector ] ) {
63
+ eachDescendant ( element , child => {
64
+ if ( nsSelectors . some ( s => s . match ( child ) ) ||
65
+ classSelectors . some ( s => this . hasClass ( child , s ) ) ) {
48
66
results . push ( child ) ;
49
-
50
- return ! multi ;
67
+ return multi ;
51
68
}
52
69
53
- return false ;
70
+ return true ;
54
71
} ) ;
55
72
56
73
return results ;
57
74
}
58
75
76
+ // we're using that instead of match for classes
77
+ // that are dynamically added by the animation engine
78
+ // such as .ng-trigger, that's added for every :enter view
79
+ private hasClass ( element : any , cls : string ) {
80
+ return element [ "$$classes" ] [ cls ] ;
81
+ }
82
+
59
83
computeStyle ( element : NgView , prop : string ) : string {
60
84
traceLog (
61
85
`NativeScriptAnimationDriver.computeStyle ` +
0 commit comments