mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-05-01 14:25:08 +08:00
TextInput: Remove PropTypes, NativeMethodsMixin; Convert to ES6 class (#21885)
Summary: This pull requests converts `TextInput` to an ES6 class, and in the process removes its usage of `prop-types` and `NativeMethodsMixin`. The code (and some relevant types) for the native components have been moved to `TextInputNativeComponent.js`. The rest of the flow proptypes have been moved to `TextInputTypes.js`. Pull Request resolved: https://github.com/facebook/react-native/pull/21885 Reviewed By: RSNara Differential Revision: D10515754 Pulled By: TheSavior fbshipit-source-id: 5cfb25344385904b37a49582008c2a4b46db809d
This commit is contained in:
committed by
Facebook Github Bot
parent
e57ad4ee37
commit
70e9e2665b
64
Libraries/Components/TextInput/TextInputNativeComponent.js
Normal file
64
Libraries/Components/TextInput/TextInputNativeComponent.js
Normal file
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @flow
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const Platform = require('Platform');
|
||||
const ReactNative = require('ReactNative');
|
||||
|
||||
const requireNativeComponent = require('requireNativeComponent');
|
||||
|
||||
import type {Props} from 'TextInputTypes';
|
||||
|
||||
let AndroidTextInput = null;
|
||||
let RCTMultilineTextInputView = null;
|
||||
let RCTSinglelineTextInputView = null;
|
||||
|
||||
if (Platform.OS === 'android') {
|
||||
AndroidTextInput = requireNativeComponent('AndroidTextInput');
|
||||
} else if (Platform.OS === 'ios') {
|
||||
RCTMultilineTextInputView = requireNativeComponent(
|
||||
'RCTMultilineTextInputView',
|
||||
);
|
||||
RCTSinglelineTextInputView = requireNativeComponent(
|
||||
'RCTSinglelineTextInputView',
|
||||
);
|
||||
}
|
||||
|
||||
type NativeProps = $ReadOnly<{|
|
||||
...Props,
|
||||
text?: ?string,
|
||||
onSelectionChangeShouldSetResponder?: ?() => boolean,
|
||||
mostRecentEventCount?: ?number,
|
||||
|}>;
|
||||
|
||||
declare class TextInputType extends ReactNative.NativeComponent<NativeProps> {
|
||||
/**
|
||||
* Removes all text from the `TextInput`.
|
||||
*/
|
||||
clear(): mixed;
|
||||
|
||||
/**
|
||||
* Returns `true` if the input is currently focused; `false` otherwise.
|
||||
*/
|
||||
isFocused(): boolean;
|
||||
}
|
||||
|
||||
export type {TextInputType};
|
||||
|
||||
module.exports = {
|
||||
AndroidTextInput: ((AndroidTextInput: any): Class<TextInputType>),
|
||||
RCTMultilineTextInputView: ((RCTMultilineTextInputView: any): Class<
|
||||
TextInputType,
|
||||
>),
|
||||
RCTSinglelineTextInputView: ((RCTSinglelineTextInputView: any): Class<
|
||||
TextInputType,
|
||||
>),
|
||||
};
|
||||
Reference in New Issue
Block a user