Become compatible with Flow's TypesFirst

Summary:
When the TextInput class is exported directly Flow complains about some definitions because they don't properly define the export type. This change adds those types but still doesn't export the TextInput directly as there are more things that still need to get fixed.

Changelog:
[Internal]

Reviewed By: JoshuaGross

Differential Revision: D18444096

fbshipit-source-id: 18c88bbf1de5504f350681a71ea21d7e41876e49
This commit is contained in:
Eli White
2019-11-15 14:02:42 -08:00
committed by Facebook Github Bot
parent 8f601418ab
commit 99dc4e204e
+28 -14
View File
@@ -678,6 +678,18 @@ export type Props = $ReadOnly<{|
contextMenuHidden?: ?boolean,
|}>;
type DefaultProps = $ReadOnly<{|
allowFontScaling: boolean,
rejectResponderTermination: boolean,
underlineColorAndroid: 'transparent',
|}>;
type State = {|
currentlyFocusedField: typeof TextInputState.currentlyFocusedField,
focusTextInput: typeof TextInputState.focusTextInput,
blurTextInput: typeof TextInputState.blurTextInput,
|};
const emptyFunctionThatReturnsTrue = () => true;
/**
@@ -791,8 +803,8 @@ const emptyFunctionThatReturnsTrue = () => true;
* or control this param programmatically with native code.
*
*/
class TextInput extends React.Component<Props> {
static defaultProps = {
class TextInput extends React.Component<Props, State> {
static defaultProps: DefaultProps = {
allowFontScaling: true,
rejectResponderTermination: true,
underlineColorAndroid: 'transparent',
@@ -800,7 +812,7 @@ class TextInput extends React.Component<Props> {
static propTypes = DeprecatedTextInputPropTypes;
static State = {
static State: State = {
currentlyFocusedField: TextInputState.currentlyFocusedField,
focusTextInput: TextInputState.focusTextInput,
blurTextInput: TextInputState.blurTextInput,
@@ -876,52 +888,54 @@ class TextInput extends React.Component<Props> {
/**
* Removes all text from the `TextInput`.
*/
clear = () => {
clear: () => void = () => {
this.setNativeProps({text: ''});
};
/**
* Returns `true` if the input is currently focused; `false` otherwise.
*/
isFocused = (): boolean => {
isFocused: () => boolean = () => {
return (
TextInputState.currentlyFocusedField() ===
ReactNative.findNodeHandle(this._inputRef)
);
};
getNativeRef = (): ?React.ElementRef<HostComponent<mixed>> => {
getNativeRef: () => ?React.ElementRef<HostComponent<mixed>> = () => {
return this._inputRef;
};
// From NativeMethodsMixin
// We need these instead of using forwardRef because we also have the other
// methods we expose
blur = () => {
blur: () => void = () => {
this._inputRef && this._inputRef.blur();
};
focus = () => {
focus: () => void = () => {
this._inputRef && this._inputRef.focus();
};
measure = (callback: MeasureOnSuccessCallback) => {
measure: (callback: MeasureOnSuccessCallback) => void = callback => {
this._inputRef && this._inputRef.measure(callback);
};
measureInWindow = (callback: MeasureInWindowOnSuccessCallback) => {
measureInWindow: (
callback: MeasureInWindowOnSuccessCallback,
) => void = callback => {
this._inputRef && this._inputRef.measureInWindow(callback);
};
measureLayout = (
measureLayout: (
relativeToNativeNode: number | React.ElementRef<HostComponent<mixed>>,
onSuccess: MeasureLayoutOnSuccessCallback,
onFail?: () => void,
) => {
) => void = (relativeToNativeNode, onSuccess, onFail) => {
this._inputRef &&
this._inputRef.measureLayout(relativeToNativeNode, onSuccess, onFail);
};
setNativeProps = (nativeProps: Object) => {
setNativeProps: (nativeProps: Object) => void = nativeProps => {
this._inputRef && this._inputRef.setNativeProps(nativeProps);
};
render() {
render(): React.Node {
let textInput = null;
let additionalTouchableProps: {|
rejectResponderTermination?: $PropertyType<