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 all commits
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
147 changes: 0 additions & 147 deletions src/components/Composer/index.android.js

This file was deleted.

96 changes: 96 additions & 0 deletions src/components/Composer/index.android.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import React, {ForwardedRef, useCallback, useEffect, useMemo, useRef} from 'react';
import {StyleSheet, TextInput} from 'react-native';
import RNTextInput from '@components/RNTextInput';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import * as ComposerUtils from '@libs/ComposerUtils';
import {ComposerProps} from './types';

function Composer(
{
shouldClear = false,
onClear = () => {},
isDisabled = false,
maxLines,
isComposerFullSize = false,
setIsFullComposerAvailable = () => {},
style,
autoFocus = false,
selection = {
start: 0,
end: 0,
},
isFullComposerAvailable = false,
...props
}: ComposerProps,
ref: ForwardedRef<TextInput>,
) {
const textInput = useRef<TextInput | null>(null);
JKobrynski marked this conversation as resolved.
Show resolved Hide resolved

const styles = useThemeStyles();
const theme = useTheme();

/**
* Set the TextInput Ref
*/
const setTextInputRef = useCallback((el: TextInput) => {
textInput.current = el;
if (typeof ref !== 'function' || textInput.current === null) {
return;
}

// This callback prop is used by the parent component using the constructor to
// get a ref to the inner textInput element e.g. if we do
// <constructor ref={el => this.textInput = el} /> this will not
// return a ref to the component, but rather the HTML element by default
ref(textInput.current);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

useEffect(() => {
if (!shouldClear) {
return;
}
textInput.current?.clear();
onClear();
}, [shouldClear, onClear]);

/**
* Set maximum number of lines
*/
const maxNumberOfLines = useMemo(() => {
if (isComposerFullSize) {
return 1000000;
}
return maxLines;
}, [isComposerFullSize, maxLines]);

const composerStyles = useMemo(() => StyleSheet.flatten(style), [style]);
JKobrynski marked this conversation as resolved.
Show resolved Hide resolved

return (
<RNTextInput
autoComplete="off"
placeholderTextColor={theme.placeholderText}
ref={setTextInputRef}
onContentSizeChange={(e) => ComposerUtils.updateNumberOfLines({maxLines, isComposerFullSize, isDisabled, setIsFullComposerAvailable}, e, styles)}
rejectResponderTermination={false}
// Setting a really high number here fixes an issue with the `maxNumberOfLines` prop on TextInput, where on Android the text input would collapse to only one line,
// when it should actually expand to the container (https://github.com/Expensify/App/issues/11694#issuecomment-1560520670)
// @Szymon20000 is working on fixing this (android-only) issue in the in the upstream PR (https://github.com/facebook/react-native/pulls?q=is%3Apr+is%3Aopen+maxNumberOfLines)
// TODO: remove this comment once upstream PR is merged and available in a future release
maxNumberOfLines={maxNumberOfLines}
textAlignVertical="center"
style={[composerStyles]}
autoFocus={autoFocus}
selection={selection}
isFullComposerAvailable={isFullComposerAvailable}
/* eslint-disable-next-line react/jsx-props-no-spreading */
{...props}
readOnly={isDisabled}
/>
);
}

Composer.displayName = 'Composer';

export default React.forwardRef(Composer);
147 changes: 0 additions & 147 deletions src/components/Composer/index.ios.js

This file was deleted.

Loading
Loading