Skip to content
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 Composer to TypeScript #31912

Merged
merged 22 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f1c060b
migrate index.ios.tsx to TypeScript
JKobrynski Nov 22, 2023
32f4140
migrate index.android.js to TypeScript
JKobrynski Nov 22, 2023
ef6cbd6
start migrating index.js
JKobrynski Nov 24, 2023
bc23a01
fix forwarded ref
JKobrynski Nov 24, 2023
3b27bf8
Fixes in refs and events
fabioh8010 Nov 24, 2023
0a02f93
remove unsupported multiline prop
JKobrynski Nov 27, 2023
dc94cd7
remove mutliline prop
JKobrynski Nov 27, 2023
2aac63a
Merge branch 'main' into migrateComposerToTypeScript
JKobrynski Nov 27, 2023
000fc54
cleanup the code
JKobrynski Nov 27, 2023
205469a
apply suggested improvements
JKobrynski Nov 28, 2023
d70b49d
apply improvements, unify ComposerProps type
JKobrynski Nov 28, 2023
da409ec
Merge branch 'main' into migrateComposerToTypeScript
JKobrynski Nov 30, 2023
c8ec585
Merge branch 'main' into migrateComposerToTypeScript
JKobrynski Nov 30, 2023
235f9a3
Merge branch 'main' into migrateComposerToTypeScript
JKobrynski Dec 1, 2023
76ac410
Merge branch 'main' into migrateComposerToTypeScript
JKobrynski Dec 4, 2023
40de00c
remove ref from if statement
JKobrynski Dec 5, 2023
76c7334
add optional chaining to onFocus call
JKobrynski Dec 5, 2023
5370049
Merge branch 'main' into migrateComposerToTypeScript
JKobrynski Dec 7, 2023
49e358c
Merge branch 'main' into migrateComposerToTypeScript
JKobrynski Dec 8, 2023
0a91ea7
move selection destructuring to the top
JKobrynski Dec 11, 2023
4114784
Merge branch 'main' into migrateComposerToTypeScript
JKobrynski Dec 14, 2023
1c26c3e
change variable names
JKobrynski Dec 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 4 additions & 37 deletions src/components/Composer/index.android.tsx
Original file line number Diff line number Diff line change
@@ -1,42 +1,9 @@
import React, {ForwardedRef, useCallback, useEffect, useMemo, useRef} from 'react';
import {StyleProp, StyleSheet, TextInput, TextStyle} from 'react-native';
import {StyleSheet, TextInput} from 'react-native';
import RNTextInput from '@components/RNTextInput';
import * as ComposerUtils from '@libs/ComposerUtils';
import themeColors from '@styles/themes/default';
import {TextSelection} from './types';

type ComposerProps = {
/** Maximum number of lines in the text input */
maxLines: number;

/** If the input should clear, it actually gets intercepted instead of .clear() */
shouldClear: boolean;

/** When the input has cleared whoever owns this input should know about it */
onClear: () => void;

/** Set focus to this component the first time it renders.
* Override this in case you need to set focus on one field out of many, or when you want to disable autoFocus */
autoFocus: boolean;

/** Prevent edits and interactions like focus for this input. */
isDisabled: boolean;

/** Selection Object */
selection: TextSelection;

/** Whether the full composer can be opened */
isFullComposerAvailable: boolean;

/** Allow the full composer to be opened */
setIsFullComposerAvailable: () => void;

/** Whether the composer is full size */
isComposerFullSize: boolean;

/** General styles to apply to the text input */
style: StyleProp<TextStyle>;
};
import {ComposerProps} from './types';

