mirror of
https://github.com/status-im/react-native.git
synced 2025-01-27 09:45:04 +00:00
Make the scrollResponderScrollNativeHandleToKeyboard works on Android
This commit is contained in:
parent
e01f90784f
commit
accf6f12e4
@ -12,13 +12,13 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var NativeModules = require('NativeModules');
|
var NativeModules = require('NativeModules');
|
||||||
|
var Platform = require('Platform');
|
||||||
var RCTDeviceEventEmitter = require('RCTDeviceEventEmitter');
|
var RCTDeviceEventEmitter = require('RCTDeviceEventEmitter');
|
||||||
var React = require('React');
|
var React = require('React');
|
||||||
var Subscribable = require('Subscribable');
|
var Subscribable = require('Subscribable');
|
||||||
var TextInputState = require('TextInputState');
|
var TextInputState = require('TextInputState');
|
||||||
|
|
||||||
var RCTUIManager = NativeModules.UIManager;
|
var RCTUIManager = NativeModules.UIManager;
|
||||||
var RCTUIManagerDeprecated = NativeModules.UIManager;
|
|
||||||
var RCTScrollViewConsts = RCTUIManager.RCTScrollView.Constants;
|
var RCTScrollViewConsts = RCTUIManager.RCTScrollView.Constants;
|
||||||
|
|
||||||
var warning = require('warning');
|
var warning = require('warning');
|
||||||
@ -351,7 +351,19 @@ var ScrollResponderMixin = {
|
|||||||
* can also be used to quickly scroll to any element we want to focus
|
* can also be used to quickly scroll to any element we want to focus
|
||||||
*/
|
*/
|
||||||
scrollResponderScrollTo: function(offsetX: number, offsetY: number) {
|
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}
|
* @param {object} rect Should have shape {x, y, width, height}
|
||||||
*/
|
*/
|
||||||
scrollResponderZoomTo: function(rect: { x: number; y: number; width: number; height: number; }) {
|
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;
|
this.preventNegativeScrollOffset = !!preventNegativeScrollOffset;
|
||||||
RCTUIManager.measureLayout(
|
RCTUIManager.measureLayout(
|
||||||
nodeHandle,
|
nodeHandle,
|
||||||
React.findNodeHandle(this),
|
React.findNodeHandle(this.getInnerViewNode()),
|
||||||
this.scrollResponderTextInputFocusError,
|
this.scrollResponderTextInputFocusError,
|
||||||
this.scrollResponderInputMeasureAndScrollToKeyboard
|
this.scrollResponderInputMeasureAndScrollToKeyboard
|
||||||
);
|
);
|
||||||
@ -429,6 +441,10 @@ var ScrollResponderMixin = {
|
|||||||
this.addListenerOn(RCTDeviceEventEmitter, 'keyboardWillHide', this.scrollResponderKeyboardWillHide);
|
this.addListenerOn(RCTDeviceEventEmitter, 'keyboardWillHide', this.scrollResponderKeyboardWillHide);
|
||||||
this.addListenerOn(RCTDeviceEventEmitter, 'keyboardDidShow', this.scrollResponderKeyboardDidShow);
|
this.addListenerOn(RCTDeviceEventEmitter, 'keyboardDidShow', this.scrollResponderKeyboardDidShow);
|
||||||
this.addListenerOn(RCTDeviceEventEmitter, 'keyboardDidHide', this.scrollResponderKeyboardDidHide);
|
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.');
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -286,19 +286,8 @@ var ScrollView = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
scrollTo: function(destY?: number, destX?: number) {
|
scrollTo: function(destY?: number, destX?: number) {
|
||||||
if (Platform.OS === 'android') {
|
// $FlowFixMe - Don't know how to pass Mixin correctly. Postpone for now
|
||||||
RCTUIManager.dispatchViewManagerCommand(
|
this.getScrollResponder().scrollResponderScrollTo(destX || 0, destY || 0);
|
||||||
React.findNodeHandle(this),
|
|
||||||
RCTUIManager.RCTScrollView.Commands.scrollTo,
|
|
||||||
[destX || 0, destY || 0]
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
RCTUIManager.scrollTo(
|
|
||||||
React.findNodeHandle(this),
|
|
||||||
destX || 0,
|
|
||||||
destY || 0
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
scrollWithoutAnimationTo: function(destY?: number, destX?: number) {
|
scrollWithoutAnimationTo: function(destY?: number, destX?: number) {
|
||||||
|
@ -252,6 +252,10 @@ var ListView = React.createClass({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getInnerViewNode: function() {
|
||||||
|
return this.refs[SCROLLVIEW_REF].getInnerViewNode();
|
||||||
|
},
|
||||||
|
|
||||||
componentWillMount: function() {
|
componentWillMount: function() {
|
||||||
// this data should never trigger a render pass, so don't put in state
|
// this data should never trigger a render pass, so don't put in state
|
||||||
this.scrollProperties = {
|
this.scrollProperties = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user