mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
Open sourced the onSelectionChange event
Summary: public Open-sourced the onSelectionChange event for RCTTextView, and also added onSelectionChange support for RCTTextField. Reviewed By: javache Differential Revision: D2647541 fb-gh-sync-id: ab0ab37f5f087e708a199461ffc33231a47d2133
This commit is contained in:
committed by
facebook-github-bot-7
parent
397791fcea
commit
5a34a097f2
@@ -31,7 +31,6 @@ var invariant = require('invariant');
|
||||
var requireNativeComponent = require('requireNativeComponent');
|
||||
|
||||
var onlyMultiline = {
|
||||
onSelectionChange: true, // not supported in Open Source yet
|
||||
onTextInput: true, // not supported in Open Source yet
|
||||
children: true,
|
||||
};
|
||||
@@ -413,6 +412,17 @@ var TextInput = React.createClass({
|
||||
_renderIOS: function() {
|
||||
var textContainer;
|
||||
|
||||
var onSelectionChange;
|
||||
if (this.props.selectionState || this.props.onSelectionChange) {
|
||||
onSelectionChange = function(event: Event) {
|
||||
if (this.props.selectionState) {
|
||||
var selection = event.nativeEvent.selection;
|
||||
this.props.selectionState.update(selection.start, selection.end);
|
||||
}
|
||||
this.props.onSelectionChange && this.props.onSelectionChange(event);
|
||||
};
|
||||
}
|
||||
|
||||
var props = Object.assign({}, this.props);
|
||||
props.style = [styles.input, this.props.style];
|
||||
if (!props.multiline) {
|
||||
@@ -430,7 +440,8 @@ var TextInput = React.createClass({
|
||||
onFocus={this._onFocus}
|
||||
onBlur={this._onBlur}
|
||||
onChange={this._onChange}
|
||||
onSelectionChangeShouldSetResponder={() => true}
|
||||
onSelectionChange={onSelectionChange}
|
||||
onSelectionChangeShouldSetResponder={emptyFunction.thatReturnsTrue}
|
||||
text={this._getText()}
|
||||
mostRecentEventCount={this.state.mostRecentEventCount}
|
||||
/>;
|
||||
@@ -465,7 +476,7 @@ var TextInput = React.createClass({
|
||||
onFocus={this._onFocus}
|
||||
onBlur={this._onBlur}
|
||||
onChange={this._onChange}
|
||||
onSelectionChange={this._onSelectionChange}
|
||||
onSelectionChange={onSelectionChange}
|
||||
onTextInput={this._onTextInput}
|
||||
onSelectionChangeShouldSetResponder={emptyFunction.thatReturnsTrue}
|
||||
text={this._getText()}
|
||||
@@ -581,14 +592,6 @@ var TextInput = React.createClass({
|
||||
}
|
||||
},
|
||||
|
||||
_onSelectionChange: function(event: Event) {
|
||||
if (this.props.selectionState) {
|
||||
var selection = event.nativeEvent.selection;
|
||||
this.props.selectionState.update(selection.start, selection.end);
|
||||
}
|
||||
this.props.onSelectionChange && this.props.onSelectionChange(event);
|
||||
},
|
||||
|
||||
_onTextInput: function(event: Event) {
|
||||
this.props.onTextInput && this.props.onTextInput(event);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user