function Composer(
{
Expand All @@ -57,7 +24,7 @@ function Composer(
}: ComposerProps,
ref: ForwardedRef<TextInput>,
) {
const textInput = useRef<TextInput>();
const textInput = useRef<TextInput | null>(null);
JKobrynski marked this conversation as resolved.
Show resolved Hide resolved

/**
* Set the TextInput Ref
Expand Down Expand Up @@ -110,12 +77,12 @@ function Composer(
maxNumberOfLines={maxNumberOfLines}
textAlignVertical="center"
style={[composerStyles]}
readOnly={isDisabled}
autoFocus={autoFocus}
selection={selection}
isFullComposerAvailable={isFullComposerAvailable}
/* eslint-disable-next-line react/jsx-props-no-spreading */
{...props}
readOnly={isDisabled}
/>
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Composer/index.ios.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function Composer(
}: ComposerProps,
ref: ForwardedRef<TextInput>,
) {
const textInput = useRef<TextInput>();
const textInput = useRef<TextInput | null>(null);

const styles = useThemeStyles();
const themeColors = useTheme();
Expand Down Expand Up @@ -78,11 +78,11 @@ function Composer(
smartInsertDelete={false}
style={[composerStyles, styles.verticalAlignMiddle]}
maxNumberOfLines={maxNumberOfLines}
readOnly={isDisabled}
autoFocus={autoFocus}
isFullComposerAvailable={isFullComposerAvailable}
/* eslint-disable-next-line react/jsx-props-no-spreading */
{...propsToPass}
JKobrynski marked this conversation as resolved.
Show resolved Hide resolved
readOnly={isDisabled}
/>
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Composer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function Composer(
const {windowWidth} = useWindowDimensions();
const navigation = useNavigation();
const textRef = useRef<HTMLElement & RNText>(null);
const textInput = useRef<HTMLTextAreaElement & TextInput>();
const textInput = useRef<(HTMLTextAreaElement & TextInput) | null>(null);
JKobrynski marked this conversation as resolved.
Show resolved Hide resolved
const initialValue = defaultValue ? `${defaultValue}` : `${value ?? ''}`;
const [numberOfLines, setNumberOfLines] = useState(numberOfLinesProp);
const [selection, setSelection] = useState<
Expand Down Expand Up @@ -118,7 +118,7 @@ function Composer(
useEffect(() => {
setSelection((prevSelection) => {
if (!!prevSelection && selectionProp.start === prevSelection.start && selectionProp.end === prevSelection.end) {
return prevSelection;
return;
}
return selectionProp;
});
Expand Down
2 changes: 1 addition & 1 deletion src/components/Composer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type ComposerProps = {
isFullComposerAvailable?: boolean;

/** Allow the full composer to be opened */
setIsFullComposerAvailable?: () => void;
setIsFullComposerAvailable?: (value: boolean) => void;

/** Should we calculate the caret position */
shouldCalculateCaretPosition?: boolean;
Expand Down
9 changes: 0 additions & 9 deletions src/libs/ComposerUtils/types.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/libs/ComposerUtils/updateIsFullComposerAvailable.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ComposerProps} from '@components/Composer/types';
import CONST from '@src/CONST';
import ComposerProps from './types';

/**
* Update isFullComposerAvailable if needed
Expand All @@ -8,7 +8,7 @@ import ComposerProps from './types';
function updateIsFullComposerAvailable(props: ComposerProps, numberOfLines: number) {
const isFullComposerAvailable = numberOfLines >= CONST.COMPOSER.FULL_COMPOSER_MIN_LINES;
if (isFullComposerAvailable !== props.isFullComposerAvailable) {
props.setIsFullComposerAvailable(isFullComposerAvailable);
props.setIsFullComposerAvailable?.(isFullComposerAvailable);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/libs/ComposerUtils/updateNumberOfLines/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {NativeSyntheticEvent, TextInputContentSizeChangeEventData} from 'react-native';
import ComposerProps from '@libs/ComposerUtils/types';
import {ComposerProps} from '@components/Composer/types';

type UpdateNumberOfLines = (props: ComposerProps, event: NativeSyntheticEvent<TextInputContentSizeChangeEventData>) => void;

Expand Down
1 change: 1 addition & 0 deletions src/types/modules/react-native.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ declare module 'react-native' {
readOnly?: boolean;
}
interface TextInputProps extends WebTextInputProps {
// TODO: remove once the app is updated to RN 0.73
smartInsertDelete?: boolean;
JKobrynski marked this conversation as resolved.
Show resolved Hide resolved
isFullComposerAvailable?: boolean;
}
Expand Down
Loading