Skip to content

Commit

Permalink
fix: adjust MarkdownTextInput ref type (#523)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheKohan authored Oct 18, 2024
1 parent b753c7a commit f171853
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 1 addition & 3 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as React from 'react';
import {Button, StyleSheet, Text, View} from 'react-native';
import {MarkdownTextInput} from '@expensify/react-native-live-markdown';
import type {TextInput} from 'react-native';
import * as TEST_CONST from './testConstants';
import {PlatformInfo} from './PlatformInfo';

Expand Down Expand Up @@ -31,8 +30,7 @@ export default function App() {
};
}, [emojiFontSizeState, linkColorState]);

// TODO: use MarkdownTextInput ref instead of TextInput ref
const ref = React.useRef<TextInput>(null);
const ref = React.useRef<MarkdownTextInput>(null);

return (
<View style={styles.container}>
Expand Down
4 changes: 3 additions & 1 deletion src/MarkdownTextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ interface MarkdownTextInputProps extends TextInputProps, InlineImagesInputProps
markdownStyle?: PartialMarkdownStyle;
}

type MarkdownTextInput = TextInput & React.Component<MarkdownTextInputProps>;

function processColorsInMarkdownStyle(input: MarkdownStyle): MarkdownStyle {
const output = JSON.parse(JSON.stringify(input));

Expand All @@ -37,7 +39,7 @@ function processMarkdownStyle(input: PartialMarkdownStyle | undefined): Markdown
return processColorsInMarkdownStyle(mergeMarkdownStyleWithDefault(input));
}

const MarkdownTextInput = React.forwardRef<TextInput, MarkdownTextInputProps>((props, ref) => {
const MarkdownTextInput = React.forwardRef<MarkdownTextInput, MarkdownTextInputProps>((props, ref) => {
const IS_FABRIC = 'nativeFabricUIManager' in global;

const markdownStyle = React.useMemo(() => processMarkdownStyle(props.markdownStyle), [props.markdownStyle]);
Expand Down
4 changes: 3 additions & 1 deletion src/MarkdownTextInput.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ interface MarkdownNativeEvent extends Event {
inputType: string;
}

type MarkdownTextInput = TextInput & React.Component<MarkdownTextInputProps>;

type Selection = {
start: number;
end: number;
Expand Down Expand Up @@ -68,7 +70,7 @@ type HTMLMarkdownElement = HTMLElement & {
value: string;
};

const MarkdownTextInput = React.forwardRef<TextInput, MarkdownTextInputProps>(
const MarkdownTextInput = React.forwardRef<MarkdownTextInput, MarkdownTextInputProps>(
(
{
accessibilityLabel,
Expand Down

0 comments on commit f171853

Please sign in to comment.