2015-02-19 20:10:52 -08:00
|
|
|
/**
|
2018-09-11 15:27:47 -07:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2015-03-23 13:35:08 -07:00
|
|
|
*
|
2018-02-16 18:24:55 -08:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-02-19 20:10:52 -08:00
|
|
|
*
|
2015-03-25 12:55:10 -07:00
|
|
|
* @flow
|
2018-01-14 19:32:22 -08:00
|
|
|
* @format
|
2015-02-19 20:10:52 -08:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
Back out TextInput es6 conversion
Summary:
This was failing due to issues with refs, which we were able to fix and then finally due to some jest tests that were failing due to things being null that shouldn't be which I couldn't easily figure out. Reverting the stack until we can actually solve it, hopefully with additional tests.
This was created by running:
```
$ hg backout c2fe2c46e538
fetching tree '' b9bbfc1925c6daf85ba3227d12f177aca9c0c054, based on 4257c76aefa84aaa17279e65aa7ca1174f4401e7, found via 02368b670953
connected to hg015.frc2.facebook.com
60 trees fetched over 2.91s
fetching tree '' c3c304df13399f0f1a29a668242da454fc1d8a97, based on b9bbfc1925c6daf85ba3227d12f177aca9c0c054, found via c2fe2c46e538
7 trees fetched over 0.03s
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
commit 4270328:50a65c5c2e27 backs out commit 4266783:c2fe2c46e538
1 files fetched over 1 fetches - (1 misses, 0.00% hit ratio) over 0.57s
[twsvcscm@sandcastle3265.ftw1 /data/sandcastle/boxes/instance-ide/xplat/js (50a65c5)]$ hg backout 02368b670953
fetching tree '' a46c8ca065f5b92cf375d7ed899fc5ca268ba4da, based on b9bbfc1925c6daf85ba3227d12f177aca9c0c054, found via bade4285eafb
connected to hg024.frc2.facebook.com
27 trees fetched over 3.21s
fetching tree '' 361548a090e81d18bab6f4fc16036c518cb4d7c1, based on a46c8ca065f5b92cf375d7ed899fc5ca268ba4da, found via bade4285eafb
41 trees fetched over 0.10s
merging react-native-github/Libraries/Components/TextInput/TextInput.js
8 files updated, 1 files merged, 0 files removed, 0 files unresolved
commit 4270329:dbaca0daf0ac backs out commit 4266782:02368b670953
14 files fetched over 7 fetches - (14 misses, 0.00% hit ratio) over 1.72s
[twsvcscm@sandcastle3265.ftw1 /data/sandcastle/boxes/instance-ide/xplat/js (dbaca0d)]$ hg backout bade4285eafb
connected to hg030.frc2.facebook.com
fetching tree '' 1b4a17164fdbfcad40139e46da4a9bfa8aa8def3, based on 361548a090e81d18bab6f4fc16036c518cb4d7c1, found via 5cfb25344385
7 trees fetched over 0.06s
merging react-native-github/Libraries/Components/TextInput/TextInput.js
20 files updated, 1 files merged, 0 files removed, 0 files unresolved
commit 4270330:2951740e5b32 backs out commit 4266781:bade4285eafb
33 files fetched over 14 fetches - (33 misses, 0.00% hit ratio) over 4.50s
[twsvcscm@sandcastle3265.ftw1 /data/sandcastle/boxes/instance-ide/xplat/js (2951740)]$ hg backout 5cfb25344385
connected to hg035.frc2.facebook.com
merging react-native-github/Libraries/Components/TextInput/TextInput.js
0 files updated, 1 files merged, 2 files removed, 0 files unresolved
commit 4270331:fffb4629a397 backs out commit 4266780:5cfb25344385
1 files fetched over 1 fetches - (1 misses, 0.00% hit ratio) over 4.03s
```
Reviewed By: yungsters
Differential Revision: D12989604
fbshipit-source-id: 703a7c9c1f5bdd710077e515bdff06fdb34502ec
2018-11-08 17:57:08 -08:00
|
|
|
const DeprecatedViewPropTypes = require('DeprecatedViewPropTypes');
|
2018-11-15 20:42:47 -08:00
|
|
|
const DeprecatedColorPropType = require('DeprecatedColorPropType');
|
|
|
|
const DeprecatedStyleSheetPropType = require('DeprecatedStyleSheetPropType');
|
2018-11-07 18:42:19 -08:00
|
|
|
const DocumentSelectionState = require('DocumentSelectionState');
|
2018-11-15 20:42:47 -08:00
|
|
|
const TextStylePropTypes = require('TextStylePropTypes');
|
2016-06-24 06:28:38 -07:00
|
|
|
const Platform = require('Platform');
|
2018-11-07 18:42:19 -08:00
|
|
|
const PropTypes = require('prop-types');
|
2018-08-22 18:22:00 -07:00
|
|
|
const React = require('React');
|
2016-10-14 18:50:14 -07:00
|
|
|
const ReactNative = require('ReactNative');
|
2016-06-24 06:28:38 -07:00
|
|
|
const StyleSheet = require('StyleSheet');
|
|
|
|
const Text = require('Text');
|
2018-05-09 00:47:46 -07:00
|
|
|
const TextAncestor = require('TextAncestor');
|
2016-06-24 06:28:38 -07:00
|
|
|
const TextInputState = require('TextInputState');
|
|
|
|
const TouchableWithoutFeedback = require('TouchableWithoutFeedback');
|
|
|
|
const UIManager = require('UIManager');
|
2015-02-19 20:10:52 -08:00
|
|
|
|
2018-11-15 20:42:47 -08:00
|
|
|
const {
|
|
|
|
AndroidTextInput,
|
|
|
|
RCTMultilineTextInputView,
|
|
|
|
RCTSinglelineTextInputView,
|
|
|
|
} = require('TextInputNativeComponent');
|
|
|
|
|
2016-06-24 06:28:38 -07:00
|
|
|
const emptyFunction = require('fbjs/lib/emptyFunction');
|
|
|
|
const invariant = require('fbjs/lib/invariant');
|
2017-02-14 18:24:52 -08:00
|
|
|
const warning = require('fbjs/lib/warning');
|
2018-11-15 20:42:47 -08:00
|
|
|
const nullthrows = require('nullthrows');
|
|
|
|
|
|
|
|
import type {Props, Selection, Event} from 'TextInputTypes';
|
|
|
|
import type {EventEmitter} from 'EventEmitter';
|
|
|
|
import type {TextInputType} from 'TextInputNativeComponent';
|
|
|
|
import type {PressEvent} from 'CoreEventTypes';
|
|
|
|
import type {
|
|
|
|
MeasureOnSuccessCallback,
|
|
|
|
MeasureLayoutOnSuccessCallback,
|
|
|
|
MeasureInWindowOnSuccessCallback,
|
|
|
|
} from 'ReactNativeTypes';
|
2015-06-09 16:02:16 -07:00
|
|
|
|
2018-06-01 12:37:22 -07:00
|
|
|
const onlyMultiline = {
|
|
|
|
onTextInput: true,
|
|
|
|
children: true,
|
|
|
|
};
|
|
|
|
|
2015-03-09 09:28:51 -07:00
|
|
|
/**
|
|
|
|
* A foundational component for inputting text into the app via a
|
2015-06-16 10:05:27 -07:00
|
|
|
* keyboard. Props provide configurability for several features, such as
|
|
|
|
* auto-correction, auto-capitalization, placeholder text, and different keyboard
|
2015-03-09 09:28:51 -07:00
|
|
|
* types, such as a numeric keypad.
|
|
|
|
*
|
|
|
|
* The simplest use case is to plop down a `TextInput` and subscribe to the
|
2015-07-27 06:20:37 -07:00
|
|
|
* `onChangeText` events to read the user input. There are also other events,
|
|
|
|
* such as `onSubmitEditing` and `onFocus` that can be subscribed to. A simple
|
2015-03-09 09:28:51 -07:00
|
|
|
* example:
|
|
|
|
*
|
2016-06-24 11:53:30 -07:00
|
|
|
* ```ReactNativeWebPlayer
|
|
|
|
* import React, { Component } from 'react';
|
|
|
|
* import { AppRegistry, TextInput } from 'react-native';
|
|
|
|
*
|
2017-05-16 23:43:46 -07:00
|
|
|
* export default class UselessTextInput extends Component {
|
2016-06-24 11:53:30 -07:00
|
|
|
* constructor(props) {
|
|
|
|
* super(props);
|
|
|
|
* this.state = { text: 'Useless Placeholder' };
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* render() {
|
|
|
|
* return (
|
|
|
|
* <TextInput
|
|
|
|
* style={{height: 40, borderColor: 'gray', borderWidth: 1}}
|
|
|
|
* onChangeText={(text) => this.setState({text})}
|
|
|
|
* value={this.state.text}
|
|
|
|
* />
|
|
|
|
* );
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
2017-05-16 23:43:46 -07:00
|
|
|
* // skip this line if using Create React Native App
|
2016-06-24 11:53:30 -07:00
|
|
|
* AppRegistry.registerComponent('AwesomeProject', () => UselessTextInput);
|
2015-03-09 09:28:51 -07:00
|
|
|
* ```
|
|
|
|
*
|
2017-08-17 00:08:37 -07:00
|
|
|
* Two methods exposed via the native element are .focus() and .blur() that
|
|
|
|
* will focus or blur the TextInput programmatically.
|
|
|
|
*
|
2016-03-10 13:43:53 -08:00
|
|
|
* Note that some props are only available with `multiline={true/false}`.
|
|
|
|
* Additionally, border styles that apply to only one side of the element
|
|
|
|
* (e.g., `borderBottomColor`, `borderLeftWidth`, etc.) will not be applied if
|
|
|
|
* `multiline=false`. To achieve the same effect, you can wrap your `TextInput`
|
|
|
|
* in a `View`:
|
|
|
|
*
|
2016-06-24 11:53:30 -07:00
|
|
|
* ```ReactNativeWebPlayer
|
|
|
|
* import React, { Component } from 'react';
|
|
|
|
* import { AppRegistry, View, TextInput } from 'react-native';
|
|
|
|
*
|
|
|
|
* class UselessTextInput extends Component {
|
|
|
|
* render() {
|
|
|
|
* return (
|
|
|
|
* <TextInput
|
|
|
|
* {...this.props} // Inherit any props passed to it; e.g., multiline, numberOfLines below
|
|
|
|
* editable = {true}
|
|
|
|
* maxLength = {40}
|
|
|
|
* />
|
|
|
|
* );
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
2017-05-16 23:43:46 -07:00
|
|
|
* export default class UselessTextInputMultiline extends Component {
|
2016-06-24 11:53:30 -07:00
|
|
|
* constructor(props) {
|
|
|
|
* super(props);
|
|
|
|
* this.state = {
|
|
|
|
* text: 'Useless Multiline Placeholder',
|
|
|
|
* };
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* // If you type something in the text box that is a color, the background will change to that
|
|
|
|
* // color.
|
|
|
|
* render() {
|
|
|
|
* return (
|
|
|
|
* <View style={{
|
|
|
|
* backgroundColor: this.state.text,
|
|
|
|
* borderBottomColor: '#000000',
|
|
|
|
* borderBottomWidth: 1 }}
|
|
|
|
* >
|
|
|
|
* <UselessTextInput
|
|
|
|
* multiline = {true}
|
|
|
|
* numberOfLines = {4}
|
|
|
|
* onChangeText={(text) => this.setState({text})}
|
|
|
|
* value={this.state.text}
|
|
|
|
* />
|
|
|
|
* </View>
|
|
|
|
* );
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
2017-05-16 23:43:46 -07:00
|
|
|
* // skip these lines if using Create React Native App
|
2016-06-24 11:53:30 -07:00
|
|
|
* AppRegistry.registerComponent(
|
|
|
|
* 'AwesomeProject',
|
|
|
|
* () => UselessTextInputMultiline
|
|
|
|
* );
|
2016-03-10 13:43:53 -08:00
|
|
|
* ```
|
2016-06-23 14:12:01 -07:00
|
|
|
*
|
|
|
|
* `TextInput` has by default a border at the bottom of its view. This border
|
|
|
|
* has its padding set by the background image provided by the system, and it
|
|
|
|
* cannot be changed. Solutions to avoid this is to either not set height
|
|
|
|
* explicitly, case in which the system will take care of displaying the border
|
|
|
|
* in the correct position, or to not display the border by setting
|
|
|
|
* `underlineColorAndroid` to transparent.
|
|
|
|
*
|
2016-11-02 13:46:39 -07:00
|
|
|
* Note that on Android performing text selection in input can change
|
|
|
|
* app's activity `windowSoftInputMode` param to `adjustResize`.
|
|
|
|
* This may cause issues with components that have position: 'absolute'
|
|
|
|
* while keyboard is active. To avoid this behavior either specify `windowSoftInputMode`
|
|
|
|
* in AndroidManifest.xml ( https://developer.android.com/guide/topics/manifest/activity-element.html )
|
|
|
|
* or control this param programmatically with native code.
|
|
|
|
*
|
2015-03-09 09:28:51 -07:00
|
|
|
*/
|
2018-11-15 20:42:47 -08:00
|
|
|
class TextInput extends React.Component<Props> {
|
|
|
|
static defaultProps = {
|
|
|
|
allowFontScaling: true,
|
|
|
|
underlineColorAndroid: 'transparent',
|
|
|
|
};
|
|
|
|
|
|
|
|
_inputRef: ?React.ElementRef<Class<TextInputType>> = null;
|
|
|
|
_lastNativeText: ?Stringish = null;
|
|
|
|
_lastNativeSelection: ?Selection = null;
|
|
|
|
_rafId: ?AnimationFrameID = null;
|
|
|
|
|
|
|
|
context: {
|
|
|
|
focusEmitter?: ?EventEmitter,
|
|
|
|
onFocusRequested?: ?(component: React.Component<any>) => mixed,
|
|
|
|
};
|
|
|
|
_focusSubscription: ?Function = null;
|
|
|
|
|
|
|
|
_setNativeRef = ref => {
|
|
|
|
this._inputRef = ref;
|
|
|
|
};
|
Back out TextInput es6 conversion
Summary:
This was failing due to issues with refs, which we were able to fix and then finally due to some jest tests that were failing due to things being null that shouldn't be which I couldn't easily figure out. Reverting the stack until we can actually solve it, hopefully with additional tests.
This was created by running:
```
$ hg backout c2fe2c46e538
fetching tree '' b9bbfc1925c6daf85ba3227d12f177aca9c0c054, based on 4257c76aefa84aaa17279e65aa7ca1174f4401e7, found via 02368b670953
connected to hg015.frc2.facebook.com
60 trees fetched over 2.91s
fetching tree '' c3c304df13399f0f1a29a668242da454fc1d8a97, based on b9bbfc1925c6daf85ba3227d12f177aca9c0c054, found via c2fe2c46e538
7 trees fetched over 0.03s
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
commit 4270328:50a65c5c2e27 backs out commit 4266783:c2fe2c46e538
1 files fetched over 1 fetches - (1 misses, 0.00% hit ratio) over 0.57s
[twsvcscm@sandcastle3265.ftw1 /data/sandcastle/boxes/instance-ide/xplat/js (50a65c5)]$ hg backout 02368b670953
fetching tree '' a46c8ca065f5b92cf375d7ed899fc5ca268ba4da, based on b9bbfc1925c6daf85ba3227d12f177aca9c0c054, found via bade4285eafb
connected to hg024.frc2.facebook.com
27 trees fetched over 3.21s
fetching tree '' 361548a090e81d18bab6f4fc16036c518cb4d7c1, based on a46c8ca065f5b92cf375d7ed899fc5ca268ba4da, found via bade4285eafb
41 trees fetched over 0.10s
merging react-native-github/Libraries/Components/TextInput/TextInput.js
8 files updated, 1 files merged, 0 files removed, 0 files unresolved
commit 4270329:dbaca0daf0ac backs out commit 4266782:02368b670953
14 files fetched over 7 fetches - (14 misses, 0.00% hit ratio) over 1.72s
[twsvcscm@sandcastle3265.ftw1 /data/sandcastle/boxes/instance-ide/xplat/js (dbaca0d)]$ hg backout bade4285eafb
connected to hg030.frc2.facebook.com
fetching tree '' 1b4a17164fdbfcad40139e46da4a9bfa8aa8def3, based on 361548a090e81d18bab6f4fc16036c518cb4d7c1, found via 5cfb25344385
7 trees fetched over 0.06s
merging react-native-github/Libraries/Components/TextInput/TextInput.js
20 files updated, 1 files merged, 0 files removed, 0 files unresolved
commit 4270330:2951740e5b32 backs out commit 4266781:bade4285eafb
33 files fetched over 14 fetches - (33 misses, 0.00% hit ratio) over 4.50s
[twsvcscm@sandcastle3265.ftw1 /data/sandcastle/boxes/instance-ide/xplat/js (2951740)]$ hg backout 5cfb25344385
connected to hg035.frc2.facebook.com
merging react-native-github/Libraries/Components/TextInput/TextInput.js
0 files updated, 1 files merged, 2 files removed, 0 files unresolved
commit 4270331:fffb4629a397 backs out commit 4266780:5cfb25344385
1 files fetched over 1 fetches - (1 misses, 0.00% hit ratio) over 4.03s
```
Reviewed By: yungsters
Differential Revision: D12989604
fbshipit-source-id: 703a7c9c1f5bdd710077e515bdff06fdb34502ec
2018-11-08 17:57:08 -08:00
|
|
|
|
2018-11-15 20:42:47 -08:00
|
|
|
focus(): void {
|
|
|
|
nullthrows(this._inputRef).focus();
|
|
|
|
}
|
Back out TextInput es6 conversion
Summary:
This was failing due to issues with refs, which we were able to fix and then finally due to some jest tests that were failing due to things being null that shouldn't be which I couldn't easily figure out. Reverting the stack until we can actually solve it, hopefully with additional tests.
This was created by running:
```
$ hg backout c2fe2c46e538
fetching tree '' b9bbfc1925c6daf85ba3227d12f177aca9c0c054, based on 4257c76aefa84aaa17279e65aa7ca1174f4401e7, found via 02368b670953
connected to hg015.frc2.facebook.com
60 trees fetched over 2.91s
fetching tree '' c3c304df13399f0f1a29a668242da454fc1d8a97, based on b9bbfc1925c6daf85ba3227d12f177aca9c0c054, found via c2fe2c46e538
7 trees fetched over 0.03s
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
commit 4270328:50a65c5c2e27 backs out commit 4266783:c2fe2c46e538
1 files fetched over 1 fetches - (1 misses, 0.00% hit ratio) over 0.57s
[twsvcscm@sandcastle3265.ftw1 /data/sandcastle/boxes/instance-ide/xplat/js (50a65c5)]$ hg backout 02368b670953
fetching tree '' a46c8ca065f5b92cf375d7ed899fc5ca268ba4da, based on b9bbfc1925c6daf85ba3227d12f177aca9c0c054, found via bade4285eafb
connected to hg024.frc2.facebook.com
27 trees fetched over 3.21s
fetching tree '' 361548a090e81d18bab6f4fc16036c518cb4d7c1, based on a46c8ca065f5b92cf375d7ed899fc5ca268ba4da, found via bade4285eafb
41 trees fetched over 0.10s
merging react-native-github/Libraries/Components/TextInput/TextInput.js
8 files updated, 1 files merged, 0 files removed, 0 files unresolved
commit 4270329:dbaca0daf0ac backs out commit 4266782:02368b670953
14 files fetched over 7 fetches - (14 misses, 0.00% hit ratio) over 1.72s
[twsvcscm@sandcastle3265.ftw1 /data/sandcastle/boxes/instance-ide/xplat/js (dbaca0d)]$ hg backout bade4285eafb
connected to hg030.frc2.facebook.com
fetching tree '' 1b4a17164fdbfcad40139e46da4a9bfa8aa8def3, based on 361548a090e81d18bab6f4fc16036c518cb4d7c1, found via 5cfb25344385
7 trees fetched over 0.06s
merging react-native-github/Libraries/Components/TextInput/TextInput.js
20 files updated, 1 files merged, 0 files removed, 0 files unresolved
commit 4270330:2951740e5b32 backs out commit 4266781:bade4285eafb
33 files fetched over 14 fetches - (33 misses, 0.00% hit ratio) over 4.50s
[twsvcscm@sandcastle3265.ftw1 /data/sandcastle/boxes/instance-ide/xplat/js (2951740)]$ hg backout 5cfb25344385
connected to hg035.frc2.facebook.com
merging react-native-github/Libraries/Components/TextInput/TextInput.js
0 files updated, 1 files merged, 2 files removed, 0 files unresolved
commit 4270331:fffb4629a397 backs out commit 4266780:5cfb25344385
1 files fetched over 1 fetches - (1 misses, 0.00% hit ratio) over 4.03s
```
Reviewed By: yungsters
Differential Revision: D12989604
fbshipit-source-id: 703a7c9c1f5bdd710077e515bdff06fdb34502ec
2018-11-08 17:57:08 -08:00
|
|
|
|
2018-11-15 20:42:47 -08:00
|
|
|
setNativeProps(props: Object): void {
|
|
|
|
nullthrows(this._inputRef).setNativeProps(props);
|
|
|
|
}
|
Back out TextInput es6 conversion
Summary:
This was failing due to issues with refs, which we were able to fix and then finally due to some jest tests that were failing due to things being null that shouldn't be which I couldn't easily figure out. Reverting the stack until we can actually solve it, hopefully with additional tests.
This was created by running:
```
$ hg backout c2fe2c46e538
fetching tree '' b9bbfc1925c6daf85ba3227d12f177aca9c0c054, based on 4257c76aefa84aaa17279e65aa7ca1174f4401e7, found via 02368b670953
connected to hg015.frc2.facebook.com
60 trees fetched over 2.91s
fetching tree '' c3c304df13399f0f1a29a668242da454fc1d8a97, based on b9bbfc1925c6daf85ba3227d12f177aca9c0c054, found via c2fe2c46e538
7 trees fetched over 0.03s
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
commit 4270328:50a65c5c2e27 backs out commit 4266783:c2fe2c46e538
1 files fetched over 1 fetches - (1 misses, 0.00% hit ratio) over 0.57s
[twsvcscm@sandcastle3265.ftw1 /data/sandcastle/boxes/instance-ide/xplat/js (50a65c5)]$ hg backout 02368b670953
fetching tree '' a46c8ca065f5b92cf375d7ed899fc5ca268ba4da, based on b9bbfc1925c6daf85ba3227d12f177aca9c0c054, found via bade4285eafb
connected to hg024.frc2.facebook.com
27 trees fetched over 3.21s
fetching tree '' 361548a090e81d18bab6f4fc16036c518cb4d7c1, based on a46c8ca065f5b92cf375d7ed899fc5ca268ba4da, found via bade4285eafb
41 trees fetched over 0.10s
merging react-native-github/Libraries/Components/TextInput/TextInput.js
8 files updated, 1 files merged, 0 files removed, 0 files unresolved
commit 4270329:dbaca0daf0ac backs out commit 4266782:02368b670953
14 files fetched over 7 fetches - (14 misses, 0.00% hit ratio) over 1.72s
[twsvcscm@sandcastle3265.ftw1 /data/sandcastle/boxes/instance-ide/xplat/js (dbaca0d)]$ hg backout bade4285eafb
connected to hg030.frc2.facebook.com
fetching tree '' 1b4a17164fdbfcad40139e46da4a9bfa8aa8def3, based on 361548a090e81d18bab6f4fc16036c518cb4d7c1, found via 5cfb25344385
7 trees fetched over 0.06s
merging react-native-github/Libraries/Components/TextInput/TextInput.js
20 files updated, 1 files merged, 0 files removed, 0 files unresolved
commit 4270330:2951740e5b32 backs out commit 4266781:bade4285eafb
33 files fetched over 14 fetches - (33 misses, 0.00% hit ratio) over 4.50s
[twsvcscm@sandcastle3265.ftw1 /data/sandcastle/boxes/instance-ide/xplat/js (2951740)]$ hg backout 5cfb25344385
connected to hg035.frc2.facebook.com
merging react-native-github/Libraries/Components/TextInput/TextInput.js
0 files updated, 1 files merged, 2 files removed, 0 files unresolved
commit 4270331:fffb4629a397 backs out commit 4266780:5cfb25344385
1 files fetched over 1 fetches - (1 misses, 0.00% hit ratio) over 4.03s
```
Reviewed By: yungsters
Differential Revision: D12989604
fbshipit-source-id: 703a7c9c1f5bdd710077e515bdff06fdb34502ec
2018-11-08 17:57:08 -08:00
|
|
|
|
2018-11-15 20:42:47 -08:00
|
|
|
blur(): void {
|
|
|
|
nullthrows(this._inputRef).blur();
|
|
|
|
}
|
2015-02-19 20:10:52 -08:00
|
|
|
|
2016-04-09 11:12:46 -07:00
|
|
|
/**
|
2016-06-24 11:53:30 -07:00
|
|
|
* Returns `true` if the input is currently focused; `false` otherwise.
|
2016-04-09 11:12:46 -07:00
|
|
|
*/
|
2018-11-15 20:42:47 -08:00
|
|
|
isFocused(): boolean {
|
2018-01-14 19:32:22 -08:00
|
|
|
return (
|
|
|
|
TextInputState.currentlyFocusedField() ===
|
|
|
|
ReactNative.findNodeHandle(this._inputRef)
|
|
|
|
);
|
2018-11-15 20:42:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
measure(callback: MeasureOnSuccessCallback): void {
|
|
|
|
nullthrows(this._inputRef).measure(callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
measureLayout(
|
|
|
|
relativeToNativeNode: number,
|
|
|
|
onSuccess: MeasureLayoutOnSuccessCallback,
|
|
|
|
onFail: () => void,
|
|
|
|
): void {
|
|
|
|
nullthrows(this._inputRef).measureLayout(
|
|
|
|
relativeToNativeNode,
|
|
|
|
onSuccess,
|
|
|
|
onFail,
|
|
|
|
);
|
|
|
|
}
|
2015-03-25 12:55:10 -07:00
|
|
|
|
2018-11-15 20:42:47 -08:00
|
|
|
measureInWindow(callback: MeasureInWindowOnSuccessCallback): void {
|
|
|
|
nullthrows(this._inputRef).measureInWindow(callback);
|
|
|
|
}
|
Back out TextInput es6 conversion
Summary:
This was failing due to issues with refs, which we were able to fix and then finally due to some jest tests that were failing due to things being null that shouldn't be which I couldn't easily figure out. Reverting the stack until we can actually solve it, hopefully with additional tests.
This was created by running:
```
$ hg backout c2fe2c46e538
fetching tree '' b9bbfc1925c6daf85ba3227d12f177aca9c0c054, based on 4257c76aefa84aaa17279e65aa7ca1174f4401e7, found via 02368b670953
connected to hg015.frc2.facebook.com
60 trees fetched over 2.91s
fetching tree '' c3c304df13399f0f1a29a668242da454fc1d8a97, based on b9bbfc1925c6daf85ba3227d12f177aca9c0c054, found via c2fe2c46e538
7 trees fetched over 0.03s
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
commit 4270328:50a65c5c2e27 backs out commit 4266783:c2fe2c46e538
1 files fetched over 1 fetches - (1 misses, 0.00% hit ratio) over 0.57s
[twsvcscm@sandcastle3265.ftw1 /data/sandcastle/boxes/instance-ide/xplat/js (50a65c5)]$ hg backout 02368b670953
fetching tree '' a46c8ca065f5b92cf375d7ed899fc5ca268ba4da, based on b9bbfc1925c6daf85ba3227d12f177aca9c0c054, found via bade4285eafb
connected to hg024.frc2.facebook.com
27 trees fetched over 3.21s
fetching tree '' 361548a090e81d18bab6f4fc16036c518cb4d7c1, based on a46c8ca065f5b92cf375d7ed899fc5ca268ba4da, found via bade4285eafb
41 trees fetched over 0.10s
merging react-native-github/Libraries/Components/TextInput/TextInput.js
8 files updated, 1 files merged, 0 files removed, 0 files unresolved
commit 4270329:dbaca0daf0ac backs out commit 4266782:02368b670953
14 files fetched over 7 fetches - (14 misses, 0.00% hit ratio) over 1.72s
[twsvcscm@sandcastle3265.ftw1 /data/sandcastle/boxes/instance-ide/xplat/js (dbaca0d)]$ hg backout bade4285eafb
connected to hg030.frc2.facebook.com
fetching tree '' 1b4a17164fdbfcad40139e46da4a9bfa8aa8def3, based on 361548a090e81d18bab6f4fc16036c518cb4d7c1, found via 5cfb25344385
7 trees fetched over 0.06s
merging react-native-github/Libraries/Components/TextInput/TextInput.js
20 files updated, 1 files merged, 0 files removed, 0 files unresolved
commit 4270330:2951740e5b32 backs out commit 4266781:bade4285eafb
33 files fetched over 14 fetches - (33 misses, 0.00% hit ratio) over 4.50s
[twsvcscm@sandcastle3265.ftw1 /data/sandcastle/boxes/instance-ide/xplat/js (2951740)]$ hg backout 5cfb25344385
connected to hg035.frc2.facebook.com
merging react-native-github/Libraries/Components/TextInput/TextInput.js
0 files updated, 1 files merged, 2 files removed, 0 files unresolved
commit 4270331:fffb4629a397 backs out commit 4266780:5cfb25344385
1 files fetched over 1 fetches - (1 misses, 0.00% hit ratio) over 4.03s
```
Reviewed By: yungsters
Differential Revision: D12989604
fbshipit-source-id: 703a7c9c1f5bdd710077e515bdff06fdb34502ec
2018-11-08 17:57:08 -08:00
|
|
|
|
2018-11-15 20:42:47 -08:00
|
|
|
componentDidMount() {
|
2016-05-26 07:20:50 -07:00
|
|
|
this._lastNativeText = this.props.value;
|
2018-04-16 13:03:50 -07:00
|
|
|
const tag = ReactNative.findNodeHandle(this._inputRef);
|
|
|
|
if (tag != null) {
|
|
|
|
// tag is null only in unit tests
|
|
|
|
TextInputState.registerInput(tag);
|
|
|
|
}
|
2018-11-15 20:42:47 -08:00
|
|
|
const safeCallbackDoFocus = () => {
|
|
|
|
// Checks needed to prevent jest tests from crashing
|
|
|
|
if (this._inputRef && this._inputRef.focus) {
|
|
|
|
this._inputRef.focus();
|
|
|
|
}
|
|
|
|
};
|
2018-04-16 13:03:50 -07:00
|
|
|
if (this.context.focusEmitter) {
|
|
|
|
this._focusSubscription = this.context.focusEmitter.addListener(
|
|
|
|
'focus',
|
|
|
|
el => {
|
|
|
|
if (this === el) {
|
2018-11-15 20:42:47 -08:00
|
|
|
this._rafId = requestAnimationFrame(safeCallbackDoFocus);
|
|
|
|
} else if (
|
|
|
|
this.isFocused() &&
|
|
|
|
this._inputRef &&
|
|
|
|
this._inputRef.blur
|
|
|
|
) {
|
|
|
|
this._inputRef.blur();
|
2018-04-16 13:03:50 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
2018-11-15 20:42:47 -08:00
|
|
|
if (this.props.autoFocus && this.context.onFocusRequested) {
|
2018-04-16 13:03:50 -07:00
|
|
|
this.context.onFocusRequested(this);
|
|
|
|
}
|
|
|
|
} else {
|
2015-02-19 20:10:52 -08:00
|
|
|
if (this.props.autoFocus) {
|
2018-11-15 20:42:47 -08:00
|
|
|
this._rafId = requestAnimationFrame(safeCallbackDoFocus);
|
2015-02-19 20:10:52 -08:00
|
|
|
}
|
|
|
|
}
|
2018-11-15 20:42:47 -08:00
|
|
|
}
|
2015-02-19 20:10:52 -08:00
|
|
|
|
2018-11-15 20:42:47 -08:00
|
|
|
componentWillUnmount() {
|
2015-03-11 14:45:49 -07:00
|
|
|
this._focusSubscription && this._focusSubscription.remove();
|
2018-11-15 20:42:47 -08:00
|
|
|
if (this.isFocused() && this._inputRef && this._inputRef.blur) {
|
|
|
|
this._inputRef.blur();
|
2015-04-24 09:12:04 -07:00
|
|
|
}
|
2018-04-16 13:03:50 -07:00
|
|
|
const tag = ReactNative.findNodeHandle(this._inputRef);
|
|
|
|
if (tag != null) {
|
|
|
|
TextInputState.unregisterInput(tag);
|
|
|
|
}
|
2018-10-08 11:00:23 -07:00
|
|
|
if (this._rafId != null) {
|
|
|
|
cancelAnimationFrame(this._rafId);
|
|
|
|
}
|
2018-11-15 20:42:47 -08:00
|
|
|
}
|
2015-05-29 18:16:57 -02:00
|
|
|
|
2016-04-09 11:12:46 -07:00
|
|
|
/**
|
2016-06-24 11:53:30 -07:00
|
|
|
* Removes all text from the `TextInput`.
|
2016-04-09 11:12:46 -07:00
|
|
|
*/
|
2018-11-15 20:42:47 -08:00
|
|
|
clear() {
|
|
|
|
nullthrows(this._inputRef).setNativeProps({text: ''});
|
|
|
|
}
|
2015-07-24 09:34:18 -07:00
|
|
|
|
2018-11-15 20:42:47 -08:00
|
|
|
render() {
|
2018-05-09 00:47:46 -07:00
|
|
|
let textInput;
|
2015-03-27 11:44:43 -07:00
|
|
|
if (Platform.OS === 'ios') {
|
2018-09-27 15:55:31 -07:00
|
|
|
textInput = UIManager.getViewManagerConfig('RCTVirtualText')
|
2018-01-14 19:32:28 -08:00
|
|
|
? this._renderIOS()
|
|
|
|
: this._renderIOSLegacy();
|
2015-03-27 11:44:43 -07:00
|
|
|
} else if (Platform.OS === 'android') {
|
2018-05-09 00:47:46 -07:00
|
|
|
textInput = this._renderAndroid();
|
2015-03-27 11:44:43 -07:00
|
|
|
}
|
2018-05-09 00:47:46 -07:00
|
|
|
return (
|
|
|
|
<TextAncestor.Provider value={true}>{textInput}</TextAncestor.Provider>
|
|
|
|
);
|
2018-11-15 20:42:47 -08:00
|
|
|
}
|
2015-03-27 11:44:43 -07:00
|
|
|
|
2018-11-15 20:42:47 -08:00
|
|
|
_getText(): ?string {
|
2018-01-14 19:32:22 -08:00
|
|
|
return typeof this.props.value === 'string'
|
|
|
|
? this.props.value
|
|
|
|
: typeof this.props.defaultValue === 'string'
|
|
|
|
? this.props.defaultValue
|
|
|
|
: '';
|
2018-11-15 20:42:47 -08:00
|
|
|
}
|
2016-08-25 17:18:05 -07:00
|
|
|
|
2018-11-15 20:42:47 -08:00
|
|
|
_renderIOSLegacy() {
|
2018-03-03 15:04:46 -08:00
|
|
|
let textContainer;
|
2015-02-19 20:10:52 -08:00
|
|
|
|
2018-03-03 15:04:46 -08:00
|
|
|
const props = Object.assign({}, this.props);
|
2018-11-15 20:42:47 -08:00
|
|
|
const style = [this.props.style];
|
2016-08-25 17:18:05 -07:00
|
|
|
|
|
|
|
if (props.selection && props.selection.end == null) {
|
2018-01-14 19:32:22 -08:00
|
|
|
props.selection = {
|
|
|
|
start: props.selection.start,
|
|
|
|
end: props.selection.start,
|
|
|
|
};
|
2016-08-25 17:18:05 -07:00
|
|
|
}
|
|
|
|
|
2015-06-05 08:46:17 -07:00
|
|
|
if (!props.multiline) {
|
2016-07-01 04:08:22 -07:00
|
|
|
if (__DEV__) {
|
2018-03-03 15:04:46 -08:00
|
|
|
for (const propKey in onlyMultiline) {
|
2016-07-01 04:08:22 -07:00
|
|
|
if (props[propKey]) {
|
2016-07-13 16:33:39 -07:00
|
|
|
const error = new Error(
|
2018-01-14 19:32:22 -08:00
|
|
|
'TextInput prop `' +
|
|
|
|
propKey +
|
|
|
|
'` is only supported with multiline.',
|
2016-07-01 04:08:22 -07:00
|
|
|
);
|
2016-07-13 16:33:39 -07:00
|
|
|
warning(false, '%s', error.stack);
|
2016-07-01 04:08:22 -07:00
|
|
|
}
|
2015-02-19 20:10:52 -08:00
|
|
|
}
|
|
|
|
}
|
2018-01-14 19:32:22 -08:00
|
|
|
textContainer = (
|
2017-12-19 19:48:22 -08:00
|
|
|
<RCTSinglelineTextInputView
|
2016-08-25 17:18:05 -07:00
|
|
|
ref={this._setNativeRef}
|
2015-06-05 08:46:17 -07:00
|
|
|
{...props}
|
2015-02-19 20:10:52 -08:00
|
|
|
onFocus={this._onFocus}
|
|
|
|
onBlur={this._onBlur}
|
|
|
|
onChange={this._onChange}
|
2016-08-25 17:18:05 -07:00
|
|
|
onSelectionChange={this._onSelectionChange}
|
2015-11-14 09:41:59 -08:00
|
|
|
onSelectionChangeShouldSetResponder={emptyFunction.thatReturnsTrue}
|
2015-07-22 14:03:32 -07:00
|
|
|
text={this._getText()}
|
2018-01-14 19:32:22 -08:00
|
|
|
/>
|
|
|
|
);
|
2015-02-19 20:10:52 -08:00
|
|
|
} else {
|
2018-03-03 15:04:46 -08:00
|
|
|
let children = props.children;
|
|
|
|
let childCount = 0;
|
2016-10-14 18:50:19 -07:00
|
|
|
React.Children.forEach(children, () => ++childCount);
|
2015-02-19 20:10:52 -08:00
|
|
|
invariant(
|
2015-06-05 08:46:17 -07:00
|
|
|
!(props.value && childCount),
|
2018-01-14 19:32:22 -08:00
|
|
|
'Cannot specify both value and children.',
|
2015-02-19 20:10:52 -08:00
|
|
|
);
|
2016-04-21 12:09:16 -07:00
|
|
|
if (childCount >= 1) {
|
2018-01-14 19:32:22 -08:00
|
|
|
children = (
|
2018-09-04 17:33:06 -07:00
|
|
|
<Text
|
2018-11-15 20:42:47 -08:00
|
|
|
style={style}
|
2018-09-04 17:33:06 -07:00
|
|
|
allowFontScaling={props.allowFontScaling}
|
2018-09-25 19:37:32 -07:00
|
|
|
maxFontSizeMultiplier={props.maxFontSizeMultiplier}>
|
2018-01-14 19:32:22 -08:00
|
|
|
{children}
|
|
|
|
</Text>
|
|
|
|
);
|
2015-02-19 20:10:52 -08:00
|
|
|
}
|
2015-06-05 08:46:17 -07:00
|
|
|
if (props.inputView) {
|
|
|
|
children = [children, props.inputView];
|
2015-02-19 20:10:52 -08:00
|
|
|
}
|
2018-11-15 20:42:47 -08:00
|
|
|
style.unshift(styles.multilineInput);
|
2018-01-14 19:32:22 -08:00
|
|
|
textContainer = (
|
2017-12-19 19:48:22 -08:00
|
|
|
<RCTMultilineTextInputView
|
2016-08-25 17:18:05 -07:00
|
|
|
ref={this._setNativeRef}
|
2015-06-05 08:46:17 -07:00
|
|
|
{...props}
|
2015-02-19 20:10:52 -08:00
|
|
|
children={children}
|
|
|
|
onFocus={this._onFocus}
|
|
|
|
onBlur={this._onBlur}
|
|
|
|
onChange={this._onChange}
|
2017-08-14 23:46:44 -07:00
|
|
|
onContentSizeChange={this.props.onContentSizeChange}
|
2016-08-25 17:18:05 -07:00
|
|
|
onSelectionChange={this._onSelectionChange}
|
2015-02-19 20:10:52 -08:00
|
|
|
onTextInput={this._onTextInput}
|
|
|
|
onSelectionChangeShouldSetResponder={emptyFunction.thatReturnsTrue}
|
2015-07-22 14:03:32 -07:00
|
|
|
text={this._getText()}
|
2016-07-31 14:20:13 -07:00
|
|
|
dataDetectorTypes={this.props.dataDetectorTypes}
|
2016-11-22 11:52:18 -08:00
|
|
|
onScroll={this._onScroll}
|
2018-01-14 19:32:22 -08:00
|
|
|
/>
|
|
|
|
);
|
2015-02-19 20:10:52 -08:00
|
|
|
}
|
2017-12-18 14:57:38 -08:00
|
|
|
|
2015-02-19 20:10:52 -08:00
|
|
|
return (
|
|
|
|
<TouchableWithoutFeedback
|
2016-06-10 03:14:47 -07:00
|
|
|
onLayout={props.onLayout}
|
2015-02-19 20:10:52 -08:00
|
|
|
onPress={this._onPress}
|
2015-05-29 05:18:42 -07:00
|
|
|
rejectResponderTermination={true}
|
2016-02-04 05:12:36 -08:00
|
|
|
accessible={props.accessible}
|
|
|
|
accessibilityLabel={props.accessibilityLabel}
|
2018-07-25 23:37:16 -07:00
|
|
|
accessibilityRole={props.accessibilityRole}
|
|
|
|
accessibilityStates={props.accessibilityStates}
|
2017-04-07 11:47:35 -07:00
|
|
|
nativeID={this.props.nativeID}
|
2015-06-05 08:46:17 -07:00
|
|
|
testID={props.testID}>
|
2015-02-19 20:10:52 -08:00
|
|
|
{textContainer}
|
|
|
|
</TouchableWithoutFeedback>
|
|
|
|
);
|
2018-11-15 20:42:47 -08:00
|
|
|
}
|
2015-02-19 20:10:52 -08:00
|
|
|
|
2018-11-15 20:42:47 -08:00
|
|
|
_renderIOS() {
|
2018-03-03 15:04:46 -08:00
|
|
|
const props = Object.assign({}, this.props);
|
2018-01-14 19:32:28 -08:00
|
|
|
props.style = [this.props.style];
|
|
|
|
|
|
|
|
if (props.selection && props.selection.end == null) {
|
|
|
|
props.selection = {
|
|
|
|
start: props.selection.start,
|
|
|
|
end: props.selection.start,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const RCTTextInputView = props.multiline
|
|
|
|
? RCTMultilineTextInputView
|
|
|
|
: RCTSinglelineTextInputView;
|
|
|
|
|
|
|
|
if (props.multiline) {
|
|
|
|
props.style.unshift(styles.multilineInput);
|
|
|
|
}
|
|
|
|
|
|
|
|
const textContainer = (
|
|
|
|
<RCTTextInputView
|
|
|
|
ref={this._setNativeRef}
|
|
|
|
{...props}
|
|
|
|
onFocus={this._onFocus}
|
|
|
|
onBlur={this._onBlur}
|
|
|
|
onChange={this._onChange}
|
|
|
|
onContentSizeChange={this.props.onContentSizeChange}
|
|
|
|
onSelectionChange={this._onSelectionChange}
|
|
|
|
onTextInput={this._onTextInput}
|
|
|
|
onSelectionChangeShouldSetResponder={emptyFunction.thatReturnsTrue}
|
|
|
|
text={this._getText()}
|
|
|
|
dataDetectorTypes={this.props.dataDetectorTypes}
|
|
|
|
onScroll={this._onScroll}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<TouchableWithoutFeedback
|
|
|
|
onLayout={props.onLayout}
|
|
|
|
onPress={this._onPress}
|
|
|
|
rejectResponderTermination={true}
|
|
|
|
accessible={props.accessible}
|
|
|
|
accessibilityLabel={props.accessibilityLabel}
|
2018-07-25 23:37:16 -07:00
|
|
|
accessibilityRole={props.accessibilityRole}
|
|
|
|
accessibilityStates={props.accessibilityStates}
|
2018-01-14 19:32:28 -08:00
|
|
|
nativeID={this.props.nativeID}
|
|
|
|
testID={props.testID}>
|
|
|
|
{textContainer}
|
|
|
|
</TouchableWithoutFeedback>
|
|
|
|
);
|
2018-11-15 20:42:47 -08:00
|
|
|
}
|
2018-01-14 19:32:28 -08:00
|
|
|
|
2018-11-15 20:42:47 -08:00
|
|
|
_renderAndroid() {
|
2016-08-19 07:18:03 -07:00
|
|
|
const props = Object.assign({}, this.props);
|
2017-12-18 14:57:38 -08:00
|
|
|
props.style = [this.props.style];
|
2018-09-27 15:55:31 -07:00
|
|
|
props.autoCapitalize = UIManager.getViewManagerConfig(
|
|
|
|
'AndroidTextInput',
|
|
|
|
).Constants.AutoCapitalizationType[props.autoCapitalize || 'sentences'];
|
2018-03-03 15:04:46 -08:00
|
|
|
let children = this.props.children;
|
|
|
|
let childCount = 0;
|
2016-10-14 18:50:19 -07:00
|
|
|
React.Children.forEach(children, () => ++childCount);
|
2015-05-29 18:16:57 -02:00
|
|
|
invariant(
|
|
|
|
!(this.props.value && childCount),
|
2018-01-14 19:32:22 -08:00
|
|
|
'Cannot specify both value and children.',
|
2015-05-29 18:16:57 -02:00
|
|
|
);
|
|
|
|
if (childCount > 1) {
|
|
|
|
children = <Text>{children}</Text>;
|
|
|
|
}
|
2017-12-18 14:57:38 -08:00
|
|
|
|
2016-09-05 07:04:26 -07:00
|
|
|
if (props.selection && props.selection.end == null) {
|
2018-01-14 19:32:22 -08:00
|
|
|
props.selection = {
|
|
|
|
start: props.selection.start,
|
|
|
|
end: props.selection.start,
|
|
|
|
};
|
2016-09-05 07:04:26 -07:00
|
|
|
}
|
2017-12-18 14:57:38 -08:00
|
|
|
|
2018-01-14 19:32:22 -08:00
|
|
|
const textContainer = (
|
2015-03-27 11:44:43 -07:00
|
|
|
<AndroidTextInput
|
2016-08-25 17:18:05 -07:00
|
|
|
ref={this._setNativeRef}
|
2016-08-19 07:18:03 -07:00
|
|
|
{...props}
|
2015-12-14 06:41:45 -08:00
|
|
|
mostRecentEventCount={0}
|
2015-03-27 11:44:43 -07:00
|
|
|
onFocus={this._onFocus}
|
|
|
|
onBlur={this._onBlur}
|
|
|
|
onChange={this._onChange}
|
2016-08-25 17:18:05 -07:00
|
|
|
onSelectionChange={this._onSelectionChange}
|
2015-06-08 03:45:44 -07:00
|
|
|
onTextInput={this._onTextInput}
|
2015-07-22 14:03:32 -07:00
|
|
|
text={this._getText()}
|
2015-05-29 18:16:57 -02:00
|
|
|
children={children}
|
2016-11-23 06:41:53 -08:00
|
|
|
disableFullscreenUI={this.props.disableFullscreenUI}
|
2016-12-16 01:19:16 -08:00
|
|
|
textBreakStrategy={this.props.textBreakStrategy}
|
2017-02-06 07:22:09 -08:00
|
|
|
onScroll={this._onScroll}
|
2018-01-14 19:32:22 -08:00
|
|
|
/>
|
|
|
|
);
|
2015-04-08 06:54:32 -07:00
|
|
|
|
|
|
|
return (
|
|
|
|
<TouchableWithoutFeedback
|
2018-02-24 00:59:22 -08:00
|
|
|
onLayout={props.onLayout}
|
2015-04-08 06:54:32 -07:00
|
|
|
onPress={this._onPress}
|
2016-02-04 05:12:36 -08:00
|
|
|
accessible={this.props.accessible}
|
|
|
|
accessibilityLabel={this.props.accessibilityLabel}
|
2018-07-25 23:37:16 -07:00
|
|
|
accessibilityRole={this.props.accessibilityRole}
|
|
|
|
accessibilityStates={this.props.accessibilityStates}
|
2017-04-07 11:47:35 -07:00
|
|
|
nativeID={this.props.nativeID}
|
2015-04-08 06:54:32 -07:00
|
|
|
testID={this.props.testID}>
|
|
|
|
{textContainer}
|
|
|
|
</TouchableWithoutFeedback>
|
2015-03-27 11:44:43 -07:00
|
|
|
);
|
2018-11-15 20:42:47 -08:00
|
|
|
}
|
2015-03-27 11:44:43 -07:00
|
|
|
|
2018-11-15 20:42:47 -08:00
|
|
|
_onFocus = (event: Event) => {
|
2015-02-19 20:10:52 -08:00
|
|
|
if (this.props.onFocus) {
|
|
|
|
this.props.onFocus(event);
|
|
|
|
}
|
2016-02-02 04:40:40 -08:00
|
|
|
|
|
|
|
if (this.props.selectionState) {
|
|
|
|
this.props.selectionState.focus();
|
|
|
|
}
|
2018-11-15 20:42:47 -08:00
|
|
|
};
|
2015-02-19 20:10:52 -08:00
|
|
|
|
2018-11-15 20:42:47 -08:00
|
|
|
_onPress = (event: PressEvent) => {
|
2015-07-15 08:23:48 -07:00
|
|
|
if (this.props.editable || this.props.editable === undefined) {
|
2018-11-15 20:42:47 -08:00
|
|
|
nullthrows(this._inputRef).focus();
|
2015-07-15 08:23:48 -07:00
|
|
|
}
|
2018-11-15 20:42:47 -08:00
|
|
|
};
|
2015-02-19 20:10:52 -08:00
|
|
|
|
2018-11-15 20:42:47 -08:00
|
|
|
_onChange = (event: Event) => {
|
2015-12-14 06:41:45 -08:00
|
|
|
// Make sure to fire the mostRecentEventCount first so it is already set on
|
|
|
|
// native when the text value is set.
|
2018-11-15 20:42:47 -08:00
|
|
|
if (this._inputRef && this._inputRef.setNativeProps) {
|
2017-01-20 16:41:22 -08:00
|
|
|
this._inputRef.setNativeProps({
|
|
|
|
mostRecentEventCount: event.nativeEvent.eventCount,
|
|
|
|
});
|
|
|
|
}
|
2015-12-14 06:41:45 -08:00
|
|
|
|
2018-03-03 15:04:46 -08:00
|
|
|
const text = event.nativeEvent.text;
|
2015-02-19 20:10:52 -08:00
|
|
|
this.props.onChange && this.props.onChange(event);
|
2015-07-21 12:37:24 -07:00
|
|
|
this.props.onChangeText && this.props.onChangeText(text);
|
2015-12-14 06:41:45 -08:00
|
|
|
|
2016-08-25 17:18:05 -07:00
|
|
|
if (!this._inputRef) {
|
2015-12-15 17:31:07 -08:00
|
|
|
// calling `this.props.onChange` or `this.props.onChangeText`
|
|
|
|
// may clean up the input itself. Exits here.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-26 07:20:50 -07:00
|
|
|
this._lastNativeText = text;
|
|
|
|
this.forceUpdate();
|
2018-11-15 20:42:47 -08:00
|
|
|
};
|
2016-05-26 07:20:50 -07:00
|
|
|
|
2018-11-15 20:42:47 -08:00
|
|
|
_onSelectionChange = (event: Event) => {
|
2016-08-25 17:18:05 -07:00
|
|
|
this.props.onSelectionChange && this.props.onSelectionChange(event);
|
|
|
|
|
|
|
|
if (!this._inputRef) {
|
|
|
|
// calling `this.props.onSelectionChange`
|
|
|
|
// may clean up the input itself. Exits here.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._lastNativeSelection = event.nativeEvent.selection;
|
|
|
|
|
|
|
|
if (this.props.selection || this.props.selectionState) {
|
|
|
|
this.forceUpdate();
|
|
|
|
}
|
2018-11-15 20:42:47 -08:00
|
|
|
};
|
2016-08-25 17:18:05 -07:00
|
|
|
|
2018-11-15 20:42:47 -08:00
|
|
|
componentDidUpdate() {
|
2015-12-14 06:41:45 -08:00
|
|
|
// This is necessary in case native updates the text and JS decides
|
|
|
|
// that the update should be ignored and we should stick with the value
|
|
|
|
// that we have in JS.
|
2016-08-25 17:18:05 -07:00
|
|
|
const nativeProps = {};
|
|
|
|
|
2018-01-14 19:32:22 -08:00
|
|
|
if (
|
|
|
|
this._lastNativeText !== this.props.value &&
|
|
|
|
typeof this.props.value === 'string'
|
|
|
|
) {
|
2016-08-25 17:18:05 -07:00
|
|
|
nativeProps.text = this.props.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Selection is also a controlled prop, if the native value doesn't match
|
|
|
|
// JS, update to the JS value.
|
|
|
|
const {selection} = this.props;
|
2018-01-14 19:32:22 -08:00
|
|
|
if (
|
|
|
|
this._lastNativeSelection &&
|
|
|
|
selection &&
|
|
|
|
(this._lastNativeSelection.start !== selection.start ||
|
|
|
|
this._lastNativeSelection.end !== selection.end)
|
|
|
|
) {
|
2016-08-25 17:18:05 -07:00
|
|
|
nativeProps.selection = this.props.selection;
|
|
|
|
}
|
|
|
|
|
2018-11-15 20:42:47 -08:00
|
|
|
if (
|
|
|
|
Object.keys(nativeProps).length > 0 &&
|
|
|
|
this._inputRef &&
|
|
|
|
this._inputRef.setNativeProps
|
|
|
|
) {
|
2016-08-25 17:18:05 -07:00
|
|
|
this._inputRef.setNativeProps(nativeProps);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.props.selectionState && selection) {
|
|
|
|
this.props.selectionState.update(selection.start, selection.end);
|
2015-12-14 06:41:45 -08:00
|
|
|
}
|
2018-11-15 20:42:47 -08:00
|
|
|
}
|
2015-02-19 20:10:52 -08:00
|
|
|
|
2018-11-15 20:42:47 -08:00
|
|
|
_onBlur = (event: Event) => {
|
|
|
|
nullthrows(this._inputRef).blur();
|
2015-02-19 20:10:52 -08:00
|
|
|
if (this.props.onBlur) {
|
|
|
|
this.props.onBlur(event);
|
|
|
|
}
|
2016-02-02 04:40:40 -08:00
|
|
|
|
|
|
|
if (this.props.selectionState) {
|
|
|
|
this.props.selectionState.blur();
|
|
|
|
}
|
2018-11-15 20:42:47 -08:00
|
|
|
};
|
2015-02-19 20:10:52 -08:00
|
|
|
|
2018-11-15 20:42:47 -08:00
|
|
|
_onTextInput = (event: Event) => {
|
2015-02-19 20:10:52 -08:00
|
|
|
this.props.onTextInput && this.props.onTextInput(event);
|
2018-11-15 20:42:47 -08:00
|
|
|
};
|
2016-11-22 11:52:18 -08:00
|
|
|
|
2018-11-15 20:42:47 -08:00
|
|
|
_onScroll = (event: Event) => {
|
2016-11-22 11:52:18 -08:00
|
|
|
this.props.onScroll && this.props.onScroll(event);
|
2018-11-15 20:42:47 -08:00
|
|
|
};
|
Back out TextInput es6 conversion
Summary:
This was failing due to issues with refs, which we were able to fix and then finally due to some jest tests that were failing due to things being null that shouldn't be which I couldn't easily figure out. Reverting the stack until we can actually solve it, hopefully with additional tests.
This was created by running:
```
$ hg backout c2fe2c46e538
fetching tree '' b9bbfc1925c6daf85ba3227d12f177aca9c0c054, based on 4257c76aefa84aaa17279e65aa7ca1174f4401e7, found via 02368b670953
connected to hg015.frc2.facebook.com
60 trees fetched over 2.91s
fetching tree '' c3c304df13399f0f1a29a668242da454fc1d8a97, based on b9bbfc1925c6daf85ba3227d12f177aca9c0c054, found via c2fe2c46e538
7 trees fetched over 0.03s
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
commit 4270328:50a65c5c2e27 backs out commit 4266783:c2fe2c46e538
1 files fetched over 1 fetches - (1 misses, 0.00% hit ratio) over 0.57s
[twsvcscm@sandcastle3265.ftw1 /data/sandcastle/boxes/instance-ide/xplat/js (50a65c5)]$ hg backout 02368b670953
fetching tree '' a46c8ca065f5b92cf375d7ed899fc5ca268ba4da, based on b9bbfc1925c6daf85ba3227d12f177aca9c0c054, found via bade4285eafb
connected to hg024.frc2.facebook.com
27 trees fetched over 3.21s
fetching tree '' 361548a090e81d18bab6f4fc16036c518cb4d7c1, based on a46c8ca065f5b92cf375d7ed899fc5ca268ba4da, found via bade4285eafb
41 trees fetched over 0.10s
merging react-native-github/Libraries/Components/TextInput/TextInput.js
8 files updated, 1 files merged, 0 files removed, 0 files unresolved
commit 4270329:dbaca0daf0ac backs out commit 4266782:02368b670953
14 files fetched over 7 fetches - (14 misses, 0.00% hit ratio) over 1.72s
[twsvcscm@sandcastle3265.ftw1 /data/sandcastle/boxes/instance-ide/xplat/js (dbaca0d)]$ hg backout bade4285eafb
connected to hg030.frc2.facebook.com
fetching tree '' 1b4a17164fdbfcad40139e46da4a9bfa8aa8def3, based on 361548a090e81d18bab6f4fc16036c518cb4d7c1, found via 5cfb25344385
7 trees fetched over 0.06s
merging react-native-github/Libraries/Components/TextInput/TextInput.js
20 files updated, 1 files merged, 0 files removed, 0 files unresolved
commit 4270330:2951740e5b32 backs out commit 4266781:bade4285eafb
33 files fetched over 14 fetches - (33 misses, 0.00% hit ratio) over 4.50s
[twsvcscm@sandcastle3265.ftw1 /data/sandcastle/boxes/instance-ide/xplat/js (2951740)]$ hg backout 5cfb25344385
connected to hg035.frc2.facebook.com
merging react-native-github/Libraries/Components/TextInput/TextInput.js
0 files updated, 1 files merged, 2 files removed, 0 files unresolved
commit 4270331:fffb4629a397 backs out commit 4266780:5cfb25344385
1 files fetched over 1 fetches - (1 misses, 0.00% hit ratio) over 4.03s
```
Reviewed By: yungsters
Differential Revision: D12989604
fbshipit-source-id: 703a7c9c1f5bdd710077e515bdff06fdb34502ec
2018-11-08 17:57:08 -08:00
|
|
|
}
|
2018-11-07 18:42:19 -08:00
|
|
|
|
2018-11-15 20:42:47 -08:00
|
|
|
const DataDetectorTypes = [
|
|
|
|
'phoneNumber',
|
|
|
|
'link',
|
|
|
|
'address',
|
|
|
|
'calendarEvent',
|
|
|
|
'none',
|
|
|
|
'all',
|
|
|
|
];
|
|
|
|
|
|
|
|
TextInput.propTypes = {
|
|
|
|
...DeprecatedViewPropTypes,
|
|
|
|
autoCapitalize: PropTypes.oneOf(['none', 'sentences', 'words', 'characters']),
|
|
|
|
autoCorrect: PropTypes.bool,
|
|
|
|
spellCheck: PropTypes.bool,
|
|
|
|
autoFocus: PropTypes.bool,
|
|
|
|
allowFontScaling: PropTypes.bool,
|
|
|
|
maxFontSizeMultiplier: PropTypes.number,
|
|
|
|
editable: PropTypes.bool,
|
|
|
|
keyboardType: PropTypes.oneOf([
|
|
|
|
// Cross-platform
|
|
|
|
'default',
|
|
|
|
'email-address',
|
|
|
|
'numeric',
|
|
|
|
'phone-pad',
|
|
|
|
'number-pad',
|
|
|
|
// iOS-only
|
|
|
|
'ascii-capable',
|
|
|
|
'numbers-and-punctuation',
|
|
|
|
'url',
|
|
|
|
'name-phone-pad',
|
|
|
|
'decimal-pad',
|
|
|
|
'twitter',
|
|
|
|
'web-search',
|
|
|
|
// Android-only
|
|
|
|
'visible-password',
|
|
|
|
]),
|
|
|
|
keyboardAppearance: PropTypes.oneOf(['default', 'light', 'dark']),
|
|
|
|
returnKeyType: PropTypes.oneOf([
|
|
|
|
// Cross-platform
|
|
|
|
'done',
|
|
|
|
'go',
|
|
|
|
'next',
|
|
|
|
'search',
|
|
|
|
'send',
|
|
|
|
// Android-only
|
|
|
|
'none',
|
|
|
|
'previous',
|
|
|
|
// iOS-only
|
|
|
|
'default',
|
|
|
|
'emergency-call',
|
|
|
|
'google',
|
|
|
|
'join',
|
|
|
|
'route',
|
|
|
|
'yahoo',
|
|
|
|
]),
|
|
|
|
returnKeyLabel: PropTypes.string,
|
|
|
|
maxLength: PropTypes.number,
|
|
|
|
numberOfLines: PropTypes.number,
|
|
|
|
disableFullscreenUI: PropTypes.bool,
|
|
|
|
enablesReturnKeyAutomatically: PropTypes.bool,
|
|
|
|
multiline: PropTypes.bool,
|
|
|
|
textBreakStrategy: PropTypes.oneOf(['simple', 'highQuality', 'balanced']),
|
|
|
|
onBlur: PropTypes.func,
|
|
|
|
onFocus: PropTypes.func,
|
|
|
|
onChange: PropTypes.func,
|
|
|
|
onChangeText: PropTypes.func,
|
|
|
|
onContentSizeChange: PropTypes.func,
|
|
|
|
onTextInput: PropTypes.func,
|
|
|
|
onEndEditing: PropTypes.func,
|
|
|
|
onSelectionChange: PropTypes.func,
|
|
|
|
onSubmitEditing: PropTypes.func,
|
|
|
|
onKeyPress: PropTypes.func,
|
|
|
|
onLayout: PropTypes.func,
|
|
|
|
onScroll: PropTypes.func,
|
|
|
|
placeholder: PropTypes.string,
|
|
|
|
placeholderTextColor: DeprecatedColorPropType,
|
|
|
|
scrollEnabled: PropTypes.bool,
|
|
|
|
secureTextEntry: PropTypes.bool,
|
|
|
|
selectionColor: DeprecatedColorPropType,
|
|
|
|
selectionState: PropTypes.instanceOf(DocumentSelectionState),
|
|
|
|
selection: PropTypes.shape({
|
|
|
|
start: PropTypes.number.isRequired,
|
|
|
|
end: PropTypes.number,
|
|
|
|
}),
|
|
|
|
value: PropTypes.string,
|
|
|
|
defaultValue: PropTypes.string,
|
|
|
|
clearButtonMode: PropTypes.oneOf([
|
|
|
|
'never',
|
|
|
|
'while-editing',
|
|
|
|
'unless-editing',
|
|
|
|
'always',
|
|
|
|
]),
|
|
|
|
clearTextOnFocus: PropTypes.bool,
|
|
|
|
selectTextOnFocus: PropTypes.bool,
|
|
|
|
blurOnSubmit: PropTypes.bool,
|
|
|
|
style: DeprecatedStyleSheetPropType(TextStylePropTypes),
|
|
|
|
underlineColorAndroid: DeprecatedColorPropType,
|
|
|
|
inlineImageLeft: PropTypes.string,
|
|
|
|
inlineImagePadding: PropTypes.number,
|
|
|
|
dataDetectorTypes: PropTypes.oneOfType([
|
|
|
|
PropTypes.oneOf(DataDetectorTypes),
|
|
|
|
PropTypes.arrayOf(PropTypes.oneOf(DataDetectorTypes)),
|
|
|
|
]),
|
|
|
|
caretHidden: PropTypes.bool,
|
|
|
|
contextMenuHidden: PropTypes.bool,
|
|
|
|
inputAccessoryViewID: PropTypes.string,
|
|
|
|
textContentType: PropTypes.oneOf([
|
|
|
|
'none',
|
|
|
|
'URL',
|
|
|
|
'addressCity',
|
|
|
|
'addressCityAndState',
|
|
|
|
'addressState',
|
|
|
|
'countryName',
|
|
|
|
'creditCardNumber',
|
|
|
|
'emailAddress',
|
|
|
|
'familyName',
|
|
|
|
'fullStreetAddress',
|
|
|
|
'givenName',
|
|
|
|
'jobTitle',
|
|
|
|
'location',
|
|
|
|
'middleName',
|
|
|
|
'name',
|
|
|
|
'namePrefix',
|
|
|
|
'nameSuffix',
|
|
|
|
'nickname',
|
|
|
|
'organizationName',
|
|
|
|
'postalCode',
|
|
|
|
'streetAddressLine1',
|
|
|
|
'streetAddressLine2',
|
|
|
|
'sublocality',
|
|
|
|
'telephoneNumber',
|
|
|
|
'username',
|
|
|
|
'password',
|
|
|
|
'newPassword',
|
|
|
|
'oneTimeCode',
|
|
|
|
]),
|
|
|
|
};
|
2018-11-07 18:42:19 -08:00
|
|
|
|
2018-03-03 15:04:46 -08:00
|
|
|
const styles = StyleSheet.create({
|
2017-03-20 00:00:18 -07:00
|
|
|
multilineInput: {
|
2017-12-19 19:48:22 -08:00
|
|
|
// This default top inset makes RCTMultilineTextInputView seem as close as possible
|
|
|
|
// to single-line RCTSinglelineTextInputView defaults, using the system defaults
|
2017-03-20 00:00:18 -07:00
|
|
|
// of font size 17 and a height of 31 points.
|
|
|
|
paddingTop: 5,
|
|
|
|
},
|
2015-02-19 20:10:52 -08:00
|
|
|
});
|
|
|
|
|
2018-11-15 20:42:47 -08:00
|
|
|
module.exports = TextInput;
|