-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35973 from software-mansion-labs/animated-markdow…
…n-input Reintroduce animated input for Markdown composer
- Loading branch information
Showing
2 changed files
with
42 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 AnimatedMarkdownTextInput = Animated.createAnimatedComponent(MarkdownTextInput); | ||
|
||
type AnimatedMarkdownTextInputRef = typeof AnimatedMarkdownTextInput & TextInput & HTMLInputElement; | ||
|
||
function RNMarkdownTextInputWithRef(props: MarkdownTextInputProps, ref: ForwardedRef<AnimatedMarkdownTextInputRef>) { | ||
const theme = useTheme(); | ||
|
||
return ( | ||
<AnimatedMarkdownTextInput | ||
allowFontScaling={false} | ||
textBreakStrategy="simple" | ||
keyboardAppearance={theme.colorScheme} | ||
ref={(refHandle) => { | ||
if (typeof ref !== 'function') { | ||
return; | ||
} | ||
ref(refHandle as AnimatedMarkdownTextInputRef); | ||
}} | ||
// eslint-disable-next-line | ||
{...props} | ||
/> | ||
); | ||
} | ||
|
||
RNMarkdownTextInputWithRef.displayName = 'RNTextInputWithRef'; | ||
|
||
export default React.forwardRef(RNMarkdownTextInputWithRef); | ||
export type {AnimatedMarkdownTextInputRef}; |