diff --git a/src/components/mentions.tsx b/src/components/mentions.tsx index 47a5c71..15e911d 100644 --- a/src/components/mentions.tsx +++ b/src/components/mentions.tsx @@ -1,4 +1,4 @@ -import React, { FC, useMemo, useRef, useState } from 'react'; +import React, { FC, MutableRefObject, useMemo, useRef, useState } from 'react'; import { NativeSyntheticEvent, Text, @@ -267,7 +267,14 @@ const Mentions: FC = ( const handleTextInputRef = (ref: TextInput) => { textInput.current = ref as TextInput; - if (propInputRef) propInputRef.current = ref as TextInput; + + if (propInputRef) { + if (typeof propInputRef === 'function') { + propInputRef(ref); + } else { + (propInputRef as MutableRefObject).current = ref as TextInput; + } + } }; return ( diff --git a/src/types/types.ts b/src/types/types.ts index f0fa0d6..1a86a26 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -1,5 +1,5 @@ +import { ReactNode, Ref } from 'react'; import { StyleProp, TextInput, TextInputProps, TextStyle, ViewStyle } from 'react-native'; -import { MutableRefObject, ReactNode } from 'react'; type Suggestion = { id: string; @@ -49,7 +49,7 @@ type MentionsProps = Omit & { // Should we add a space after selected mentions if the mention is at the end of row isInsertSpaceAfterMention?: boolean; - inputRef?: MutableRefObject; + inputRef?: Ref; mentionTextStyle?: StyleProp;