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

Reintroduce animated input for Markdown composer #35973

Merged
4 changes: 2 additions & 2 deletions src/components/Composer/index.native.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {MarkdownTextInput} from '@expensify/react-native-live-markdown';
import type {ForwardedRef} from 'react';
import React, {useCallback, useEffect, useMemo, useRef} from 'react';
import type {TextInput} from 'react-native';
import {StyleSheet} from 'react-native';
import type {AnimatedTextInputRef} from '@components/RNTextInput';
import type {AnimatedTextInputRef} from '@components/RNMarkdownTextInput';
import MarkdownTextInput from '@components/RNMarkdownTextInput';
import useMarkdownStyle from '@hooks/useMarkdownStyle';
robertKozik marked this conversation as resolved.
Show resolved Hide resolved
import useResetComposerFocus from '@hooks/useResetComposerFocus';
import useStyleUtils from '@hooks/useStyleUtils';
Expand Down
37 changes: 37 additions & 0 deletions src/components/RNMarkdownTextInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type {MarkdownTextInputProps} from '@expensify/react-native-live-markdown';
import {MarkdownTextInput} from '@expensify/react-native-live-markdown';
import type {ForwardedRef} from 'react';
import React from 'react';
import type {TextInput} from 'react-native';
import Animated from 'react-native-reanimated';
import useTheme from '@hooks/useTheme';

// Convert the underlying TextInput into an Animated component so that we can take an animated ref and pass it to a worklet
const AnimatedTextInput = Animated.createAnimatedComponent(MarkdownTextInput);
robertKozik marked this conversation as resolved.
Show resolved Hide resolved

type AnimatedTextInputRef = typeof AnimatedTextInput & TextInput & HTMLInputElement;
robertKozik marked this conversation as resolved.
Show resolved Hide resolved

function RNMarkdownTextInput(props: MarkdownTextInputProps, ref: ForwardedRef<AnimatedTextInputRef>) {
robertKozik marked this conversation as resolved.
Show resolved Hide resolved
const theme = useTheme();

return (
<AnimatedTextInput
robertKozik marked this conversation as resolved.
Show resolved Hide resolved
allowFontScaling={false}
textBreakStrategy="simple"
keyboardAppearance={theme.colorScheme}
ref={(refHandle) => {
if (typeof ref !== 'function') {
return;
}
ref(refHandle as AnimatedTextInputRef);
}}
// eslint-disable-next-line
{...props}
/>
);
}

RNMarkdownTextInput.displayName = 'RNTextInputWithRef';
robertKozik marked this conversation as resolved.
Show resolved Hide resolved

export default React.forwardRef(RNMarkdownTextInput);
robertKozik marked this conversation as resolved.
Show resolved Hide resolved
export type {AnimatedTextInputRef};
Loading