diff --git a/Libraries/Components/TextInput/TextInput.js b/Libraries/Components/TextInput/TextInput.js
index 62ff5f2a8..53bc6235d 100644
--- a/Libraries/Components/TextInput/TextInput.js
+++ b/Libraries/Components/TextInput/TextInput.js
@@ -216,6 +216,10 @@ var TextInput = React.createClass({
* Callback that is called when text input ends.
*/
onEndEditing: PropTypes.func,
+ /**
+ * Callback that is called when the text input selection is changed
+ */
+ onSelectionChange: PropTypes.func,
/**
* Callback that is called when the text input's submit button is pressed.
* Invalid if multiline={true} is specified.
@@ -474,6 +478,17 @@ var TextInput = React.createClass({
},
_renderAndroid: function() {
+ var onSelectionChange;
+ if (this.props.selectionState || this.props.onSelectionChange) {
+ onSelectionChange = (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 autoCapitalize = UIManager.UIText.AutocapitalizationType[this.props.autoCapitalize];
var textAlign =
UIManager.AndroidTextInput.Constants.TextAlign[this.props.textAlign];
@@ -489,6 +504,7 @@ var TextInput = React.createClass({
if (childCount > 1) {
children = {children};
}
+
var textContainer =
{
+
+ private static final String EVENT_NAME = "topSelectionChange";
+
+ private int mSelectionStart;
+ private int mSelectionEnd;
+
+ public ReactTextInputSelectionEvent(
+ int viewId,
+ long timestampMs,
+ int selectionStart,
+ int selectionEnd) {
+ super(viewId, timestampMs);
+ mSelectionStart = selectionStart;
+ mSelectionEnd = selectionEnd;
+ }
+
+ @Override
+ public String getEventName() {
+ return EVENT_NAME;
+ }
+
+ @Override
+ public void dispatch(RCTEventEmitter rctEventEmitter) {
+ rctEventEmitter.receiveEvent(getViewTag(), getEventName(), serializeEventData());
+ }
+
+ private WritableMap serializeEventData() {
+ WritableMap eventData = Arguments.createMap();
+
+ WritableMap selectionData = Arguments.createMap();
+ selectionData.putInt("start", mSelectionStart);
+ selectionData.putInt("end", mSelectionEnd);
+
+ eventData.putMap("selection", selectionData);
+ return eventData;
+ }
+}
diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/SelectionWatcher.java b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/SelectionWatcher.java
new file mode 100644
index 000000000..f569067ab
--- /dev/null
+++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/SelectionWatcher.java
@@ -0,0 +1,18 @@
+/**
+ * Copyright (c) 2015-present, Facebook, Inc.
+ * All rights reserved.
+ *
+ * This source code is licensed under the BSD-style license found in the
+ * LICENSE file in the root directory of this source tree. An additional grant
+ * of patent rights can be found in the PATENTS file in the same directory.
+ */
+
+package com.facebook.react.views.textinput;
+
+/**
+ * Implement this interface to be informed of selection changes in the ReactTextEdit
+ * This is used by the ReactTextInputManager to forward events from the EditText to JS
+ */
+interface SelectionWatcher {
+ public void onSelectionChanged(int start, int end);
+}