diff --git a/Libraries/Components/ScrollResponder.js b/Libraries/Components/ScrollResponder.js index ab03e55fb..920b56478 100644 --- a/Libraries/Components/ScrollResponder.js +++ b/Libraries/Components/ScrollResponder.js @@ -12,13 +12,13 @@ 'use strict'; var NativeModules = require('NativeModules'); +var Platform = require('Platform'); var RCTDeviceEventEmitter = require('RCTDeviceEventEmitter'); var React = require('React'); var Subscribable = require('Subscribable'); var TextInputState = require('TextInputState'); var RCTUIManager = NativeModules.UIManager; -var RCTUIManagerDeprecated = NativeModules.UIManager; var RCTScrollViewConsts = RCTUIManager.RCTScrollView.Constants; var warning = require('warning'); @@ -351,7 +351,19 @@ var ScrollResponderMixin = { * can also be used to quickly scroll to any element we want to focus */ scrollResponderScrollTo: function(offsetX: number, offsetY: number) { - RCTUIManagerDeprecated.scrollTo(React.findNodeHandle(this), offsetX, offsetY); + if (Platform.OS === 'android') { + RCTUIManager.dispatchViewManagerCommand( + React.findNodeHandle(this), + RCTUIManager.RCTScrollView.Commands.scrollTo, + [offsetX, offsetY], + ); + } else { + RCTUIManager.scrollTo( + React.findNodeHandle(this), + offsetX, + offsetY + ); + } }, /** @@ -359,7 +371,7 @@ var ScrollResponderMixin = { * @param {object} rect Should have shape {x, y, width, height} */ scrollResponderZoomTo: function(rect: { x: number; y: number; width: number; height: number; }) { - RCTUIManagerDeprecated.zoomToRect(React.findNodeHandle(this), rect); + RCTUIManager.zoomToRect(React.findNodeHandle(this), rect); }, /** @@ -377,7 +389,7 @@ var ScrollResponderMixin = { this.preventNegativeScrollOffset = !!preventNegativeScrollOffset; RCTUIManager.measureLayout( nodeHandle, - React.findNodeHandle(this), + React.findNodeHandle(this.getInnerViewNode()), this.scrollResponderTextInputFocusError, this.scrollResponderInputMeasureAndScrollToKeyboard ); @@ -429,6 +441,10 @@ var ScrollResponderMixin = { this.addListenerOn(RCTDeviceEventEmitter, 'keyboardWillHide', this.scrollResponderKeyboardWillHide); this.addListenerOn(RCTDeviceEventEmitter, 'keyboardDidShow', this.scrollResponderKeyboardDidShow); this.addListenerOn(RCTDeviceEventEmitter, 'keyboardDidHide', this.scrollResponderKeyboardDidHide); + warning(this.getInnerViewNode, 'You need to implement getInnerViewNode in ' + + this.constructor.displayName + ' to get full' + + 'functionality from ScrollResponder mixin. See example of ListView and' + + ' ScrollView.'); }, /** diff --git a/Libraries/Components/ScrollView/ScrollView.js b/Libraries/Components/ScrollView/ScrollView.js index cd2dbf575..e82c5134b 100644 --- a/Libraries/Components/ScrollView/ScrollView.js +++ b/Libraries/Components/ScrollView/ScrollView.js @@ -286,19 +286,8 @@ var ScrollView = React.createClass({ }, scrollTo: function(destY?: number, destX?: number) { - if (Platform.OS === 'android') { - RCTUIManager.dispatchViewManagerCommand( - React.findNodeHandle(this), - RCTUIManager.RCTScrollView.Commands.scrollTo, - [destX || 0, destY || 0] - ); - } else { - RCTUIManager.scrollTo( - React.findNodeHandle(this), - destX || 0, - destY || 0 - ); - } + // $FlowFixMe - Don't know how to pass Mixin correctly. Postpone for now + this.getScrollResponder().scrollResponderScrollTo(destX || 0, destY || 0); }, scrollWithoutAnimationTo: function(destY?: number, destX?: number) { diff --git a/Libraries/CustomComponents/ListView/ListView.js b/Libraries/CustomComponents/ListView/ListView.js index b1183c253..fda582c3a 100644 --- a/Libraries/CustomComponents/ListView/ListView.js +++ b/Libraries/CustomComponents/ListView/ListView.js @@ -252,6 +252,10 @@ var ListView = React.createClass({ }; }, + getInnerViewNode: function() { + return this.refs[SCROLLVIEW_REF].getInnerViewNode(); + }, + componentWillMount: function() { // this data should never trigger a render pass, so don't put in state this.scrollProperties = {