774 lines
22 KiB
JavaScript
Raw Normal View History

/**
* 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.
*
2015-03-25 12:55:10 -07:00
* @flow
* @format
*/
'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');
const DeprecatedColorPropType = require('DeprecatedColorPropType');
const DeprecatedStyleSheetPropType = require('DeprecatedStyleSheetPropType');
const DocumentSelectionState = require('DocumentSelectionState');
const TextStylePropTypes = require('TextStylePropTypes');
const Platform = require('Platform');
const PropTypes = require('prop-types');
const React = require('React');
const ReactNative = require('ReactNative');
const StyleSheet = require('StyleSheet');
const Text = require('Text');
const TextAncestor = require('TextAncestor');
const TextInputState = require('TextInputState');
const TouchableWithoutFeedback = require('TouchableWithoutFeedback');
const UIManager = require('UIManager');
const {
AndroidTextInput,
RCTMultilineTextInputView,
RCTSinglelineTextInputView,
} = require('TextInputNativeComponent');
const emptyFunction = require('fbjs/lib/emptyFunction');
const invariant = require('fbjs/lib/invariant');
const warning = require('fbjs/lib/warning');
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';
const onlyMultiline = {
onTextInput: true,
children: true,
};
/**
* A foundational component for inputting text into the app via a
* keyboard. Props provide configurability for several features, such as
* auto-correction, auto-capitalization, placeholder text, and different keyboard
* 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
* example:
*
* ```ReactNativeWebPlayer
* import React, { Component } from 'react';
* import { AppRegistry, TextInput } from 'react-native';
*
* export default class UselessTextInput extends Component {
* 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}
* />
* );
* }
* }
*
* // skip this line if using Create React Native App
* AppRegistry.registerComponent('AwesomeProject', () => UselessTextInput);
* ```
*
* Two methods exposed via the native element are .focus() and .blur() that
* will focus or blur the TextInput programmatically.
*
* 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`:
*
* ```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}
* />
* );
* }
* }
*
* export default class UselessTextInputMultiline extends Component {
* 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>
* );
* }
* }
*
* // skip these lines if using Create React Native App
* AppRegistry.registerComponent(
* 'AwesomeProject',
* () => UselessTextInputMultiline
* );
* ```
*
* `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.
*
* 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.
*
*/
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
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
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
blur(): void {
nullthrows(this._inputRef).blur();
}
/**
* Returns `true` if the input is currently focused; `false` otherwise.
*/
isFocused(): boolean {
return (
TextInputState.currentlyFocusedField() ===
ReactNative.findNodeHandle(this._inputRef)
);
}
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
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
componentDidMount() {
this._lastNativeText = this.props.value;
const tag = ReactNative.findNodeHandle(this._inputRef);
if (tag != null) {
// tag is null only in unit tests
TextInputState.registerInput(tag);
}
const safeCallbackDoFocus = () => {
// Checks needed to prevent jest tests from crashing
if (this._inputRef && this._inputRef.focus) {
this._inputRef.focus();
}
};
if (this.context.focusEmitter) {
this._focusSubscription = this.context.focusEmitter.addListener(
'focus',
el => {
if (this === el) {
this._rafId = requestAnimationFrame(safeCallbackDoFocus);
} else if (
this.isFocused() &&
this._inputRef &&
this._inputRef.blur
) {
this._inputRef.blur();
}
},
);
if (this.props.autoFocus && this.context.onFocusRequested) {
this.context.onFocusRequested(this);
}
} else {
if (this.props.autoFocus) {
this._rafId = requestAnimationFrame(safeCallbackDoFocus);
}
}
}
componentWillUnmount() {
this._focusSubscription && this._focusSubscription.remove();
if (this.isFocused() && this._inputRef && this._inputRef.blur) {
this._inputRef.blur();
}
const tag = ReactNative.findNodeHandle(this._inputRef);
if (tag != null) {
TextInputState.unregisterInput(tag);
}
if (this._rafId != null) {
cancelAnimationFrame(this._rafId);
}
}
/**
* Removes all text from the `TextInput`.
*/
clear() {
nullthrows(this._inputRef).setNativeProps({text: ''});
}
render() {
let textInput;
2015-03-27 11:44:43 -07:00
if (Platform.OS === 'ios') {
textInput = UIManager.getViewManagerConfig('RCTVirtualText')
? this._renderIOS()
: this._renderIOSLegacy();
2015-03-27 11:44:43 -07:00
} else if (Platform.OS === 'android') {
textInput = this._renderAndroid();
2015-03-27 11:44:43 -07:00
}
return (
<TextAncestor.Provider value={true}>{textInput}</TextAncestor.Provider>
);
}
2015-03-27 11:44:43 -07:00
_getText(): ?string {
return typeof this.props.value === 'string'
? this.props.value
: typeof this.props.defaultValue === 'string'
? this.props.defaultValue
: '';
}
_renderIOSLegacy() {
let textContainer;
const props = Object.assign({}, this.props);
const style = [this.props.style];
if (props.selection && props.selection.end == null) {
props.selection = {
start: props.selection.start,
end: props.selection.start,
};
}
if (!props.multiline) {
if (__DEV__) {
for (const propKey in onlyMultiline) {
if (props[propKey]) {
const error = new Error(
'TextInput prop `' +
propKey +
'` is only supported with multiline.',
);
warning(false, '%s', error.stack);
}
}
}
textContainer = (
<RCTSinglelineTextInputView
ref={this._setNativeRef}
{...props}
onFocus={this._onFocus}
onBlur={this._onBlur}
onChange={this._onChange}
onSelectionChange={this._onSelectionChange}
onSelectionChangeShouldSetResponder={emptyFunction.thatReturnsTrue}
text={this._getText()}
/>
);
} else {
let children = props.children;
let childCount = 0;
React.Children.forEach(children, () => ++childCount);
invariant(
!(props.value && childCount),
'Cannot specify both value and children.',
);
if (childCount >= 1) {
children = (
iOS: Add a maxFontSizeMultiplier prop to <Text> and <TextInput> (#20915) Summary: **Motivation** Whenever a user changes the system font size to its maximum allowable setting, React Native apps that allow font scaling can become unusable because the text gets too big. Experimenting with a native app like iMessage on iOS, the font size used for non-body text (e.g. header, navigational elements) is capped while the body text (e.g. text in the message bubbles) is allowed to grow. This PR introduces a new prop on `<Text>` and `<TextInput>` called `maxFontSizeMultiplier`. This enables devs to set the maximum allowed text scale factor on a Text/TextInput. The default is 0 which means no limit. Another PR will add this feature to Android. **Test Plan** I created a test app which utilizes all categories of values of `maxFontSizeMultiplier`: - `undefined`: inherit from parent - `0`: no limit - `1`, `1.2`: fixed limits I tried this with `Text`, `TextInput` with `value`, and `TextInput` with children. For `Text`, I also verified that nesting works properly (if a child `Text` doesn't specify `maxFontSizeMultiplier`, it inherits it from its parent). Lastly, we've been using a version of this in Skype for several months. **Release Notes** [GENERAL] [ENHANCEMENT] [Text/TextInput] - Added maxFontSizeMultiplier prop to prevent some text from getting unusably large as user increases OS's font scale setting (iOS) Adam Comella Microsoft Corp. Pull Request resolved: https://github.com/facebook/react-native/pull/20915 Differential Revision: D9646739 Pulled By: shergin fbshipit-source-id: c823f59c1e342c22d6297b88b2cb11c5a1f10310
2018-09-04 17:33:06 -07:00
<Text
style={style}
iOS: Add a maxFontSizeMultiplier prop to <Text> and <TextInput> (#20915) Summary: **Motivation** Whenever a user changes the system font size to its maximum allowable setting, React Native apps that allow font scaling can become unusable because the text gets too big. Experimenting with a native app like iMessage on iOS, the font size used for non-body text (e.g. header, navigational elements) is capped while the body text (e.g. text in the message bubbles) is allowed to grow. This PR introduces a new prop on `<Text>` and `<TextInput>` called `maxFontSizeMultiplier`. This enables devs to set the maximum allowed text scale factor on a Text/TextInput. The default is 0 which means no limit. Another PR will add this feature to Android. **Test Plan** I created a test app which utilizes all categories of values of `maxFontSizeMultiplier`: - `undefined`: inherit from parent - `0`: no limit - `1`, `1.2`: fixed limits I tried this with `Text`, `TextInput` with `value`, and `TextInput` with children. For `Text`, I also verified that nesting works properly (if a child `Text` doesn't specify `maxFontSizeMultiplier`, it inherits it from its parent). Lastly, we've been using a version of this in Skype for several months. **Release Notes** [GENERAL] [ENHANCEMENT] [Text/TextInput] - Added maxFontSizeMultiplier prop to prevent some text from getting unusably large as user increases OS's font scale setting (iOS) Adam Comella Microsoft Corp. Pull Request resolved: https://github.com/facebook/react-native/pull/20915 Differential Revision: D9646739 Pulled By: shergin fbshipit-source-id: c823f59c1e342c22d6297b88b2cb11c5a1f10310
2018-09-04 17:33:06 -07:00
allowFontScaling={props.allowFontScaling}
maxFontSizeMultiplier={props.maxFontSizeMultiplier}>
{children}
</Text>
);
}
if (props.inputView) {
children = [children, props.inputView];
}
style.unshift(styles.multilineInput);
textContainer = (
<RCTMultilineTextInputView
ref={this._setNativeRef}
{...props}
children={children}
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}
accessibilityTraits + accessibilityComponentType >> accessibilityRole + accessibilityStates 2/3 Summary: Previously, I created two props, `accessibilityRole` and `accessibilityStates` for view. These props were intended to be a cross-platform solution to replace `accessibilityComponentType` on Android and `accessibilityTraits` on iOS. In this stack, I ran a code mod to replace instances of the two old properties used in our codebase with the new ones. For this diff, I did a search for all the remnant uses of `accessibilityComponentType` that was not caught by my script, and I manually changed them to `accessibilityRole` and `accessibilityStates`. If the same prop also set `accessibilityTraits` I also removed that here because the two new props works on both platforms. It was difficult to write a script for this, because most of them were contextual changes. Out of the contextual changes, most of them followed one of these two patterns: Before: ``` const accessibilityComponentType = 'button'; const accessibilityTraits = ['button']; if (this.props.checked) { accessibilityTraits.push('selected'); } if (this.props.disabled) { accessibilityTraits.push('disabled'); } contentView = ( <AdsManagerTouchableHighlight accessibilityComponentType={accessibilityComponentType} accessibilityTraits={accessibilityTraits} ``` After: const accessibilityRole = 'button'; const accessibilityStates = []; if (this.props.checked) { accessibilityStates.push('selected'); } if (this.props.disabled) { accessibilityStates.push('disabled'); } contentView = ( <AdsManagerTouchableHighlight accessibilityRole={accessibilityRole} accessibilityStates={accessibilityStates} Before: ``` <PressableBackground accessible={this.props.accessible} accessibilityLabel={this.props.accessibilityLabel} accessibilityTraits={this.props.accessibilityTraits} ``` After: ``` <PressableBackground accessible={this.props.accessible} accessibilityLabel={this.props.accessibilityLabel} accessibilityRole={this.props.accessibilityRole} accessibilityRole={this.props.accessibilityStates} ``` In addition to changing the props on the components, Another fix I had to do was to add props accessibilityRole and accessibilityStates to components that don't directly inherit properties from view including text input and touchables. Reviewed By: PeteTheHeat Differential Revision: D8943499 fbshipit-source-id: fbb40a5e5f5d630b0fe56a009ff24635d4c8cc93
2018-07-25 23:37:16 -07:00
accessibilityRole={props.accessibilityRole}
accessibilityStates={props.accessibilityStates}
nativeID={this.props.nativeID}
testID={props.testID}>
{textContainer}
</TouchableWithoutFeedback>
);
}
_renderIOS() {
const props = Object.assign({}, this.props);
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}
accessibilityTraits + accessibilityComponentType >> accessibilityRole + accessibilityStates 2/3 Summary: Previously, I created two props, `accessibilityRole` and `accessibilityStates` for view. These props were intended to be a cross-platform solution to replace `accessibilityComponentType` on Android and `accessibilityTraits` on iOS. In this stack, I ran a code mod to replace instances of the two old properties used in our codebase with the new ones. For this diff, I did a search for all the remnant uses of `accessibilityComponentType` that was not caught by my script, and I manually changed them to `accessibilityRole` and `accessibilityStates`. If the same prop also set `accessibilityTraits` I also removed that here because the two new props works on both platforms. It was difficult to write a script for this, because most of them were contextual changes. Out of the contextual changes, most of them followed one of these two patterns: Before: ``` const accessibilityComponentType = 'button'; const accessibilityTraits = ['button']; if (this.props.checked) { accessibilityTraits.push('selected'); } if (this.props.disabled) { accessibilityTraits.push('disabled'); } contentView = ( <AdsManagerTouchableHighlight accessibilityComponentType={accessibilityComponentType} accessibilityTraits={accessibilityTraits} ``` After: const accessibilityRole = 'button'; const accessibilityStates = []; if (this.props.checked) { accessibilityStates.push('selected'); } if (this.props.disabled) { accessibilityStates.push('disabled'); } contentView = ( <AdsManagerTouchableHighlight accessibilityRole={accessibilityRole} accessibilityStates={accessibilityStates} Before: ``` <PressableBackground accessible={this.props.accessible} accessibilityLabel={this.props.accessibilityLabel} accessibilityTraits={this.props.accessibilityTraits} ``` After: ``` <PressableBackground accessible={this.props.accessible} accessibilityLabel={this.props.accessibilityLabel} accessibilityRole={this.props.accessibilityRole} accessibilityRole={this.props.accessibilityStates} ``` In addition to changing the props on the components, Another fix I had to do was to add props accessibilityRole and accessibilityStates to components that don't directly inherit properties from view including text input and touchables. Reviewed By: PeteTheHeat Differential Revision: D8943499 fbshipit-source-id: fbb40a5e5f5d630b0fe56a009ff24635d4c8cc93
2018-07-25 23:37:16 -07:00
accessibilityRole={props.accessibilityRole}
accessibilityStates={props.accessibilityStates}
nativeID={this.props.nativeID}
testID={props.testID}>
{textContainer}
</TouchableWithoutFeedback>
);
}
_renderAndroid() {
const props = Object.assign({}, this.props);
props.style = [this.props.style];
props.autoCapitalize = UIManager.getViewManagerConfig(
'AndroidTextInput',
).Constants.AutoCapitalizationType[props.autoCapitalize || 'sentences'];
let children = this.props.children;
let childCount = 0;
React.Children.forEach(children, () => ++childCount);
invariant(
!(this.props.value && childCount),
'Cannot specify both value and children.',
);
if (childCount > 1) {
children = <Text>{children}</Text>;
}
if (props.selection && props.selection.end == null) {
props.selection = {
start: props.selection.start,
end: props.selection.start,
};
}
const textContainer = (
2015-03-27 11:44:43 -07:00
<AndroidTextInput
ref={this._setNativeRef}
{...props}
mostRecentEventCount={0}
2015-03-27 11:44:43 -07:00
onFocus={this._onFocus}
onBlur={this._onBlur}
onChange={this._onChange}
onSelectionChange={this._onSelectionChange}
onTextInput={this._onTextInput}
text={this._getText()}
children={children}
disableFullscreenUI={this.props.disableFullscreenUI}
textBreakStrategy={this.props.textBreakStrategy}
onScroll={this._onScroll}
/>
);
return (
<TouchableWithoutFeedback
Fix `onLayout` prop for TextInput on Android Summary: When the `autogrow` prop was removed from `TextInput` on Android, the `_onLayout` helper method was removed. This helper method implemented the hook required to make `autogrow` work, then dispatched the `onLayout` event to the handler in `this.props`. This change points passes the `onLayout` handler from `this.props` directly to the inner component. <!-- Thank you for sending the PR! We appreciate you spending the time to work on these changes. Help us understand your motivation by explaining why you decided to make this change. You can learn more about contributing to React Native here: http://facebook.github.io/react-native/docs/contributing.html Happy contributing! --> I was updating copied code in react-native-windows and noticed this bug. Run jest tests. N/A <!-- Help reviewers and the release process by writing your own release notes **INTERNAL and MINOR tagged notes will not be included in the next version's final release notes.** CATEGORY [----------] TYPE [ CLI ] [-------------] LOCATION [ DOCS ] [ BREAKING ] [-------------] [ GENERAL ] [ BUGFIX ] [-{Component}-] [ INTERNAL ] [ ENHANCEMENT ] [ {File} ] [ IOS ] [ FEATURE ] [ {Directory} ] |-----------| [ ANDROID ] [ MINOR ] [ {Framework} ] - | {Message} | [----------] [-------------] [-------------] |-----------| [CATEGORY] [TYPE] [LOCATION] - MESSAGE EXAMPLES: [IOS] [BREAKING] [FlatList] - Change a thing that breaks other things [ANDROID] [BUGFIX] [TextInput] - Did a thing to TextInput [CLI] [FEATURE] [local-cli/info/info.js] - CLI easier to do things with [DOCS] [BUGFIX] [GettingStarted.md] - Accidentally a thing/word [GENERAL] [ENHANCEMENT] [Yoga] - Added new yoga thing/position [INTERNAL] [FEATURE] [./scripts] - Added thing to script that nobody will see --> [ANDROID][MINOR][BUGFIX] [TextInput] - Fix `onLayout` prop for TextInput on Android Closes https://github.com/facebook/react-native/pull/18040 Differential Revision: D7078736 Pulled By: hramos fbshipit-source-id: 798530729d7f0ee1ebb59f698af4d4b6ff43928b
2018-02-24 00:59:22 -08:00
onLayout={props.onLayout}
onPress={this._onPress}
accessible={this.props.accessible}
accessibilityLabel={this.props.accessibilityLabel}
accessibilityTraits + accessibilityComponentType >> accessibilityRole + accessibilityStates 2/3 Summary: Previously, I created two props, `accessibilityRole` and `accessibilityStates` for view. These props were intended to be a cross-platform solution to replace `accessibilityComponentType` on Android and `accessibilityTraits` on iOS. In this stack, I ran a code mod to replace instances of the two old properties used in our codebase with the new ones. For this diff, I did a search for all the remnant uses of `accessibilityComponentType` that was not caught by my script, and I manually changed them to `accessibilityRole` and `accessibilityStates`. If the same prop also set `accessibilityTraits` I also removed that here because the two new props works on both platforms. It was difficult to write a script for this, because most of them were contextual changes. Out of the contextual changes, most of them followed one of these two patterns: Before: ``` const accessibilityComponentType = 'button'; const accessibilityTraits = ['button']; if (this.props.checked) { accessibilityTraits.push('selected'); } if (this.props.disabled) { accessibilityTraits.push('disabled'); } contentView = ( <AdsManagerTouchableHighlight accessibilityComponentType={accessibilityComponentType} accessibilityTraits={accessibilityTraits} ``` After: const accessibilityRole = 'button'; const accessibilityStates = []; if (this.props.checked) { accessibilityStates.push('selected'); } if (this.props.disabled) { accessibilityStates.push('disabled'); } contentView = ( <AdsManagerTouchableHighlight accessibilityRole={accessibilityRole} accessibilityStates={accessibilityStates} Before: ``` <PressableBackground accessible={this.props.accessible} accessibilityLabel={this.props.accessibilityLabel} accessibilityTraits={this.props.accessibilityTraits} ``` After: ``` <PressableBackground accessible={this.props.accessible} accessibilityLabel={this.props.accessibilityLabel} accessibilityRole={this.props.accessibilityRole} accessibilityRole={this.props.accessibilityStates} ``` In addition to changing the props on the components, Another fix I had to do was to add props accessibilityRole and accessibilityStates to components that don't directly inherit properties from view including text input and touchables. Reviewed By: PeteTheHeat Differential Revision: D8943499 fbshipit-source-id: fbb40a5e5f5d630b0fe56a009ff24635d4c8cc93
2018-07-25 23:37:16 -07:00
accessibilityRole={this.props.accessibilityRole}
accessibilityStates={this.props.accessibilityStates}
nativeID={this.props.nativeID}
testID={this.props.testID}>
{textContainer}
</TouchableWithoutFeedback>
2015-03-27 11:44:43 -07:00
);
}
2015-03-27 11:44:43 -07:00
_onFocus = (event: Event) => {
if (this.props.onFocus) {
this.props.onFocus(event);
}
if (this.props.selectionState) {
this.props.selectionState.focus();
}
};
_onPress = (event: PressEvent) => {
if (this.props.editable || this.props.editable === undefined) {
nullthrows(this._inputRef).focus();
}
};
_onChange = (event: Event) => {
// Make sure to fire the mostRecentEventCount first so it is already set on
// native when the text value is set.
if (this._inputRef && this._inputRef.setNativeProps) {
this._inputRef.setNativeProps({
mostRecentEventCount: event.nativeEvent.eventCount,
});
}
const text = event.nativeEvent.text;
this.props.onChange && this.props.onChange(event);
[ReactNative] TextInput bug fixes and features Summary: This introduces event counts to make sure JS doesn't set out of date values on native text inputs, which can cause dropped characters and can mess with autocomplete, and obviates the need for the input buffering which added lag and complexity to the component. Made sure to test simulated super-slow JS text event processing to make sure characters aren't dropped, as well as typing obviously correctable words and making sure autocomplete works as expected. TextInput is now a controlled input by default without causing any issues for most cases, so I removed the `controlled` prop. Fixes selection state jumping by restoring it after setting new text values, so highlighting the middle of some text in the new ReWrite example and hitting space will replace that selection with an underscore and keep the cursor at a sensible position as expected, instead of jumping to the end. Ads `maxLength` prop to support the most commonly needed syncronous behavior: preventing the user from typing too many characters. It can also be used to prevent users from continuing to type after entering special characters by changing it to the current length after a regex match. Made sure to verify it works well with pasted input (including in the middle of existing text), truncating it and collapsing the selection the same way it does on the web. Fixes bug in TextEventsExample where it wouldn't show the submit and end events, even though there were firing correctly.
2015-07-21 12:37:24 -07:00
this.props.onChangeText && this.props.onChangeText(text);
if (!this._inputRef) {
// calling `this.props.onChange` or `this.props.onChangeText`
// may clean up the input itself. Exits here.
return;
}
this._lastNativeText = text;
this.forceUpdate();
};
_onSelectionChange = (event: Event) => {
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();
}
};
componentDidUpdate() {
// 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.
const nativeProps = {};
if (
this._lastNativeText !== this.props.value &&
typeof this.props.value === 'string'
) {
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;
if (
this._lastNativeSelection &&
selection &&
(this._lastNativeSelection.start !== selection.start ||
this._lastNativeSelection.end !== selection.end)
) {
nativeProps.selection = this.props.selection;
}
if (
Object.keys(nativeProps).length > 0 &&
this._inputRef &&
this._inputRef.setNativeProps
) {
this._inputRef.setNativeProps(nativeProps);
}
if (this.props.selectionState && selection) {
this.props.selectionState.update(selection.start, selection.end);
}
}
_onBlur = (event: Event) => {
nullthrows(this._inputRef).blur();
if (this.props.onBlur) {
this.props.onBlur(event);
}
if (this.props.selectionState) {
this.props.selectionState.blur();
}
};
_onTextInput = (event: Event) => {
this.props.onTextInput && this.props.onTextInput(event);
};
_onScroll = (event: Event) => {
this.props.onScroll && this.props.onScroll(event);
};
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 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',
]),
};
const styles = StyleSheet.create({
multilineInput: {
// This default top inset makes RCTMultilineTextInputView seem as close as possible
// to single-line RCTSinglelineTextInputView defaults, using the system defaults
// of font size 17 and a height of 31 points.
paddingTop: 5,
},
});
module.exports = TextInput;