Make the scrollResponderScrollNativeHandleToKeyboard works on Android

This commit is contained in:
Rui Chen 2015-07-23 17:57:42 -07:00
parent e01f90784f
commit accf6f12e4
3 changed files with 26 additions and 17 deletions

View File

@ -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.');
},
/**

View File

@ -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) {

View File

@ -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 = {