diff --git a/Libraries/Components/TextInput/TextInput.js b/Libraries/Components/TextInput/TextInput.js index 2c56ef73206..6caa6bbef04 100644 --- a/Libraries/Components/TextInput/TextInput.js +++ b/Libraries/Components/TextInput/TextInput.js @@ -10,7 +10,6 @@ 'use strict'; const DeprecatedTextInputPropTypes = require('../../DeprecatedPropTypes/DeprecatedTextInputPropTypes'); -const DocumentSelectionState = require('../../vendor/document/selection/DocumentSelectionState'); const NativeMethodsMixin = require('../../Renderer/shims/NativeMethodsMixin'); const Platform = require('../../Utilities/Platform'); const React = require('react'); @@ -221,23 +220,6 @@ type IOSProps = $ReadOnly<{| */ enablesReturnKeyAutomatically?: ?boolean, - /** - * An instance of `DocumentSelectionState`, this is some state that is responsible for - * maintaining selection information for a document. - * - * Some functionality that can be performed with this instance is: - * - * - `blur()` - * - `focus()` - * - `update()` - * - * > You can reference `DocumentSelectionState` in - * > [`vendor/document/selection/DocumentSelectionState.js`](https://github.com/facebook/react-native/blob/master/Libraries/vendor/document/selection/DocumentSelectionState.js) - * - * @platform ios - */ - selectionState?: ?DocumentSelectionState, - /** * When the clear button should appear on the right side of the text view. * This property is supported only for single-line TextInput component. @@ -1115,10 +1097,6 @@ const TextInput = createReactClass({ if (this.props.onFocus) { this.props.onFocus(event); } - - if (this.props.selectionState) { - this.props.selectionState.focus(); - } }, _onPress: function(event: PressEvent) { @@ -1161,7 +1139,7 @@ const TextInput = createReactClass({ this._lastNativeSelection = event.nativeEvent.selection; - if (this.props.selection || this.props.selectionState) { + if (this.props.selection) { this.forceUpdate(); } }, @@ -1198,10 +1176,6 @@ const TextInput = createReactClass({ ) { this._inputRef.setNativeProps(nativeProps); } - - if (this.props.selectionState && selection) { - this.props.selectionState.update(selection.start, selection.end); - } }, _onBlur: function(event: BlurEvent) { @@ -1211,10 +1185,6 @@ const TextInput = createReactClass({ if (this.props.onBlur) { this.props.onBlur(event); } - - if (this.props.selectionState) { - this.props.selectionState.blur(); - } }, _onTextInput: function(event: TextInputEvent) { diff --git a/Libraries/DeprecatedPropTypes/DeprecatedTextInputPropTypes.js b/Libraries/DeprecatedPropTypes/DeprecatedTextInputPropTypes.js index 9288b0f01d1..649120eb125 100644 --- a/Libraries/DeprecatedPropTypes/DeprecatedTextInputPropTypes.js +++ b/Libraries/DeprecatedPropTypes/DeprecatedTextInputPropTypes.js @@ -12,7 +12,6 @@ const DeprecatedColorPropType = require('./DeprecatedColorPropType'); const DeprecatedViewPropTypes = require('./DeprecatedViewPropTypes'); -const DocumentSelectionState = require('../vendor/document/selection/DocumentSelectionState'); const PropTypes = require('prop-types'); const Text = require('../Text/Text'); @@ -388,22 +387,6 @@ module.exports = { * The highlight and cursor color of the text input. */ selectionColor: DeprecatedColorPropType, - /** - * An instance of `DocumentSelectionState`, this is some state that is responsible for - * maintaining selection information for a document. - * - * Some functionality that can be performed with this instance is: - * - * - `blur()` - * - `focus()` - * - `update()` - * - * > You can reference `DocumentSelectionState` in - * > [`vendor/document/selection/DocumentSelectionState.js`](https://github.com/facebook/react-native/blob/master/Libraries/vendor/document/selection/DocumentSelectionState.js) - * - * @platform ios - */ - selectionState: (PropTypes.instanceOf(DocumentSelectionState): void), /** * The start and end of the text input's selection. Set start and end to * the same value to position the cursor. diff --git a/Libraries/vendor/document/selection/DocumentSelectionState.js b/Libraries/vendor/document/selection/DocumentSelectionState.js deleted file mode 100644 index 577f192f508..00000000000 --- a/Libraries/vendor/document/selection/DocumentSelectionState.js +++ /dev/null @@ -1,150 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @format - * @typechecks - */ - -'use strict'; - -const mixInEventEmitter = require('../../emitter/mixInEventEmitter'); - -/** - * DocumentSelectionState is responsible for maintaining selection information - * for a document. - * - * It is intended for use by AbstractTextEditor-based components for - * identifying the appropriate start/end positions to modify the - * DocumentContent, and for programmatically setting browser selection when - * components re-render. - */ -class DocumentSelectionState { - /** - * @param {number} anchor - * @param {number} focus - */ - constructor(anchor, focus) { - this._anchorOffset = anchor; - this._focusOffset = focus; - this._hasFocus = false; - } - - /** - * Apply an update to the state. If either offset value has changed, - * set the values and emit the `change` event. Otherwise no-op. - * - * @param {number} anchor - * @param {number} focus - */ - update(anchor, focus) { - if (this._anchorOffset !== anchor || this._focusOffset !== focus) { - this._anchorOffset = anchor; - this._focusOffset = focus; - this.emit('update'); - } - } - - /** - * Given a max text length, constrain our selection offsets to ensure - * that the selection remains strictly within the text range. - * - * @param {number} maxLength - */ - constrainLength(maxLength) { - this.update( - Math.min(this._anchorOffset, maxLength), - Math.min(this._focusOffset, maxLength), - ); - } - - focus() { - if (!this._hasFocus) { - this._hasFocus = true; - this.emit('focus'); - } - } - - blur() { - if (this._hasFocus) { - this._hasFocus = false; - this.emit('blur'); - } - } - - /** - * @return {boolean} - */ - hasFocus() { - return this._hasFocus; - } - - /** - * @return {boolean} - */ - isCollapsed() { - return this._anchorOffset === this._focusOffset; - } - - /** - * @return {boolean} - */ - isBackward() { - return this._anchorOffset > this._focusOffset; - } - - /** - * @return {?number} - */ - getAnchorOffset() { - return this._hasFocus ? this._anchorOffset : null; - } - - /** - * @return {?number} - */ - getFocusOffset() { - return this._hasFocus ? this._focusOffset : null; - } - - /** - * @return {?number} - */ - getStartOffset() { - return this._hasFocus - ? Math.min(this._anchorOffset, this._focusOffset) - : null; - } - - /** - * @return {?number} - */ - getEndOffset() { - return this._hasFocus - ? Math.max(this._anchorOffset, this._focusOffset) - : null; - } - - /** - * @param {number} start - * @param {number} end - * @return {boolean} - */ - overlaps(start, end) { - return ( - this.hasFocus() && - this.getStartOffset() <= end && - start <= this.getEndOffset() - ); - } -} - -mixInEventEmitter(DocumentSelectionState, { - blur: true, - focus: true, - update: true, -}); - -module.exports = DocumentSelectionState;