@@ -210,14 +210,44 @@ var ScrollView = React.createClass({
210
210
return React . findNodeHandle ( this . refs [ INNERVIEW ] ) ;
211
211
} ,
212
212
213
- scrollTo : function ( destY ?: number , destX ?: number ) {
213
+ scrollTo : function ( destY ?: number , destX ?: number , options ?: { animated ?: bool , duration ?: number } ) {
214
214
if ( Platform . OS === 'android' ) {
215
+ // TODO: update to allow for custom duration which is already enabled on iOS
215
216
RCTUIManager . dispatchViewManagerCommand (
216
217
React . findNodeHandle ( this ) ,
217
218
RCTUIManager . RCTScrollView . Commands . scrollTo ,
218
219
[ destX || 0 , destY || 0 ]
219
220
) ;
220
221
} else {
222
+ var animated = options && options . animated || ! options ;
223
+
224
+ if ( ! animated ) {
225
+ // scroll with no animation
226
+ RCTUIManager . scrollWithoutAnimationTo (
227
+ React . findNodeHandle ( this ) ,
228
+ destX || 0 ,
229
+ destY || 0
230
+ ) ;
231
+ return ;
232
+ }
233
+
234
+ // scroll using RCTAnimation with custom duration if a duration was passed
235
+ if ( animated && ! isNaN ( options . duration ) ) {
236
+ invariant (
237
+ options . duration >= 0 ,
238
+ 'Duration passed to ScrollView \'scrollTo\' ' +
239
+ 'should be greater than or equal to 0.'
240
+ ) ;
241
+ RCTUIManager . scrollWithCustomDurationTo (
242
+ React . findNodeHandle ( this ) ,
243
+ destX || 0 ,
244
+ destY || 0 ,
245
+ options . duration
246
+ ) ;
247
+ return ;
248
+ }
249
+
250
+ // Default scroll behavior
221
251
RCTUIManager . scrollTo (
222
252
React . findNodeHandle ( this ) ,
223
253
destX || 0 ,
@@ -227,20 +257,7 @@ var ScrollView = React.createClass({
227
257
} ,
228
258
229
259
scrollWithoutAnimationTo : function ( destY ?: number , destX ?: number ) {
230
- RCTUIManager . scrollWithoutAnimationTo (
231
- React . findNodeHandle ( this ) ,
232
- destX || 0 ,
233
- destY || 0
234
- ) ;
235
- } ,
236
-
237
- scrollWithCustomDurationTo : function ( destY ?: number , destX ?: number , duration ?: number ) {
238
- RCTUIManager . scrollWithCustomDurationTo (
239
- React . findNodeHandle ( this ) ,
240
- destX || 0 ,
241
- destY || 0 ,
242
- duration || 0
243
- ) ;
260
+ this . scrollTo ( destY , destX , { animated : false } ) ;
244
261
} ,
245
262
246
263
render : function ( ) {
0 commit comments