-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TS migration] Migrate 'TextInput' component to TypeScript #31356
Changes from all commits
326e443
61fd846
255058f
0e5fe98
b573de9
b568d32
e90c503
6a3a270
aaaeac0
5b562b7
bddaeb2
2bcc1c7
4bc71cd
bbe0c5d
1f5cac7
fc794e3
052610c
0b22b3b
cd39877
c8fa81e
12f6197
b48cee2
f327d28
b4597cb
3abace7
11bf2ef
cba69d0
886aa60
ac1564e
e596427
d69e087
aad9c1d
fa251df
648100c
ccd8f60
31ad5b6
ee63669
c02470c
b6ba4e1
2632af4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import React from 'react'; | ||
import type {Component, ForwardedRef} from 'react'; | ||
import type {GestureResponderEvent, StyleProp, TextInputProps, TextStyle, ViewStyle} from 'react-native'; | ||
import type {AnimatedProps} from 'react-native-reanimated'; | ||
import type {SrcProps} from '@components/Icon'; | ||
import type {MaybePhraseKey} from '@libs/Localize'; | ||
|
||
type CustomBaseTextInputProps = { | ||
/** Input label */ | ||
label?: string; | ||
|
||
/** Name attribute for the input */ | ||
name?: string; | ||
|
||
/** Input value */ | ||
value?: string; | ||
|
||
/** Default value - used for non controlled inputs */ | ||
defaultValue?: string; | ||
|
||
/** Input value placeholder */ | ||
placeholder?: string; | ||
|
||
/** Error text to display */ | ||
errorText?: MaybePhraseKey; | ||
|
||
/** Icon to display in right side of text input */ | ||
icon: ((props: SrcProps) => React.ReactNode) | null; | ||
|
||
/** Customize the TextInput container */ | ||
textInputContainerStyles?: StyleProp<ViewStyle>; | ||
|
||
/** Customize the main container */ | ||
containerStyles?: StyleProp<ViewStyle>; | ||
|
||
/** input style */ | ||
inputStyle?: StyleProp<TextStyle>; | ||
|
||
/** If present, this prop forces the label to remain in a position where it will not collide with input text */ | ||
forceActiveLabel?: boolean; | ||
|
||
/** Should the input auto focus? */ | ||
autoFocus?: boolean; | ||
|
||
/** Disable the virtual keyboard */ | ||
disableKeyboard?: boolean; | ||
|
||
/** | ||
* Autogrow input container length based on the entered text. | ||
* Note: If you use this prop, the text input has to be controlled | ||
* by a value prop. | ||
*/ | ||
autoGrow?: boolean; | ||
|
||
/** | ||
* Autogrow input container height based on the entered text | ||
* Note: If you use this prop, the text input has to be controlled | ||
* by a value prop. | ||
*/ | ||
autoGrowHeight?: boolean; | ||
|
||
/** Hide the focus styles on TextInput */ | ||
hideFocusedState?: boolean; | ||
|
||
/** Hint text to display below the TextInput */ | ||
hint?: string; | ||
|
||
/** Prefix character */ | ||
prefixCharacter?: string; | ||
|
||
/** Whether autoCorrect functionality should enable */ | ||
autoCorrect?: boolean; | ||
|
||
/** Form props */ | ||
/** The ID used to uniquely identify the input in a Form */ | ||
inputID?: string; | ||
|
||
/** Saves a draft of the input value when used in a form */ | ||
shouldSaveDraft?: boolean; | ||
|
||
/** Callback to update the value on Form when input is used in the Form component. */ | ||
onInputChange?: (value: string) => void; | ||
|
||
/** Whether we should wait before focusing the TextInput, useful when using transitions */ | ||
shouldDelayFocus?: boolean; | ||
|
||
/** Indicate whether pressing Enter on multiline input is allowed to submit the form. */ | ||
submitOnEnter?: boolean; | ||
|
||
/** Indicate whether input is multiline */ | ||
multiline?: boolean; | ||
|
||
/** Set the default value to the input if there is a valid saved value */ | ||
shouldUseDefaultValue?: boolean; | ||
|
||
/** Indicate whether or not the input should prevent swipe actions in tabs */ | ||
shouldInterceptSwipe?: boolean; | ||
|
||
/** Should there be an error displayed */ | ||
hasError?: boolean; | ||
|
||
/** On Press handler */ | ||
onPress?: (event: GestureResponderEvent | KeyboardEvent) => void; | ||
|
||
/** Should loading state should be displayed */ | ||
isLoading?: boolean; | ||
|
||
/** Type of autocomplete */ | ||
autoCompleteType?: string; | ||
}; | ||
|
||
type BaseTextInputRef = ForwardedRef<HTMLFormElement | Component<AnimatedProps<TextInputProps>>>; | ||
|
||
type BaseTextInputProps = CustomBaseTextInputProps & TextInputProps; | ||
|
||
export type {CustomBaseTextInputProps, BaseTextInputRef, BaseTextInputProps}; |
This file was deleted.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NAB - most prop descriptions in this file are pretty weak / not descriptive. Maybe they came from somewhere else in the codebase (a.k.a. weren't added new here?) but it would be best to try to make them as clear as possible... Probably in a follow-up PR |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import {Animated} from 'react-native'; | ||
|
||
type TextInputLabelProps = { | ||
/** Label */ | ||
label: string; | ||
|
||
/** Label vertical translate */ | ||
labelTranslateY: Animated.Value; | ||
|
||
/** Label scale */ | ||
labelScale: Animated.Value; | ||
|
||
/** Whether the label is currently active or not */ | ||
isLabelActive: boolean; | ||
|
||
/** For attribute for label */ | ||
for?: string; | ||
}; | ||
|
||
export default TextInputLabelProps; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,11 @@ import React, {forwardRef, useEffect} from 'react'; | |
import {AppState, Keyboard} from 'react-native'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import BaseTextInput from './BaseTextInput'; | ||
import * as baseTextInputPropTypes from './BaseTextInput/baseTextInputPropTypes'; | ||
import type {BaseTextInputProps, BaseTextInputRef} from './BaseTextInput/types'; | ||
|
||
const TextInput = forwardRef((props, ref) => { | ||
function TextInput(props: BaseTextInputProps, ref: BaseTextInputRef) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NAB - Question: Why aren't we destructuring |
||
const styles = useThemeStyles(); | ||
|
||
useEffect(() => { | ||
if (!props.disableKeyboard) { | ||
return; | ||
|
@@ -30,15 +31,13 @@ const TextInput = forwardRef((props, ref) => { | |
{...props} | ||
// Setting autoCompleteType to new-password throws an error on Android/iOS, so fall back to password in that case | ||
// eslint-disable-next-line react/jsx-props-no-multi-spaces | ||
ref={ref} | ||
autoCompleteType={props.autoCompleteType === 'new-password' ? 'password' : props.autoCompleteType} | ||
innerRef={ref} | ||
inputStyle={[styles.baseTextInput, ...props.inputStyle]} | ||
inputStyle={[styles.baseTextInput, props.inputStyle]} | ||
/> | ||
); | ||
}); | ||
} | ||
|
||
TextInput.propTypes = baseTextInputPropTypes.propTypes; | ||
TextInput.defaultProps = baseTextInputPropTypes.defaultProps; | ||
TextInput.displayName = 'TextInput'; | ||
|
||
export default TextInput; | ||
export default forwardRef(TextInput); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super NAB - can we use
AnimatedTextInputRef
here like this?