@@ -20,10 +20,6 @@ import type AnimatedTracking from './AnimatedTracking';
20
20
21
21
const NativeAnimatedAPI = NativeAnimatedHelper . API ;
22
22
23
- type ValueListenerCallback = ( state : { value : number } ) => void ;
24
-
25
- let _uniqueId = 1 ;
26
-
27
23
/**
28
24
* Animated works by building a directed acyclic graph of dependencies
29
25
* transparently when you render your Animated components.
@@ -77,15 +73,12 @@ class AnimatedValue extends AnimatedWithChildren {
77
73
_offset : number ;
78
74
_animation : ?Animation ;
79
75
_tracking : ?AnimatedTracking ;
80
- _listeners : { [ key : string ] : ValueListenerCallback } ;
81
- __nativeAnimatedValueListener: ?any ;
82
76
83
77
constructor ( value : number ) {
84
78
super ( ) ;
85
79
this . _startingValue = this . _value = value ;
86
80
this . _offset = 0 ;
87
81
this . _animation = null ;
88
- this . _listeners = { } ;
89
82
}
90
83
91
84
__detach ( ) {
@@ -97,14 +90,6 @@ class AnimatedValue extends AnimatedWithChildren {
97
90
return this . _value + this . _offset ;
98
91
}
99
92
100
- __makeNative ( ) {
101
- super . __makeNative ( ) ;
102
-
103
- if ( Object . keys ( this . _listeners ) . length ) {
104
- this . _startListeningToNativeValueUpdates ( ) ;
105
- }
106
- }
107
-
108
93
/**
109
94
* Directly set the value. This will stop any animations running on the value
110
95
* and update all the bound properties.
@@ -167,74 +152,6 @@ class AnimatedValue extends AnimatedWithChildren {
167
152
}
168
153
}
169
154
170
- /**
171
- * Adds an asynchronous listener to the value so you can observe updates from
172
- * animations. This is useful because there is no way to
173
- * synchronously read the value because it might be driven natively.
174
- *
175
- * See http://facebook.github.io/react-native/docs/animatedvalue.html#addlistener
176
- */
177
- addListener ( callback : ValueListenerCallback ) : string {
178
- const id = String ( _uniqueId ++ ) ;
179
- this . _listeners [ id ] = callback ;
180
- if ( this . __isNative ) {
181
- this . _startListeningToNativeValueUpdates ( ) ;
182
- }
183
- return id ;
184
- }
185
-
186
- /**
187
- * Unregister a listener. The `id` param shall match the identifier
188
- * previously returned by `addListener()`.
189
- *
190
- * See http://facebook.github.io/react-native/docs/animatedvalue.html#removelistener
191
- */
192
- removeListener ( id : string ) : void {
193
- delete this . _listeners [ id ] ;
194
- if ( this . __isNative && Object . keys ( this . _listeners ) . length === 0 ) {
195
- this . _stopListeningForNativeValueUpdates ( ) ;
196
- }
197
- }
198
-
199
- /**
200
- * Remove all registered listeners.
201
- *
202
- * See http://facebook.github.io/react-native/docs/animatedvalue.html#removealllisteners
203
- */
204
- removeAllListeners ( ) : void {
205
- this . _listeners = { } ;
206
- if ( this . __isNative ) {
207
- this . _stopListeningForNativeValueUpdates ( ) ;
208
- }
209
- }
210
-
211
- _startListeningToNativeValueUpdates ( ) {
212
- if ( this . __nativeAnimatedValueListener ) {
213
- return ;
214
- }
215
-
216
- NativeAnimatedAPI . startListeningToAnimatedNodeValue ( this . __getNativeTag ( ) ) ;
217
- this . __nativeAnimatedValueListener = NativeAnimatedHelper . nativeEventEmitter . addListener (
218
- 'onAnimatedValueUpdate' ,
219
- data => {
220
- if ( data . tag !== this . __getNativeTag ( ) ) {
221
- return ;
222
- }
223
- this . _updateValue ( data . value , false /* flush */ ) ;
224
- } ,
225
- ) ;
226
- }
227
-
228
- _stopListeningForNativeValueUpdates ( ) {
229
- if ( ! this . __nativeAnimatedValueListener ) {
230
- return ;
231
- }
232
-
233
- this . __nativeAnimatedValueListener . remove ( ) ;
234
- this . __nativeAnimatedValueListener = null ;
235
- NativeAnimatedAPI . stopListeningToAnimatedNodeValue ( this . __getNativeTag ( ) ) ;
236
- }
237
-
238
155
/**
239
156
* Stops any running animation or tracking. `callback` is invoked with the
240
157
* final value after stopping the animation, which is useful for updating
@@ -259,6 +176,10 @@ class AnimatedValue extends AnimatedWithChildren {
259
176
this . _value = this . _startingValue ;
260
177
}
261
178
179
+ _onAnimatedValueUpdateReceived ( value : number ) : void {
180
+ this. _updateValue ( value , false /*flush*/ ) ;
181
+ }
182
+
262
183
/**
263
184
* Interpolates the value before updating the property, e.g. mapping 0-1 to
264
185
* 0-10.
@@ -321,9 +242,7 @@ class AnimatedValue extends AnimatedWithChildren {
321
242
if ( flush ) {
322
243
_flush ( this ) ;
323
244
}
324
- for ( const key in this . _listeners ) {
325
- this . _listeners [ key ] ( { value : this . __getValue ( ) } ) ;
326
- }
245
+ super . __callListeners ( this . __getValue ( ) ) ;
327
246
}
328
247
329
248
__getNativeConfig ( ) : Object {
0 commit comments