2015-02-20 04:10:52 +00:00
|
|
|
/**
|
2018-09-11 22:27:47 +00:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2015-03-23 20:35:08 +00:00
|
|
|
*
|
2018-02-17 02:24:55 +00: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-20 04:10:52 +00:00
|
|
|
*
|
2015-03-25 19:55:10 +00:00
|
|
|
* @flow
|
2018-01-15 03:32:22 +00:00
|
|
|
* @format
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2016-06-24 13:28:38 +00:00
|
|
|
const ColorPropType = require('ColorPropType');
|
2018-08-23 01:22:00 +00:00
|
|
|
const DeprecatedViewPropTypes = require('DeprecatedViewPropTypes');
|
2016-06-24 13:28:38 +00:00
|
|
|
const DocumentSelectionState = require('DocumentSelectionState');
|
|
|
|
const EventEmitter = require('EventEmitter');
|
2016-11-04 12:40:26 +00:00
|
|
|
const NativeMethodsMixin = require('NativeMethodsMixin');
|
2016-06-24 13:28:38 +00:00
|
|
|
const Platform = require('Platform');
|
2017-04-12 23:09:48 +00:00
|
|
|
const PropTypes = require('prop-types');
|
2018-08-23 01:22:00 +00:00
|
|
|
const React = require('React');
|
2016-10-15 01:50:14 +00:00
|
|
|
const ReactNative = require('ReactNative');
|
2016-06-24 13:28:38 +00:00
|
|
|
const StyleSheet = require('StyleSheet');
|
|
|
|
const Text = require('Text');
|
2018-05-09 07:47:46 +00:00
|
|
|
const TextAncestor = require('TextAncestor');
|
2016-06-24 13:28:38 +00:00
|
|
|
const TextInputState = require('TextInputState');
|
|
|
|
const TimerMixin = require('react-timer-mixin');
|
|
|
|
const TouchableWithoutFeedback = require('TouchableWithoutFeedback');
|
|
|
|
const UIManager = require('UIManager');
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2018-08-23 01:22:00 +00:00
|
|
|
const createReactClass = require('create-react-class');
|
2016-06-24 13:28:38 +00:00
|
|
|
const emptyFunction = require('fbjs/lib/emptyFunction');
|
|
|
|
const invariant = require('fbjs/lib/invariant');
|
|
|
|
const requireNativeComponent = require('requireNativeComponent');
|
2017-02-15 02:24:52 +00:00
|
|
|
const warning = require('fbjs/lib/warning');
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2018-08-14 23:31:04 +00:00
|
|
|
import type {TextStyleProp, ViewStyleProp} from 'StyleSheet';
|
2018-08-23 01:22:00 +00:00
|
|
|
import type {ColorValue} from 'StyleSheetTypes';
|
2018-05-14 07:08:58 +00:00
|
|
|
import type {ViewProps} from 'ViewPropTypes';
|
|
|
|
|
2018-03-02 00:53:36 +00:00
|
|
|
let AndroidTextInput;
|
|
|
|
let RCTMultilineTextInputView;
|
|
|
|
let RCTSinglelineTextInputView;
|
|
|
|
|
2015-09-24 00:03:06 +00:00
|
|
|
if (Platform.OS === 'android') {
|
2018-06-01 19:37:22 +00:00
|
|
|
AndroidTextInput = requireNativeComponent('AndroidTextInput');
|
2015-09-24 00:03:06 +00:00
|
|
|
} else if (Platform.OS === 'ios') {
|
2018-03-02 00:53:36 +00:00
|
|
|
RCTMultilineTextInputView = requireNativeComponent(
|
2018-01-15 03:32:22 +00:00
|
|
|
'RCTMultilineTextInputView',
|
|
|
|
);
|
2018-03-02 00:53:36 +00:00
|
|
|
RCTSinglelineTextInputView = requireNativeComponent(
|
2018-01-15 03:32:22 +00:00
|
|
|
'RCTSinglelineTextInputView',
|
|
|
|
);
|
2015-09-24 00:03:06 +00:00
|
|
|
}
|
2015-06-09 23:02:16 +00:00
|
|
|
|
2018-06-01 19:37:22 +00:00
|
|
|
const onlyMultiline = {
|
|
|
|
onTextInput: true,
|
|
|
|
children: true,
|
|
|
|
};
|
|
|
|
|
2015-03-25 19:55:10 +00:00
|
|
|
type Event = Object;
|
2016-08-26 00:18:05 +00:00
|
|
|
type Selection = {
|
|
|
|
start: number,
|
|
|
|
end?: number,
|
|
|
|
};
|
2015-03-25 19:55:10 +00:00
|
|
|
|
2016-07-31 21:20:13 +00:00
|
|
|
const DataDetectorTypes = [
|
|
|
|
'phoneNumber',
|
|
|
|
'link',
|
|
|
|
'address',
|
|
|
|
'calendarEvent',
|
|
|
|
'none',
|
|
|
|
'all',
|
|
|
|
];
|
|
|
|
|
2018-05-14 07:08:58 +00:00
|
|
|
type DataDetectorTypesType =
|
|
|
|
| 'phoneNumber'
|
|
|
|
| 'link'
|
|
|
|
| 'address'
|
|
|
|
| 'calendarEvent'
|
|
|
|
| 'none'
|
|
|
|
| 'all';
|
|
|
|
|
|
|
|
export type KeyboardType =
|
|
|
|
// Cross Platform
|
|
|
|
| 'default'
|
|
|
|
| 'email-address'
|
|
|
|
| 'numeric'
|
|
|
|
| 'phone-pad'
|
|
|
|
| 'number-pad'
|
2018-06-14 20:53:58 +00:00
|
|
|
| 'decimal-pad'
|
2018-05-14 07:08:58 +00:00
|
|
|
// iOS-only
|
|
|
|
| 'ascii-capable'
|
|
|
|
| 'numbers-and-punctuation'
|
|
|
|
| 'url'
|
|
|
|
| 'name-phone-pad'
|
|
|
|
| 'twitter'
|
|
|
|
| 'web-search'
|
|
|
|
// Android-only
|
|
|
|
| 'visible-password';
|
|
|
|
|
|
|
|
export type ReturnKeyType =
|
|
|
|
// Cross Platform
|
|
|
|
| 'done'
|
|
|
|
| 'go'
|
|
|
|
| 'next'
|
|
|
|
| 'search'
|
|
|
|
| 'send'
|
|
|
|
// Android-only
|
|
|
|
| 'none'
|
|
|
|
| 'previous'
|
|
|
|
// iOS-only
|
|
|
|
| 'default'
|
|
|
|
| 'emergency-call'
|
|
|
|
| 'google'
|
|
|
|
| 'join'
|
|
|
|
| 'route'
|
|
|
|
| 'yahoo';
|
|
|
|
|
|
|
|
export type AutoCapitalize = 'none' | 'sentences' | 'words' | 'characters';
|
|
|
|
|
|
|
|
type IOSProps = $ReadOnly<{|
|
|
|
|
spellCheck?: ?boolean,
|
|
|
|
keyboardAppearance?: ?('default' | 'light' | 'dark'),
|
|
|
|
enablesReturnKeyAutomatically?: ?boolean,
|
|
|
|
selectionState?: ?DocumentSelectionState,
|
|
|
|
clearButtonMode?: ?('never' | 'while-editing' | 'unless-editing' | 'always'),
|
|
|
|
clearTextOnFocus?: ?boolean,
|
|
|
|
dataDetectorTypes?:
|
|
|
|
| ?DataDetectorTypesType
|
|
|
|
| $ReadOnlyArray<DataDetectorTypesType>,
|
|
|
|
inputAccessoryViewID?: ?string,
|
|
|
|
textContentType?: ?(
|
|
|
|
| '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'
|
2018-09-13 21:44:30 +00:00
|
|
|
| 'newPassword'
|
|
|
|
| 'oneTimeCode'
|
2018-05-14 07:08:58 +00:00
|
|
|
),
|
2018-08-18 01:57:30 +00:00
|
|
|
scrollEnabled?: ?boolean,
|
2018-05-14 07:08:58 +00:00
|
|
|
|}>;
|
|
|
|
|
|
|
|
type AndroidProps = $ReadOnly<{|
|
|
|
|
returnKeyLabel?: ?string,
|
|
|
|
numberOfLines?: ?number,
|
|
|
|
disableFullscreenUI?: ?boolean,
|
|
|
|
textBreakStrategy?: ?('simple' | 'highQuality' | 'balanced'),
|
|
|
|
underlineColorAndroid?: ?ColorValue,
|
|
|
|
inlineImageLeft?: ?string,
|
|
|
|
inlineImagePadding?: ?number,
|
|
|
|
|}>;
|
|
|
|
|
|
|
|
type Props = $ReadOnly<{|
|
2018-08-14 23:31:04 +00:00
|
|
|
...$Diff<ViewProps, $ReadOnly<{|style: ?ViewStyleProp|}>>,
|
2018-05-14 07:08:58 +00:00
|
|
|
...IOSProps,
|
|
|
|
...AndroidProps,
|
|
|
|
autoCapitalize?: ?AutoCapitalize,
|
|
|
|
autoCorrect?: ?boolean,
|
|
|
|
autoFocus?: ?boolean,
|
|
|
|
allowFontScaling?: ?boolean,
|
2018-09-05 00:33:06 +00:00
|
|
|
maxFontSizeMultiplier?: ?boolean,
|
2018-05-14 07:08:58 +00:00
|
|
|
editable?: ?boolean,
|
|
|
|
keyboardType?: ?KeyboardType,
|
|
|
|
returnKeyType?: ?ReturnKeyType,
|
|
|
|
maxLength?: ?number,
|
|
|
|
multiline?: ?boolean,
|
|
|
|
onBlur?: ?Function,
|
|
|
|
onFocus?: ?Function,
|
|
|
|
onChange?: ?Function,
|
|
|
|
onChangeText?: ?Function,
|
|
|
|
onContentSizeChange?: ?Function,
|
|
|
|
onTextInput?: ?Function,
|
|
|
|
onEndEditing?: ?Function,
|
|
|
|
onSelectionChange?: ?Function,
|
|
|
|
onSubmitEditing?: ?Function,
|
|
|
|
onKeyPress?: ?Function,
|
|
|
|
onScroll?: ?Function,
|
|
|
|
placeholder?: ?Stringish,
|
|
|
|
placeholderTextColor?: ?ColorValue,
|
|
|
|
secureTextEntry?: ?boolean,
|
|
|
|
selectionColor?: ?ColorValue,
|
|
|
|
selection?: ?$ReadOnly<{|
|
|
|
|
start: number,
|
|
|
|
end?: ?number,
|
|
|
|
|}>,
|
|
|
|
value?: ?Stringish,
|
|
|
|
defaultValue?: ?Stringish,
|
|
|
|
selectTextOnFocus?: ?boolean,
|
|
|
|
blurOnSubmit?: ?boolean,
|
|
|
|
style?: ?TextStyleProp,
|
|
|
|
caretHidden?: ?boolean,
|
|
|
|
contextMenuHidden?: ?boolean,
|
|
|
|
|}>;
|
|
|
|
|
2015-03-09 16:28:51 +00:00
|
|
|
/**
|
|
|
|
* A foundational component for inputting text into the app via a
|
2015-06-16 17:05:27 +00:00
|
|
|
* keyboard. Props provide configurability for several features, such as
|
|
|
|
* auto-correction, auto-capitalization, placeholder text, and different keyboard
|
2015-03-09 16:28:51 +00:00
|
|
|
* types, such as a numeric keypad.
|
|
|
|
*
|
|
|
|
* The simplest use case is to plop down a `TextInput` and subscribe to the
|
2015-07-27 13:20:37 +00: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 16:28:51 +00:00
|
|
|
* example:
|
|
|
|
*
|
2016-06-24 18:53:30 +00:00
|
|
|
* ```ReactNativeWebPlayer
|
|
|
|
* import React, { Component } from 'react';
|
|
|
|
* import { AppRegistry, TextInput } from 'react-native';
|
|
|
|
*
|
2017-05-17 06:43:46 +00:00
|
|
|
* export default class UselessTextInput extends Component {
|
2016-06-24 18:53:30 +00: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-17 06:43:46 +00:00
|
|
|
* // skip this line if using Create React Native App
|
2016-06-24 18:53:30 +00:00
|
|
|
* AppRegistry.registerComponent('AwesomeProject', () => UselessTextInput);
|
2015-03-09 16:28:51 +00:00
|
|
|
* ```
|
|
|
|
*
|
2017-08-17 07:08:37 +00:00
|
|
|
* Two methods exposed via the native element are .focus() and .blur() that
|
|
|
|
* will focus or blur the TextInput programmatically.
|
|
|
|
*
|
2016-03-10 21:43:53 +00: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 18:53:30 +00: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-17 06:43:46 +00:00
|
|
|
* export default class UselessTextInputMultiline extends Component {
|
2016-06-24 18:53:30 +00: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-17 06:43:46 +00:00
|
|
|
* // skip these lines if using Create React Native App
|
2016-06-24 18:53:30 +00:00
|
|
|
* AppRegistry.registerComponent(
|
|
|
|
* 'AwesomeProject',
|
|
|
|
* () => UselessTextInputMultiline
|
|
|
|
* );
|
2016-03-10 21:43:53 +00:00
|
|
|
* ```
|
2016-06-23 21:12:01 +00: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 20:46:39 +00: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 16:28:51 +00:00
|
|
|
*/
|
2017-08-11 01:43:22 +00:00
|
|
|
|
2017-07-07 21:24:25 +00:00
|
|
|
const TextInput = createReactClass({
|
|
|
|
displayName: 'TextInput',
|
2018-05-17 18:18:36 +00:00
|
|
|
statics: {
|
|
|
|
State: {
|
|
|
|
currentlyFocusedField: TextInputState.currentlyFocusedField,
|
2018-08-06 21:56:11 +00:00
|
|
|
focusTextInput: TextInputState.focusTextInput,
|
|
|
|
blurTextInput: TextInputState.blurTextInput,
|
2018-05-17 18:18:36 +00:00
|
|
|
},
|
|
|
|
},
|
2015-02-20 04:10:52 +00:00
|
|
|
propTypes: {
|
2018-08-23 01:22:00 +00:00
|
|
|
...DeprecatedViewPropTypes,
|
2015-02-20 04:10:52 +00:00
|
|
|
/**
|
2016-06-24 18:53:30 +00:00
|
|
|
* Can tell `TextInput` to automatically capitalize certain characters.
|
2015-02-20 04:10:52 +00:00
|
|
|
*
|
2016-06-24 18:53:30 +00:00
|
|
|
* - `characters`: all characters.
|
|
|
|
* - `words`: first letter of each word.
|
|
|
|
* - `sentences`: first letter of each sentence (*default*).
|
|
|
|
* - `none`: don't auto capitalize anything.
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
2015-03-04 22:04:52 +00:00
|
|
|
autoCapitalize: PropTypes.oneOf([
|
|
|
|
'none',
|
|
|
|
'sentences',
|
|
|
|
'words',
|
|
|
|
'characters',
|
|
|
|
]),
|
2015-02-20 04:10:52 +00:00
|
|
|
/**
|
2016-06-24 18:53:30 +00:00
|
|
|
* If `false`, disables auto-correct. The default value is `true`.
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
|
|
|
autoCorrect: PropTypes.bool,
|
2016-11-25 12:20:21 +00:00
|
|
|
/**
|
|
|
|
* If `false`, disables spell-check style (i.e. red underlines).
|
|
|
|
* The default value is inherited from `autoCorrect`.
|
|
|
|
* @platform ios
|
|
|
|
*/
|
|
|
|
spellCheck: PropTypes.bool,
|
2015-02-20 04:10:52 +00:00
|
|
|
/**
|
2016-06-24 18:53:30 +00:00
|
|
|
* If `true`, focuses the input on `componentDidMount`.
|
|
|
|
* The default value is `false`.
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
|
|
|
autoFocus: PropTypes.bool,
|
iOS: Support allowFontScaling on TextInput
Summary:
Currently, only `Text` supports the `allowFontScaling` prop. This commit adds support for it on `TextInput`.
As part of this change, the TextInput setters for font attributes (e.g. size, weight) had to be refactored. The problem with them is that they use RCTFont's helpers which create a new font based on an existing font. These helpers lose information. In particular, they lose the scaleMultiplier.
For example, suppose the font size is 12 and the device's font multiplier is set to 1.5. So we'd create a font with size 12 and scaleMultiplier 1.5 which is an effective size of 18 (which is the only thing stored in the font). Next, suppose the device's font multiplier changes to 1. So we'd use an RCTFont helper to create a new font based on the existing font but with a scaleMultiplier of 1. However, the font didn't store the font size (12) and scaleMultiplier (1.5) separately. It just knows the (effective) font size of 18. So RCTFont thinks the new font has a font size of 18 and a scaleMultiplier of 1 so its effective font size is 18. This is incorrect and it should have been 12.
To fix this, the font attributes are now all stored individually. Anytime one of them changes, updateFont is called which recreates the font from scratch. This happens to fix some bugs around fontStyle and fontWeight which were reported several times before: #13730, #12738, #2140, #8533.
Created a test app where I verified that `allowFontScaling` works properly for `TextInputs` for all values (`undefined`, `true`, `false`) for a variety of `TextInputs`:
- Singleline TextInput
- Singleline TextInput's placeholder
- Multiline TextInput
- Multiline TextInput's placeholder
- Multiline TextInput using children instead of `value`
Also, verified switching `fontSize`, `fontWeight`, `fontStyle` and `fontFamily` through a bunch of combinations works properly.
Lastly, my team has been using this change in our app.
Adam Comella
Microsoft Corp.
Closes https://github.com/facebook/react-native/pull/14030
Reviewed By: TheSavior
Differential Revision: D5899959
Pulled By: shergin
fbshipit-source-id: c8c8c4d4d670cd2a142286e79bfffef3b58cecd3
2017-10-02 04:40:57 +00:00
|
|
|
/**
|
|
|
|
* Specifies whether fonts should scale to respect Text Size accessibility settings. The
|
|
|
|
* default is `true`.
|
|
|
|
*/
|
|
|
|
allowFontScaling: PropTypes.bool,
|
2018-09-05 00:33:06 +00:00
|
|
|
/**
|
|
|
|
* Specifies largest possible scale a font can reach when `allowFontScaling` is enabled.
|
|
|
|
* Possible values:
|
|
|
|
* `null/undefined` (default): inherit from the parent node or the global default (0)
|
|
|
|
* `0`: no max, ignore parent/global default
|
|
|
|
* `>= 1`: sets the maxFontSizeMultiplier of this node to this value
|
|
|
|
*/
|
|
|
|
maxFontSizeMultiplier: PropTypes.number,
|
2015-02-20 04:10:52 +00:00
|
|
|
/**
|
2016-06-24 18:53:30 +00:00
|
|
|
* If `false`, text is not editable. The default value is `true`.
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
|
|
|
editable: PropTypes.bool,
|
|
|
|
/**
|
2015-03-04 22:04:52 +00:00
|
|
|
* Determines which keyboard to open, e.g.`numeric`.
|
2015-07-27 13:20:37 +00:00
|
|
|
*
|
|
|
|
* The following values work across platforms:
|
2016-05-05 17:21:35 +00:00
|
|
|
*
|
2016-06-24 18:53:30 +00:00
|
|
|
* - `default`
|
|
|
|
* - `numeric`
|
2018-03-14 21:41:58 +00:00
|
|
|
* - `number-pad`
|
2018-06-14 20:53:58 +00:00
|
|
|
* - `decimal-pad`
|
2016-06-24 18:53:30 +00:00
|
|
|
* - `email-address`
|
2016-07-04 15:08:24 +00:00
|
|
|
* - `phone-pad`
|
2017-10-11 01:02:21 +00:00
|
|
|
*
|
|
|
|
* *iOS Only*
|
|
|
|
*
|
|
|
|
* The following values work on iOS only:
|
|
|
|
*
|
|
|
|
* - `ascii-capable`
|
|
|
|
* - `numbers-and-punctuation`
|
|
|
|
* - `url`
|
|
|
|
* - `name-phone-pad`
|
|
|
|
* - `twitter`
|
|
|
|
* - `web-search`
|
|
|
|
*
|
|
|
|
* *Android Only*
|
|
|
|
*
|
|
|
|
* The following values work on Android only:
|
|
|
|
*
|
|
|
|
* - `visible-password`
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
2015-03-04 22:04:52 +00:00
|
|
|
keyboardType: PropTypes.oneOf([
|
2015-06-05 15:46:17 +00:00
|
|
|
// Cross-platform
|
2015-06-09 23:02:16 +00:00
|
|
|
'default',
|
2015-06-05 15:46:17 +00:00
|
|
|
'email-address',
|
2016-01-14 19:41:10 +00:00
|
|
|
'numeric',
|
|
|
|
'phone-pad',
|
2018-03-14 21:41:58 +00:00
|
|
|
'number-pad',
|
2015-06-05 15:46:17 +00:00
|
|
|
// iOS-only
|
2015-03-31 01:25:30 +00:00
|
|
|
'ascii-capable',
|
|
|
|
'numbers-and-punctuation',
|
|
|
|
'url',
|
|
|
|
'name-phone-pad',
|
|
|
|
'decimal-pad',
|
|
|
|
'twitter',
|
|
|
|
'web-search',
|
2017-10-11 01:02:21 +00:00
|
|
|
// Android-only
|
|
|
|
'visible-password',
|
2015-03-04 22:04:52 +00:00
|
|
|
]),
|
2015-11-11 13:31:18 +00:00
|
|
|
/**
|
|
|
|
* Determines the color of the keyboard.
|
|
|
|
* @platform ios
|
|
|
|
*/
|
2018-01-15 03:32:22 +00:00
|
|
|
keyboardAppearance: PropTypes.oneOf(['default', 'light', 'dark']),
|
2015-03-31 01:25:30 +00:00
|
|
|
/**
|
2016-05-05 17:21:35 +00:00
|
|
|
* Determines how the return key should look. On Android you can also use
|
|
|
|
* `returnKeyLabel`.
|
|
|
|
*
|
2016-06-24 18:53:30 +00:00
|
|
|
* *Cross platform*
|
|
|
|
*
|
2016-05-05 17:21:35 +00:00
|
|
|
* The following values work across platforms:
|
|
|
|
*
|
2016-06-24 18:53:30 +00:00
|
|
|
* - `done`
|
|
|
|
* - `go`
|
|
|
|
* - `next`
|
|
|
|
* - `search`
|
|
|
|
* - `send`
|
|
|
|
*
|
|
|
|
* *Android Only*
|
2016-05-05 17:21:35 +00:00
|
|
|
*
|
|
|
|
* The following values work on Android only:
|
|
|
|
*
|
2016-06-24 18:53:30 +00:00
|
|
|
* - `none`
|
|
|
|
* - `previous`
|
|
|
|
*
|
|
|
|
* *iOS Only*
|
2016-05-05 17:21:35 +00:00
|
|
|
*
|
|
|
|
* The following values work on iOS only:
|
|
|
|
*
|
2016-06-24 18:53:30 +00:00
|
|
|
* - `default`
|
|
|
|
* - `emergency-call`
|
|
|
|
* - `google`
|
|
|
|
* - `join`
|
|
|
|
* - `route`
|
|
|
|
* - `yahoo`
|
2015-03-31 01:25:30 +00:00
|
|
|
*/
|
|
|
|
returnKeyType: PropTypes.oneOf([
|
2016-05-05 17:21:35 +00:00
|
|
|
// Cross-platform
|
|
|
|
'done',
|
2015-03-31 01:25:30 +00:00
|
|
|
'go',
|
|
|
|
'next',
|
|
|
|
'search',
|
|
|
|
'send',
|
2016-05-05 17:21:35 +00:00
|
|
|
// Android-only
|
|
|
|
'none',
|
|
|
|
'previous',
|
|
|
|
// iOS-only
|
|
|
|
'default',
|
2015-03-31 01:25:30 +00:00
|
|
|
'emergency-call',
|
2016-05-05 17:21:35 +00:00
|
|
|
'google',
|
|
|
|
'join',
|
|
|
|
'route',
|
|
|
|
'yahoo',
|
2015-03-31 01:25:30 +00:00
|
|
|
]),
|
2016-05-05 17:21:35 +00:00
|
|
|
/**
|
|
|
|
* Sets the return key to the label. Use it instead of `returnKeyType`.
|
|
|
|
* @platform android
|
|
|
|
*/
|
2016-07-07 15:44:59 +00:00
|
|
|
returnKeyLabel: PropTypes.string,
|
2015-07-21 19:37:24 +00:00
|
|
|
/**
|
2015-07-27 13:20:37 +00:00
|
|
|
* Limits the maximum number of characters that can be entered. Use this
|
2015-07-21 19:37:24 +00:00
|
|
|
* instead of implementing the logic in JS to avoid flicker.
|
|
|
|
*/
|
|
|
|
maxLength: PropTypes.number,
|
2015-09-08 17:31:37 +00:00
|
|
|
/**
|
2016-06-24 18:53:30 +00:00
|
|
|
* Sets the number of lines for a `TextInput`. Use it with multiline set to
|
|
|
|
* `true` to be able to fill the lines.
|
2015-09-08 17:31:37 +00:00
|
|
|
* @platform android
|
|
|
|
*/
|
|
|
|
numberOfLines: PropTypes.number,
|
2016-11-23 14:41:53 +00:00
|
|
|
/**
|
|
|
|
* When `false`, if there is a small amount of space available around a text input
|
|
|
|
* (e.g. landscape orientation on a phone), the OS may choose to have the user edit
|
|
|
|
* the text inside of a full screen text input mode. When `true`, this feature is
|
|
|
|
* disabled and users will always edit the text directly inside of the text input.
|
|
|
|
* Defaults to `false`.
|
|
|
|
* @platform android
|
|
|
|
*/
|
|
|
|
disableFullscreenUI: PropTypes.bool,
|
2015-03-31 01:25:30 +00:00
|
|
|
/**
|
2016-06-24 18:53:30 +00:00
|
|
|
* If `true`, the keyboard disables the return key when there is no text and
|
|
|
|
* automatically enables it when there is text. The default value is `false`.
|
2015-07-27 13:20:37 +00:00
|
|
|
* @platform ios
|
2015-03-31 01:25:30 +00:00
|
|
|
*/
|
|
|
|
enablesReturnKeyAutomatically: PropTypes.bool,
|
2015-02-20 04:10:52 +00:00
|
|
|
/**
|
2016-06-24 18:53:30 +00:00
|
|
|
* If `true`, the text input can be multiple lines.
|
|
|
|
* The default value is `false`.
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
|
|
|
multiline: PropTypes.bool,
|
2016-12-16 09:19:16 +00:00
|
|
|
/**
|
|
|
|
* Set text break strategy on Android API Level 23+, possible values are `simple`, `highQuality`, `balanced`
|
|
|
|
* The default value is `simple`.
|
|
|
|
* @platform android
|
|
|
|
*/
|
2017-04-12 23:09:48 +00:00
|
|
|
textBreakStrategy: PropTypes.oneOf(['simple', 'highQuality', 'balanced']),
|
2015-02-20 04:10:52 +00:00
|
|
|
/**
|
2016-06-24 18:53:30 +00:00
|
|
|
* Callback that is called when the text input is blurred.
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
|
|
|
onBlur: PropTypes.func,
|
|
|
|
/**
|
2016-06-24 18:53:30 +00:00
|
|
|
* Callback that is called when the text input is focused.
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
|
|
|
onFocus: PropTypes.func,
|
|
|
|
/**
|
|
|
|
* Callback that is called when the text input's text changes.
|
|
|
|
*/
|
2015-03-27 18:44:43 +00:00
|
|
|
onChange: PropTypes.func,
|
2015-06-15 19:17:11 +00:00
|
|
|
/**
|
|
|
|
* Callback that is called when the text input's text changes.
|
|
|
|
* Changed text is passed as an argument to the callback handler.
|
|
|
|
*/
|
2015-02-20 04:10:52 +00:00
|
|
|
onChangeText: PropTypes.func,
|
2016-07-07 15:44:59 +00:00
|
|
|
/**
|
|
|
|
* Callback that is called when the text input's content size changes.
|
|
|
|
* This will be called with
|
|
|
|
* `{ nativeEvent: { contentSize: { width, height } } }`.
|
|
|
|
*
|
|
|
|
* Only called for multiline text inputs.
|
|
|
|
*/
|
|
|
|
onContentSizeChange: PropTypes.func,
|
2018-05-13 08:38:36 +00:00
|
|
|
onTextInput: PropTypes.func,
|
2015-04-10 00:16:14 +00:00
|
|
|
/**
|
|
|
|
* Callback that is called when text input ends.
|
|
|
|
*/
|
2015-02-20 04:10:52 +00:00
|
|
|
onEndEditing: PropTypes.func,
|
2016-01-07 15:36:51 +00:00
|
|
|
/**
|
2016-06-24 18:53:30 +00:00
|
|
|
* Callback that is called when the text input selection is changed.
|
2017-02-02 12:46:27 +00:00
|
|
|
* This will be called with
|
|
|
|
* `{ nativeEvent: { selection: { start, end } } }`.
|
2016-01-07 15:36:51 +00:00
|
|
|
*/
|
|
|
|
onSelectionChange: PropTypes.func,
|
2015-04-10 00:16:14 +00:00
|
|
|
/**
|
|
|
|
* Callback that is called when the text input's submit button is pressed.
|
2016-06-24 18:53:30 +00:00
|
|
|
* Invalid if `multiline={true}` is specified.
|
2015-04-10 00:16:14 +00:00
|
|
|
*/
|
2015-02-20 04:10:52 +00:00
|
|
|
onSubmitEditing: PropTypes.func,
|
2015-11-02 17:13:41 +00:00
|
|
|
/**
|
|
|
|
* Callback that is called when a key is pressed.
|
2016-12-30 00:56:01 +00:00
|
|
|
* This will be called with `{ nativeEvent: { key: keyValue } }`
|
|
|
|
* where `keyValue` is `'Enter'` or `'Backspace'` for respective keys and
|
|
|
|
* the typed-in character otherwise including `' '` for space.
|
2016-06-24 18:53:30 +00:00
|
|
|
* Fires before `onChange` callbacks.
|
2015-11-02 17:13:41 +00:00
|
|
|
*/
|
|
|
|
onKeyPress: PropTypes.func,
|
2015-05-15 18:41:15 +00:00
|
|
|
/**
|
2015-07-27 13:20:37 +00:00
|
|
|
* Invoked on mount and layout changes with `{x, y, width, height}`.
|
2015-05-15 18:41:15 +00:00
|
|
|
*/
|
|
|
|
onLayout: PropTypes.func,
|
2016-11-22 19:52:18 +00:00
|
|
|
/**
|
|
|
|
* Invoked on content scroll with `{ nativeEvent: { contentOffset: { x, y } } }`.
|
|
|
|
* May also contain other properties from ScrollEvent but on Android contentSize
|
|
|
|
* is not provided for performance reasons.
|
|
|
|
*/
|
|
|
|
onScroll: PropTypes.func,
|
2015-02-20 04:10:52 +00:00
|
|
|
/**
|
2016-06-24 18:53:30 +00:00
|
|
|
* The string that will be rendered before text input has been entered.
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
2017-10-10 05:15:45 +00:00
|
|
|
placeholder: PropTypes.string,
|
2015-02-20 04:10:52 +00:00
|
|
|
/**
|
2016-06-24 18:53:30 +00:00
|
|
|
* The text color of the placeholder string.
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
2016-06-23 10:06:36 +00:00
|
|
|
placeholderTextColor: ColorPropType,
|
2018-08-09 01:32:18 +00:00
|
|
|
/**
|
|
|
|
* If `false`, scrolling of the text view will be disabled.
|
|
|
|
* The default value is `true`. Does only work with 'multiline={true}'.
|
|
|
|
* @platform ios
|
|
|
|
*/
|
|
|
|
scrollEnabled: PropTypes.bool,
|
2015-07-27 13:20:37 +00:00
|
|
|
/**
|
2016-06-24 18:53:30 +00:00
|
|
|
* If `true`, the text input obscures the text entered so that sensitive text
|
2017-10-14 23:20:51 +00:00
|
|
|
* like passwords stay secure. The default value is `false`. Does not work with 'multiline={true}'.
|
2015-07-27 13:20:37 +00:00
|
|
|
*/
|
|
|
|
secureTextEntry: PropTypes.bool,
|
2016-02-03 13:48:31 +00:00
|
|
|
/**
|
2018-01-15 03:32:22 +00:00
|
|
|
* The highlight and cursor color of the text input.
|
|
|
|
*/
|
2016-06-23 10:06:36 +00:00
|
|
|
selectionColor: ColorPropType,
|
2015-02-20 04:10:52 +00:00
|
|
|
/**
|
2016-06-24 18:53:30 +00:00
|
|
|
* An instance of `DocumentSelectionState`, this is some state that is responsible for
|
|
|
|
* maintaining selection information for a document.
|
|
|
|
*
|
|
|
|
* Some functionality that can be performed with this instance is:
|
|
|
|
*
|
|
|
|
* - `blur()`
|
|
|
|
* - `focus()`
|
|
|
|
* - `update()`
|
|
|
|
*
|
2016-06-28 21:51:00 +00:00
|
|
|
* > You can reference `DocumentSelectionState` in
|
2016-06-24 18:53:30 +00:00
|
|
|
* > [`vendor/document/selection/DocumentSelectionState.js`](https://github.com/facebook/react-native/blob/master/Libraries/vendor/document/selection/DocumentSelectionState.js)
|
|
|
|
*
|
2015-07-27 13:20:37 +00:00
|
|
|
* @platform ios
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
|
|
|
selectionState: PropTypes.instanceOf(DocumentSelectionState),
|
2016-08-26 00:18:05 +00:00
|
|
|
/**
|
|
|
|
* The start and end of the text input's selection. Set start and end to
|
|
|
|
* the same value to position the cursor.
|
|
|
|
*/
|
|
|
|
selection: PropTypes.shape({
|
|
|
|
start: PropTypes.number.isRequired,
|
|
|
|
end: PropTypes.number,
|
|
|
|
}),
|
2015-02-20 04:10:52 +00:00
|
|
|
/**
|
2016-06-24 18:53:30 +00:00
|
|
|
* The value to show for the text input. `TextInput` is a controlled
|
2015-07-21 19:37:24 +00:00
|
|
|
* component, which means the native value will be forced to match this
|
2016-06-24 18:53:30 +00:00
|
|
|
* value prop if provided. For most uses, this works great, but in some
|
2015-07-21 19:37:24 +00:00
|
|
|
* cases this may cause flickering - one common cause is preventing edits
|
2015-07-27 13:20:37 +00:00
|
|
|
* by keeping value the same. In addition to simply setting the same value,
|
2015-07-21 19:37:24 +00:00
|
|
|
* either set `editable={false}`, or set/update `maxLength` to prevent
|
|
|
|
* unwanted edits without flicker.
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
|
|
|
value: PropTypes.string,
|
2015-07-22 21:03:32 +00:00
|
|
|
/**
|
|
|
|
* Provides an initial value that will change when the user starts typing.
|
2016-06-24 18:53:30 +00:00
|
|
|
* Useful for simple use-cases where you do not want to deal with listening
|
2015-07-22 21:03:32 +00:00
|
|
|
* to events and updating the value prop to keep the controlled state in sync.
|
|
|
|
*/
|
2017-03-16 00:46:14 +00:00
|
|
|
defaultValue: PropTypes.string,
|
2015-02-26 23:24:19 +00:00
|
|
|
/**
|
2016-06-24 18:53:30 +00:00
|
|
|
* When the clear button should appear on the right side of the text view.
|
2018-02-02 19:17:14 +00:00
|
|
|
* This property is supported only for single-line TextInput component.
|
2015-07-27 13:20:37 +00:00
|
|
|
* @platform ios
|
2015-02-26 23:24:19 +00:00
|
|
|
*/
|
2015-03-04 22:04:52 +00:00
|
|
|
clearButtonMode: PropTypes.oneOf([
|
|
|
|
'never',
|
|
|
|
'while-editing',
|
|
|
|
'unless-editing',
|
|
|
|
'always',
|
|
|
|
]),
|
2015-04-15 00:51:28 +00:00
|
|
|
/**
|
2016-06-24 18:53:30 +00:00
|
|
|
* If `true`, clears the text field automatically when editing begins.
|
2015-07-27 13:20:37 +00:00
|
|
|
* @platform ios
|
2015-04-15 00:51:28 +00:00
|
|
|
*/
|
|
|
|
clearTextOnFocus: PropTypes.bool,
|
|
|
|
/**
|
2016-06-24 18:53:30 +00:00
|
|
|
* If `true`, all text will automatically be selected on focus.
|
2015-04-15 00:51:28 +00:00
|
|
|
*/
|
|
|
|
selectTextOnFocus: PropTypes.bool,
|
2015-11-05 05:01:49 +00:00
|
|
|
/**
|
2016-06-24 18:53:30 +00:00
|
|
|
* If `true`, the text field will blur when submitted.
|
2015-12-02 15:11:20 +00:00
|
|
|
* The default value is true for single-line fields and false for
|
2016-06-24 18:53:30 +00:00
|
|
|
* multiline fields. Note that for multiline fields, setting `blurOnSubmit`
|
|
|
|
* to `true` means that pressing return will blur the field and trigger the
|
2016-06-28 21:51:00 +00:00
|
|
|
* `onSubmitEditing` event instead of inserting a newline into the field.
|
2015-11-05 05:01:49 +00:00
|
|
|
*/
|
|
|
|
blurOnSubmit: PropTypes.bool,
|
2015-04-15 00:51:28 +00:00
|
|
|
/**
|
2017-10-14 03:38:13 +00:00
|
|
|
* Note that not all Text styles are supported, an incomplete list of what is not supported includes:
|
|
|
|
*
|
|
|
|
* - `borderLeftWidth`
|
|
|
|
* - `borderTopWidth`
|
|
|
|
* - `borderRightWidth`
|
|
|
|
* - `borderBottomWidth`
|
|
|
|
* - `borderTopLeftRadius`
|
|
|
|
* - `borderTopRightRadius`
|
|
|
|
* - `borderBottomRightRadius`
|
|
|
|
* - `borderBottomLeftRadius`
|
|
|
|
*
|
2016-12-26 11:54:47 +00:00
|
|
|
* see [Issue#7070](https://github.com/facebook/react-native/issues/7070)
|
|
|
|
* for more detail.
|
|
|
|
*
|
2017-01-31 20:07:15 +00:00
|
|
|
* [Styles](docs/style.html)
|
2015-04-15 00:51:28 +00:00
|
|
|
*/
|
2015-03-09 16:29:09 +00:00
|
|
|
style: Text.propTypes.style,
|
2015-06-17 22:14:42 +00:00
|
|
|
/**
|
2016-06-24 18:53:30 +00:00
|
|
|
* The color of the `TextInput` underline.
|
2015-07-27 13:20:37 +00:00
|
|
|
* @platform android
|
2015-06-17 22:14:42 +00:00
|
|
|
*/
|
2016-06-23 10:06:36 +00:00
|
|
|
underlineColorAndroid: ColorPropType,
|
2016-06-28 21:11:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If defined, the provided image resource will be rendered on the left.
|
2017-08-31 17:14:04 +00:00
|
|
|
* The image resource must be inside `/android/app/src/main/res/drawable` and referenced
|
|
|
|
* like
|
|
|
|
* ```
|
|
|
|
* <TextInput
|
|
|
|
* inlineImageLeft='search_icon'
|
|
|
|
* />
|
|
|
|
* ```
|
2016-06-28 21:11:23 +00:00
|
|
|
* @platform android
|
|
|
|
*/
|
|
|
|
inlineImageLeft: PropTypes.string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Padding between the inline image, if any, and the text input itself.
|
|
|
|
* @platform android
|
|
|
|
*/
|
|
|
|
inlineImagePadding: PropTypes.number,
|
2016-07-31 21:20:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines the types of data converted to clickable URLs in the text input.
|
|
|
|
* Only valid if `multiline={true}` and `editable={false}`.
|
|
|
|
* By default no data types are detected.
|
|
|
|
*
|
|
|
|
* You can provide one type or an array of many types.
|
|
|
|
*
|
|
|
|
* Possible values for `dataDetectorTypes` are:
|
|
|
|
*
|
|
|
|
* - `'phoneNumber'`
|
|
|
|
* - `'link'`
|
|
|
|
* - `'address'`
|
|
|
|
* - `'calendarEvent'`
|
|
|
|
* - `'none'`
|
|
|
|
* - `'all'`
|
|
|
|
*
|
|
|
|
* @platform ios
|
|
|
|
*/
|
|
|
|
dataDetectorTypes: PropTypes.oneOfType([
|
|
|
|
PropTypes.oneOf(DataDetectorTypes),
|
|
|
|
PropTypes.arrayOf(PropTypes.oneOf(DataDetectorTypes)),
|
|
|
|
]),
|
2017-02-24 01:04:07 +00:00
|
|
|
/**
|
|
|
|
* If `true`, caret is hidden. The default value is `false`.
|
2018-02-02 07:06:01 +00:00
|
|
|
* This property is supported only for single-line TextInput component on iOS.
|
2017-02-24 01:04:07 +00:00
|
|
|
*/
|
|
|
|
caretHidden: PropTypes.bool,
|
2018-02-28 01:29:40 +00:00
|
|
|
/*
|
|
|
|
* If `true`, contextMenuHidden is hidden. The default value is `false`.
|
|
|
|
*/
|
|
|
|
contextMenuHidden: PropTypes.bool,
|
2018-02-27 18:42:44 +00:00
|
|
|
/**
|
|
|
|
* An optional identifier which links a custom InputAccessoryView to
|
|
|
|
* this text input. The InputAccessoryView is rendered above the
|
|
|
|
* keyboard when this text input is focused.
|
|
|
|
* @platform ios
|
|
|
|
*/
|
|
|
|
inputAccessoryViewID: PropTypes.string,
|
2018-04-02 09:31:16 +00:00
|
|
|
/**
|
|
|
|
* Give the keyboard and the system information about the
|
|
|
|
* expected semantic meaning for the content that users enter.
|
|
|
|
* @platform ios
|
|
|
|
*/
|
|
|
|
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',
|
2018-09-13 21:44:30 +00:00
|
|
|
'newPassword',
|
|
|
|
'oneTimeCode',
|
2018-04-02 09:31:16 +00:00
|
|
|
]),
|
2015-02-20 04:10:52 +00:00
|
|
|
},
|
iOS: Support allowFontScaling on TextInput
Summary:
Currently, only `Text` supports the `allowFontScaling` prop. This commit adds support for it on `TextInput`.
As part of this change, the TextInput setters for font attributes (e.g. size, weight) had to be refactored. The problem with them is that they use RCTFont's helpers which create a new font based on an existing font. These helpers lose information. In particular, they lose the scaleMultiplier.
For example, suppose the font size is 12 and the device's font multiplier is set to 1.5. So we'd create a font with size 12 and scaleMultiplier 1.5 which is an effective size of 18 (which is the only thing stored in the font). Next, suppose the device's font multiplier changes to 1. So we'd use an RCTFont helper to create a new font based on the existing font but with a scaleMultiplier of 1. However, the font didn't store the font size (12) and scaleMultiplier (1.5) separately. It just knows the (effective) font size of 18. So RCTFont thinks the new font has a font size of 18 and a scaleMultiplier of 1 so its effective font size is 18. This is incorrect and it should have been 12.
To fix this, the font attributes are now all stored individually. Anytime one of them changes, updateFont is called which recreates the font from scratch. This happens to fix some bugs around fontStyle and fontWeight which were reported several times before: #13730, #12738, #2140, #8533.
Created a test app where I verified that `allowFontScaling` works properly for `TextInputs` for all values (`undefined`, `true`, `false`) for a variety of `TextInputs`:
- Singleline TextInput
- Singleline TextInput's placeholder
- Multiline TextInput
- Multiline TextInput's placeholder
- Multiline TextInput using children instead of `value`
Also, verified switching `fontSize`, `fontWeight`, `fontStyle` and `fontFamily` through a bunch of combinations works properly.
Lastly, my team has been using this change in our app.
Adam Comella
Microsoft Corp.
Closes https://github.com/facebook/react-native/pull/14030
Reviewed By: TheSavior
Differential Revision: D5899959
Pulled By: shergin
fbshipit-source-id: c8c8c4d4d670cd2a142286e79bfffef3b58cecd3
2017-10-02 04:40:57 +00:00
|
|
|
getDefaultProps(): Object {
|
|
|
|
return {
|
|
|
|
allowFontScaling: true,
|
2018-04-26 06:27:48 +00:00
|
|
|
underlineColorAndroid: 'transparent',
|
iOS: Support allowFontScaling on TextInput
Summary:
Currently, only `Text` supports the `allowFontScaling` prop. This commit adds support for it on `TextInput`.
As part of this change, the TextInput setters for font attributes (e.g. size, weight) had to be refactored. The problem with them is that they use RCTFont's helpers which create a new font based on an existing font. These helpers lose information. In particular, they lose the scaleMultiplier.
For example, suppose the font size is 12 and the device's font multiplier is set to 1.5. So we'd create a font with size 12 and scaleMultiplier 1.5 which is an effective size of 18 (which is the only thing stored in the font). Next, suppose the device's font multiplier changes to 1. So we'd use an RCTFont helper to create a new font based on the existing font but with a scaleMultiplier of 1. However, the font didn't store the font size (12) and scaleMultiplier (1.5) separately. It just knows the (effective) font size of 18. So RCTFont thinks the new font has a font size of 18 and a scaleMultiplier of 1 so its effective font size is 18. This is incorrect and it should have been 12.
To fix this, the font attributes are now all stored individually. Anytime one of them changes, updateFont is called which recreates the font from scratch. This happens to fix some bugs around fontStyle and fontWeight which were reported several times before: #13730, #12738, #2140, #8533.
Created a test app where I verified that `allowFontScaling` works properly for `TextInputs` for all values (`undefined`, `true`, `false`) for a variety of `TextInputs`:
- Singleline TextInput
- Singleline TextInput's placeholder
- Multiline TextInput
- Multiline TextInput's placeholder
- Multiline TextInput using children instead of `value`
Also, verified switching `fontSize`, `fontWeight`, `fontStyle` and `fontFamily` through a bunch of combinations works properly.
Lastly, my team has been using this change in our app.
Adam Comella
Microsoft Corp.
Closes https://github.com/facebook/react-native/pull/14030
Reviewed By: TheSavior
Differential Revision: D5899959
Pulled By: shergin
fbshipit-source-id: c8c8c4d4d670cd2a142286e79bfffef3b58cecd3
2017-10-02 04:40:57 +00:00
|
|
|
};
|
|
|
|
},
|
2015-02-20 04:10:52 +00:00
|
|
|
/**
|
|
|
|
* `NativeMethodsMixin` will look for this when invoking `setNativeProps`. We
|
|
|
|
* make `this` look like an actual native component class.
|
|
|
|
*/
|
2015-03-11 21:45:49 +00:00
|
|
|
mixins: [NativeMethodsMixin, TimerMixin],
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2016-04-09 18:12:46 +00:00
|
|
|
/**
|
2016-06-24 18:53:30 +00:00
|
|
|
* Returns `true` if the input is currently focused; `false` otherwise.
|
2016-04-09 18:12:46 +00:00
|
|
|
*/
|
2015-03-25 19:55:10 +00:00
|
|
|
isFocused: function(): boolean {
|
2018-01-15 03:32:22 +00:00
|
|
|
return (
|
|
|
|
TextInputState.currentlyFocusedField() ===
|
|
|
|
ReactNative.findNodeHandle(this._inputRef)
|
|
|
|
);
|
2015-02-20 04:10:52 +00:00
|
|
|
},
|
|
|
|
|
2016-08-26 00:18:05 +00:00
|
|
|
_inputRef: (undefined: any),
|
2015-03-25 19:55:10 +00:00
|
|
|
_focusSubscription: (undefined: ?Function),
|
2016-05-26 14:20:50 +00:00
|
|
|
_lastNativeText: (undefined: ?string),
|
2016-08-26 00:18:05 +00:00
|
|
|
_lastNativeSelection: (undefined: ?Selection),
|
2015-03-25 19:55:10 +00:00
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
componentDidMount: function() {
|
2016-05-26 14:20:50 +00:00
|
|
|
this._lastNativeText = this.props.value;
|
2018-04-16 20:03:50 +00:00
|
|
|
const tag = ReactNative.findNodeHandle(this._inputRef);
|
|
|
|
if (tag != null) {
|
|
|
|
// tag is null only in unit tests
|
|
|
|
TextInputState.registerInput(tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.context.focusEmitter) {
|
|
|
|
this._focusSubscription = this.context.focusEmitter.addListener(
|
|
|
|
'focus',
|
|
|
|
el => {
|
|
|
|
if (this === el) {
|
|
|
|
this.requestAnimationFrame(this.focus);
|
|
|
|
} else if (this.isFocused()) {
|
|
|
|
this.blur();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
if (this.props.autoFocus) {
|
|
|
|
this.context.onFocusRequested(this);
|
|
|
|
}
|
|
|
|
} else {
|
2015-02-20 04:10:52 +00:00
|
|
|
if (this.props.autoFocus) {
|
|
|
|
this.requestAnimationFrame(this.focus);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-03-11 21:45:49 +00:00
|
|
|
componentWillUnmount: function() {
|
|
|
|
this._focusSubscription && this._focusSubscription.remove();
|
2015-04-24 16:12:04 +00:00
|
|
|
if (this.isFocused()) {
|
|
|
|
this.blur();
|
|
|
|
}
|
2018-04-16 20:03:50 +00:00
|
|
|
const tag = ReactNative.findNodeHandle(this._inputRef);
|
|
|
|
if (tag != null) {
|
|
|
|
TextInputState.unregisterInput(tag);
|
|
|
|
}
|
2015-03-11 21:45:49 +00:00
|
|
|
},
|
|
|
|
|
2018-01-15 03:32:33 +00:00
|
|
|
contextTypes: {
|
|
|
|
onFocusRequested: PropTypes.func,
|
|
|
|
focusEmitter: PropTypes.instanceOf(EventEmitter),
|
2015-05-29 20:16:57 +00:00
|
|
|
},
|
|
|
|
|
2016-04-09 18:12:46 +00:00
|
|
|
/**
|
2016-06-24 18:53:30 +00:00
|
|
|
* Removes all text from the `TextInput`.
|
2016-04-09 18:12:46 +00:00
|
|
|
*/
|
2015-07-24 16:34:18 +00:00
|
|
|
clear: function() {
|
|
|
|
this.setNativeProps({text: ''});
|
|
|
|
},
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
render: function() {
|
2018-05-09 07:47:46 +00:00
|
|
|
let textInput;
|
2015-03-27 18:44:43 +00:00
|
|
|
if (Platform.OS === 'ios') {
|
2018-05-09 07:47:46 +00:00
|
|
|
textInput = UIManager.RCTVirtualText
|
2018-01-15 03:32:28 +00:00
|
|
|
? this._renderIOS()
|
|
|
|
: this._renderIOSLegacy();
|
2015-03-27 18:44:43 +00:00
|
|
|
} else if (Platform.OS === 'android') {
|
2018-05-09 07:47:46 +00:00
|
|
|
textInput = this._renderAndroid();
|
2015-03-27 18:44:43 +00:00
|
|
|
}
|
2018-05-09 07:47:46 +00:00
|
|
|
return (
|
|
|
|
<TextAncestor.Provider value={true}>{textInput}</TextAncestor.Provider>
|
|
|
|
);
|
2015-03-27 18:44:43 +00:00
|
|
|
},
|
|
|
|
|
2015-07-22 21:03:32 +00:00
|
|
|
_getText: function(): ?string {
|
2018-01-15 03:32:22 +00:00
|
|
|
return typeof this.props.value === 'string'
|
|
|
|
? this.props.value
|
|
|
|
: typeof this.props.defaultValue === 'string'
|
|
|
|
? this.props.defaultValue
|
|
|
|
: '';
|
2015-07-22 21:03:32 +00:00
|
|
|
},
|
|
|
|
|
2016-08-26 00:18:05 +00:00
|
|
|
_setNativeRef: function(ref: any) {
|
|
|
|
this._inputRef = ref;
|
|
|
|
},
|
|
|
|
|
2018-01-15 03:32:28 +00:00
|
|
|
_renderIOSLegacy: function() {
|
2018-03-03 23:04:46 +00:00
|
|
|
let textContainer;
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2018-03-03 23:04:46 +00:00
|
|
|
const props = Object.assign({}, this.props);
|
2017-05-29 22:56:44 +00:00
|
|
|
props.style = [this.props.style];
|
2016-08-26 00:18:05 +00:00
|
|
|
|
|
|
|
if (props.selection && props.selection.end == null) {
|
2018-01-15 03:32:22 +00:00
|
|
|
props.selection = {
|
|
|
|
start: props.selection.start,
|
|
|
|
end: props.selection.start,
|
|
|
|
};
|
2016-08-26 00:18:05 +00:00
|
|
|
}
|
|
|
|
|
2015-06-05 15:46:17 +00:00
|
|
|
if (!props.multiline) {
|
2016-07-01 11:08:22 +00:00
|
|
|
if (__DEV__) {
|
2018-03-03 23:04:46 +00:00
|
|
|
for (const propKey in onlyMultiline) {
|
2016-07-01 11:08:22 +00:00
|
|
|
if (props[propKey]) {
|
2016-07-13 23:33:39 +00:00
|
|
|
const error = new Error(
|
2018-01-15 03:32:22 +00:00
|
|
|
'TextInput prop `' +
|
|
|
|
propKey +
|
|
|
|
'` is only supported with multiline.',
|
2016-07-01 11:08:22 +00:00
|
|
|
);
|
2016-07-13 23:33:39 +00:00
|
|
|
warning(false, '%s', error.stack);
|
2016-07-01 11:08:22 +00:00
|
|
|
}
|
2015-02-20 04:10:52 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-15 03:32:22 +00:00
|
|
|
textContainer = (
|
2017-12-20 03:48:22 +00:00
|
|
|
<RCTSinglelineTextInputView
|
2016-08-26 00:18:05 +00:00
|
|
|
ref={this._setNativeRef}
|
2015-06-05 15:46:17 +00:00
|
|
|
{...props}
|
2015-02-20 04:10:52 +00:00
|
|
|
onFocus={this._onFocus}
|
|
|
|
onBlur={this._onBlur}
|
|
|
|
onChange={this._onChange}
|
2016-08-26 00:18:05 +00:00
|
|
|
onSelectionChange={this._onSelectionChange}
|
2015-11-14 17:41:59 +00:00
|
|
|
onSelectionChangeShouldSetResponder={emptyFunction.thatReturnsTrue}
|
2015-07-22 21:03:32 +00:00
|
|
|
text={this._getText()}
|
2018-01-15 03:32:22 +00:00
|
|
|
/>
|
|
|
|
);
|
2015-02-20 04:10:52 +00:00
|
|
|
} else {
|
2018-03-03 23:04:46 +00:00
|
|
|
let children = props.children;
|
|
|
|
let childCount = 0;
|
2016-10-15 01:50:19 +00:00
|
|
|
React.Children.forEach(children, () => ++childCount);
|
2015-02-20 04:10:52 +00:00
|
|
|
invariant(
|
2015-06-05 15:46:17 +00:00
|
|
|
!(props.value && childCount),
|
2018-01-15 03:32:22 +00:00
|
|
|
'Cannot specify both value and children.',
|
2015-02-20 04:10:52 +00:00
|
|
|
);
|
2016-04-21 19:09:16 +00:00
|
|
|
if (childCount >= 1) {
|
2018-01-15 03:32:22 +00:00
|
|
|
children = (
|
2018-09-05 00:33:06 +00:00
|
|
|
<Text
|
|
|
|
style={props.style}
|
|
|
|
allowFontScaling={props.allowFontScaling}
|
|
|
|
maxFontSizeMultiplier={props.maxFontSizeMultiplier}
|
|
|
|
>
|
2018-01-15 03:32:22 +00:00
|
|
|
{children}
|
|
|
|
</Text>
|
|
|
|
);
|
2015-02-20 04:10:52 +00:00
|
|
|
}
|
2015-06-05 15:46:17 +00:00
|
|
|
if (props.inputView) {
|
|
|
|
children = [children, props.inputView];
|
2015-02-20 04:10:52 +00:00
|
|
|
}
|
2017-03-20 07:00:18 +00:00
|
|
|
props.style.unshift(styles.multilineInput);
|
2018-01-15 03:32:22 +00:00
|
|
|
textContainer = (
|
2017-12-20 03:48:22 +00:00
|
|
|
<RCTMultilineTextInputView
|
2016-08-26 00:18:05 +00:00
|
|
|
ref={this._setNativeRef}
|
2015-06-05 15:46:17 +00:00
|
|
|
{...props}
|
2015-02-20 04:10:52 +00:00
|
|
|
children={children}
|
|
|
|
onFocus={this._onFocus}
|
|
|
|
onBlur={this._onBlur}
|
|
|
|
onChange={this._onChange}
|
2017-08-15 06:46:44 +00:00
|
|
|
onContentSizeChange={this.props.onContentSizeChange}
|
2016-08-26 00:18:05 +00:00
|
|
|
onSelectionChange={this._onSelectionChange}
|
2015-02-20 04:10:52 +00:00
|
|
|
onTextInput={this._onTextInput}
|
|
|
|
onSelectionChangeShouldSetResponder={emptyFunction.thatReturnsTrue}
|
2015-07-22 21:03:32 +00:00
|
|
|
text={this._getText()}
|
2016-07-31 21:20:13 +00:00
|
|
|
dataDetectorTypes={this.props.dataDetectorTypes}
|
2016-11-22 19:52:18 +00:00
|
|
|
onScroll={this._onScroll}
|
2018-01-15 03:32:22 +00:00
|
|
|
/>
|
|
|
|
);
|
2015-02-20 04:10:52 +00:00
|
|
|
}
|
2017-12-18 22:57:38 +00:00
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
return (
|
|
|
|
<TouchableWithoutFeedback
|
2016-06-10 10:14:47 +00:00
|
|
|
onLayout={props.onLayout}
|
2015-02-20 04:10:52 +00:00
|
|
|
onPress={this._onPress}
|
2015-05-29 12:18:42 +00:00
|
|
|
rejectResponderTermination={true}
|
2016-02-04 13:12:36 +00:00
|
|
|
accessible={props.accessible}
|
|
|
|
accessibilityLabel={props.accessibilityLabel}
|
2018-07-26 06:37:16 +00:00
|
|
|
accessibilityRole={props.accessibilityRole}
|
|
|
|
accessibilityStates={props.accessibilityStates}
|
2017-04-07 18:47:35 +00:00
|
|
|
nativeID={this.props.nativeID}
|
2015-06-05 15:46:17 +00:00
|
|
|
testID={props.testID}>
|
2015-02-20 04:10:52 +00:00
|
|
|
{textContainer}
|
|
|
|
</TouchableWithoutFeedback>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2018-01-15 03:32:28 +00:00
|
|
|
_renderIOS: function() {
|
2018-03-03 23:04:46 +00:00
|
|
|
const props = Object.assign({}, this.props);
|
2018-01-15 03:32:28 +00: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-26 06:37:16 +00:00
|
|
|
accessibilityRole={props.accessibilityRole}
|
|
|
|
accessibilityStates={props.accessibilityStates}
|
2018-01-15 03:32:28 +00:00
|
|
|
nativeID={this.props.nativeID}
|
|
|
|
testID={props.testID}>
|
|
|
|
{textContainer}
|
|
|
|
</TouchableWithoutFeedback>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2015-03-27 18:44:43 +00:00
|
|
|
_renderAndroid: function() {
|
2016-08-19 14:18:03 +00:00
|
|
|
const props = Object.assign({}, this.props);
|
2017-12-18 22:57:38 +00:00
|
|
|
props.style = [this.props.style];
|
2016-08-19 14:18:03 +00:00
|
|
|
props.autoCapitalize =
|
2017-09-27 01:29:39 +00:00
|
|
|
UIManager.AndroidTextInput.Constants.AutoCapitalizationType[
|
|
|
|
props.autoCapitalize || 'sentences'
|
|
|
|
];
|
2017-08-29 21:54:33 +00:00
|
|
|
/* $FlowFixMe(>=0.53.0 site=react_native_fb,react_native_oss) This comment
|
|
|
|
* suppresses an error when upgrading Flow's support for React. To see the
|
|
|
|
* error delete this comment and run Flow. */
|
2018-03-03 23:04:46 +00:00
|
|
|
let children = this.props.children;
|
|
|
|
let childCount = 0;
|
2016-10-15 01:50:19 +00:00
|
|
|
React.Children.forEach(children, () => ++childCount);
|
2015-05-29 20:16:57 +00:00
|
|
|
invariant(
|
|
|
|
!(this.props.value && childCount),
|
2018-01-15 03:32:22 +00:00
|
|
|
'Cannot specify both value and children.',
|
2015-05-29 20:16:57 +00:00
|
|
|
);
|
|
|
|
if (childCount > 1) {
|
|
|
|
children = <Text>{children}</Text>;
|
|
|
|
}
|
2017-12-18 22:57:38 +00:00
|
|
|
|
2016-09-05 14:04:26 +00:00
|
|
|
if (props.selection && props.selection.end == null) {
|
2018-01-15 03:32:22 +00:00
|
|
|
props.selection = {
|
|
|
|
start: props.selection.start,
|
|
|
|
end: props.selection.start,
|
|
|
|
};
|
2016-09-05 14:04:26 +00:00
|
|
|
}
|
2017-12-18 22:57:38 +00:00
|
|
|
|
2018-01-15 03:32:22 +00:00
|
|
|
const textContainer = (
|
2015-03-27 18:44:43 +00:00
|
|
|
<AndroidTextInput
|
2016-08-26 00:18:05 +00:00
|
|
|
ref={this._setNativeRef}
|
2016-08-19 14:18:03 +00:00
|
|
|
{...props}
|
2015-12-14 14:41:45 +00:00
|
|
|
mostRecentEventCount={0}
|
2015-03-27 18:44:43 +00:00
|
|
|
onFocus={this._onFocus}
|
|
|
|
onBlur={this._onBlur}
|
|
|
|
onChange={this._onChange}
|
2016-08-26 00:18:05 +00:00
|
|
|
onSelectionChange={this._onSelectionChange}
|
2015-06-08 10:45:44 +00:00
|
|
|
onTextInput={this._onTextInput}
|
2015-07-22 21:03:32 +00:00
|
|
|
text={this._getText()}
|
2015-05-29 20:16:57 +00:00
|
|
|
children={children}
|
2016-11-23 14:41:53 +00:00
|
|
|
disableFullscreenUI={this.props.disableFullscreenUI}
|
2016-12-16 09:19:16 +00:00
|
|
|
textBreakStrategy={this.props.textBreakStrategy}
|
2017-02-06 15:22:09 +00:00
|
|
|
onScroll={this._onScroll}
|
2018-01-15 03:32:22 +00:00
|
|
|
/>
|
|
|
|
);
|
2015-04-08 13:54:32 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<TouchableWithoutFeedback
|
2018-02-24 08:59:22 +00:00
|
|
|
onLayout={props.onLayout}
|
2015-04-08 13:54:32 +00:00
|
|
|
onPress={this._onPress}
|
2016-02-04 13:12:36 +00:00
|
|
|
accessible={this.props.accessible}
|
|
|
|
accessibilityLabel={this.props.accessibilityLabel}
|
2018-07-26 06:37:16 +00:00
|
|
|
accessibilityRole={this.props.accessibilityRole}
|
|
|
|
accessibilityStates={this.props.accessibilityStates}
|
2017-04-07 18:47:35 +00:00
|
|
|
nativeID={this.props.nativeID}
|
2015-04-08 13:54:32 +00:00
|
|
|
testID={this.props.testID}>
|
|
|
|
{textContainer}
|
|
|
|
</TouchableWithoutFeedback>
|
2015-03-27 18:44:43 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2015-03-25 19:55:10 +00:00
|
|
|
_onFocus: function(event: Event) {
|
2015-02-20 04:10:52 +00:00
|
|
|
if (this.props.onFocus) {
|
|
|
|
this.props.onFocus(event);
|
|
|
|
}
|
2016-02-02 12:40:40 +00:00
|
|
|
|
|
|
|
if (this.props.selectionState) {
|
|
|
|
this.props.selectionState.focus();
|
|
|
|
}
|
2015-02-20 04:10:52 +00:00
|
|
|
},
|
|
|
|
|
2015-03-25 19:55:10 +00:00
|
|
|
_onPress: function(event: Event) {
|
2015-07-15 15:23:48 +00:00
|
|
|
if (this.props.editable || this.props.editable === undefined) {
|
|
|
|
this.focus();
|
|
|
|
}
|
2015-02-20 04:10:52 +00:00
|
|
|
},
|
|
|
|
|
2015-03-25 19:55:10 +00:00
|
|
|
_onChange: function(event: Event) {
|
2015-12-14 14:41:45 +00:00
|
|
|
// Make sure to fire the mostRecentEventCount first so it is already set on
|
|
|
|
// native when the text value is set.
|
2017-01-21 00:41:22 +00:00
|
|
|
if (this._inputRef) {
|
|
|
|
this._inputRef.setNativeProps({
|
|
|
|
mostRecentEventCount: event.nativeEvent.eventCount,
|
|
|
|
});
|
|
|
|
}
|
2015-12-14 14:41:45 +00:00
|
|
|
|
2018-03-03 23:04:46 +00:00
|
|
|
const text = event.nativeEvent.text;
|
2015-02-20 04:10:52 +00:00
|
|
|
this.props.onChange && this.props.onChange(event);
|
2015-07-21 19:37:24 +00:00
|
|
|
this.props.onChangeText && this.props.onChangeText(text);
|
2015-12-14 14:41:45 +00:00
|
|
|
|
2016-08-26 00:18:05 +00:00
|
|
|
if (!this._inputRef) {
|
2015-12-16 01:31:07 +00:00
|
|
|
// calling `this.props.onChange` or `this.props.onChangeText`
|
|
|
|
// may clean up the input itself. Exits here.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-26 14:20:50 +00:00
|
|
|
this._lastNativeText = text;
|
|
|
|
this.forceUpdate();
|
|
|
|
},
|
|
|
|
|
2016-08-26 00:18:05 +00:00
|
|
|
_onSelectionChange: function(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();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-01-15 03:32:22 +00:00
|
|
|
componentDidUpdate: function() {
|
2015-12-14 14:41:45 +00: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-26 00:18:05 +00:00
|
|
|
const nativeProps = {};
|
|
|
|
|
2018-01-15 03:32:22 +00:00
|
|
|
if (
|
|
|
|
this._lastNativeText !== this.props.value &&
|
|
|
|
typeof this.props.value === 'string'
|
|
|
|
) {
|
2016-08-26 00:18:05 +00: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-15 03:32:22 +00:00
|
|
|
if (
|
|
|
|
this._lastNativeSelection &&
|
|
|
|
selection &&
|
|
|
|
(this._lastNativeSelection.start !== selection.start ||
|
|
|
|
this._lastNativeSelection.end !== selection.end)
|
|
|
|
) {
|
2016-08-26 00:18:05 +00:00
|
|
|
nativeProps.selection = this.props.selection;
|
|
|
|
}
|
|
|
|
|
2017-01-21 00:41:22 +00:00
|
|
|
if (Object.keys(nativeProps).length > 0 && this._inputRef) {
|
2016-08-26 00:18:05 +00:00
|
|
|
this._inputRef.setNativeProps(nativeProps);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.props.selectionState && selection) {
|
|
|
|
this.props.selectionState.update(selection.start, selection.end);
|
2015-12-14 14:41:45 +00:00
|
|
|
}
|
2015-02-20 04:10:52 +00:00
|
|
|
},
|
|
|
|
|
2015-03-25 19:55:10 +00:00
|
|
|
_onBlur: function(event: Event) {
|
2015-02-20 04:10:52 +00:00
|
|
|
this.blur();
|
|
|
|
if (this.props.onBlur) {
|
|
|
|
this.props.onBlur(event);
|
|
|
|
}
|
2016-02-02 12:40:40 +00:00
|
|
|
|
|
|
|
if (this.props.selectionState) {
|
|
|
|
this.props.selectionState.blur();
|
|
|
|
}
|
2015-02-20 04:10:52 +00:00
|
|
|
},
|
|
|
|
|
2015-03-25 19:55:10 +00:00
|
|
|
_onTextInput: function(event: Event) {
|
2015-02-20 04:10:52 +00:00
|
|
|
this.props.onTextInput && this.props.onTextInput(event);
|
|
|
|
},
|
2016-11-22 19:52:18 +00:00
|
|
|
|
|
|
|
_onScroll: function(event: Event) {
|
|
|
|
this.props.onScroll && this.props.onScroll(event);
|
|
|
|
},
|
2015-02-20 04:10:52 +00:00
|
|
|
});
|
|
|
|
|
2018-05-14 07:08:58 +00:00
|
|
|
class InternalTextInputType extends ReactNative.NativeComponent<Props> {
|
|
|
|
clear() {}
|
|
|
|
|
|
|
|
// $FlowFixMe
|
|
|
|
isFocused(): boolean {}
|
|
|
|
}
|
|
|
|
|
|
|
|
const TypedTextInput = ((TextInput: any): Class<InternalTextInputType>);
|
|
|
|
|
2018-03-03 23:04:46 +00:00
|
|
|
const styles = StyleSheet.create({
|
2017-03-20 07:00:18 +00:00
|
|
|
multilineInput: {
|
2017-12-20 03:48:22 +00:00
|
|
|
// This default top inset makes RCTMultilineTextInputView seem as close as possible
|
|
|
|
// to single-line RCTSinglelineTextInputView defaults, using the system defaults
|
2017-03-20 07:00:18 +00:00
|
|
|
// of font size 17 and a height of 31 points.
|
|
|
|
paddingTop: 5,
|
|
|
|
},
|
2015-02-20 04:10:52 +00:00
|
|
|
});
|
|
|
|
|
2018-05-14 07:08:58 +00:00
|
|
|
module.exports = TypedTextInput;
|