11
11
'use strict' ;
12
12
13
13
const AnimatedValue = require ( './nodes/AnimatedValue' ) ;
14
+ const AnimatedValueXY = require ( './nodes/AnimatedValueXY' ) ;
14
15
const NativeAnimatedHelper = require ( './NativeAnimatedHelper' ) ;
15
16
const ReactNative = require ( '../Renderer/shims/ReactNative' ) ;
16
17
17
18
const invariant = require ( 'invariant' ) ;
18
19
19
20
const { shouldUseNativeDriver} = require ( './NativeAnimatedHelper' ) ;
20
21
21
- export type Mapping = { [ key : string ] : Mapping , ...} | AnimatedValue ;
22
+ export type Mapping =
23
+ | { [ key : string ] : Mapping , ...}
24
+ | AnimatedValue
25
+ | AnimatedValueXY ;
22
26
export type EventConfig = {
23
27
listener ?: ?Function ,
24
28
useNativeDriver : boolean ,
@@ -41,6 +45,9 @@ function attachNativeEvent(
41
45
nativeEventPath : path ,
42
46
animatedValueTag : value . __getNativeTag ( ) ,
43
47
} ) ;
48
+ } else if ( value instanceof AnimatedValueXY ) {
49
+ traverse ( value . x , path . concat ( 'x' ) ) ;
50
+ traverse ( value . y , path . concat ( 'y' ) ) ;
44
51
} else if ( typeof value === 'object' ) {
45
52
for ( const key in value ) {
46
53
traverse ( value [ key ] , path . concat ( key ) ) ;
@@ -95,6 +102,13 @@ function validateMapping(argMapping, args) {
95
102
) ;
96
103
return ;
97
104
}
105
+ if ( recMapping instanceof AnimatedValueXY ) {
106
+ invariant (
107
+ typeof recEvt . x === 'number' && typeof recEvt . y === 'number' ,
108
+ 'Bad mapping of event key ' + key + ', should be XY but got ' + recEvt ,
109
+ ) ;
110
+ return ;
111
+ }
98
112
if ( typeof recEvt === 'number' ) {
99
113
invariant (
100
114
recMapping instanceof AnimatedValue ,
@@ -204,22 +218,27 @@ class AnimatedEvent {
204
218
validatedMapping = true ;
205
219
}
206
220
207
- const traverse = ( recMapping , recEvt , key ) => {
221
+ const traverse = ( recMapping , recEvt ) => {
208
222
if ( recMapping instanceof AnimatedValue ) {
209
223
if ( typeof recEvt === 'number' ) {
210
224
recMapping . setValue ( recEvt ) ;
211
225
}
226
+ } else if ( recMapping instanceof AnimatedValueXY ) {
227
+ if ( typeof recEvt === 'object' ) {
228
+ traverse ( recMapping . x , recEvt . x ) ;
229
+ traverse ( recMapping . y , recEvt . y ) ;
230
+ }
212
231
} else if ( typeof recMapping === 'object' ) {
213
232
for ( const mappingKey in recMapping ) {
214
233
/* $FlowFixMe[prop-missing] (>=0.120.0) This comment suppresses an
215
234
* error found when Flow v0.120 was deployed. To see the error,
216
235
* delete this comment and run Flow. */
217
- traverse ( recMapping [ mappingKey ] , recEvt [ mappingKey ] , mappingKey ) ;
236
+ traverse ( recMapping [ mappingKey ] , recEvt [ mappingKey ] ) ;
218
237
}
219
238
}
220
239
} ;
221
240
this . _argMapping . forEach ( ( mapping , idx ) => {
222
- traverse ( mapping , args [ idx ] , 'arg' + idx ) ;
241
+ traverse ( mapping , args [ idx ] ) ;
223
242
} ) ;
224
243
225
244
this . _callListeners ( ...args ) ;
0 commit comments