1- import { useEffect , useMemo , useRef } from 'react' ;
2- import { Alert , EventSubscription , Keyboard , Platform } from 'react-native' ;
1+ import { useMemo } from 'react' ;
2+ import { Alert } from 'react-native' ;
33
44import { UserResponse } from 'stream-chat' ;
55
@@ -9,15 +9,12 @@ import type { ChannelContextValue } from '../../../contexts/channelContext/Chann
99import type { ChatContextValue } from '../../../contexts/chatContext/ChatContext' ;
1010import { MessageComposerAPIContextValue } from '../../../contexts/messageComposerContext/MessageComposerAPIContext' ;
1111import type { MessageContextValue } from '../../../contexts/messageContext/MessageContext' ;
12- import { useMessageInputContext } from '../../../contexts/messageInputContext/MessageInputContext' ;
1312import type { MessagesContextValue } from '../../../contexts/messagesContext/MessagesContext' ;
1413
1514import { useTranslationContext } from '../../../contexts/translationContext/TranslationContext' ;
16- import { useStableCallback } from '../../../hooks' ;
17- import { useKeyboardVisibility } from '../../../hooks/useKeyboardVisibility' ;
15+ import { usePortalClosingKeyboardSafeCallback , useStableCallback } from '../../../hooks' ;
1816import { useTranslatedMessage } from '../../../hooks/useTranslatedMessage' ;
1917import { NativeHandlers } from '../../../native' ;
20- import { KeyboardControllerPackage } from '../../KeyboardCompatibleView/KeyboardControllerAvoidingView' ;
2118
2219export const useMessageActionHandlers = ( {
2320 channel,
@@ -40,19 +37,9 @@ export const useMessageActionHandlers = ({
4037 const { t } = useTranslationContext ( ) ;
4138 const handleResendMessage = useStableCallback ( ( ) => retrySendMessage ( message ) ) ;
4239 const translatedMessage = useTranslatedMessage ( message ) ;
43- const { inputBoxRef } = useMessageInputContext ( ) ;
44- const isKeyboardVisible = useKeyboardVisibility ( ) ;
45- const keyboardDidShowSubscriptionRef = useRef < EventSubscription | undefined > ( undefined ) ;
4640
4741 const isMuted = useUserMuteActive ( message . user ) ;
4842
49- const clearKeyboardDidShowSubscription = useStableCallback ( ( ) => {
50- keyboardDidShowSubscriptionRef . current ?. remove ( ) ;
51- keyboardDidShowSubscriptionRef . current = undefined ;
52- } ) ;
53-
54- useEffect ( ( ) => clearKeyboardDidShowSubscription , [ clearKeyboardDidShowSubscription ] ) ;
55-
5643 const handleQuotedReplyMessage = useStableCallback ( ( ) => {
5744 setQuotedMessage ( message ) ;
5845 } ) ;
@@ -127,40 +114,7 @@ export const useMessageActionHandlers = ({
127114 }
128115 } ) ;
129116
130- const handleEditMessage = useStableCallback ( ( ) => {
131- requestAnimationFrame ( ( ) =>
132- requestAnimationFrame ( ( ) => {
133- clearKeyboardDidShowSubscription ( ) ;
134-
135- const openEditingState = ( ) => {
136- clearKeyboardDidShowSubscription ( ) ;
137- setEditingState ( message ) ;
138- } ;
139-
140- if ( ! inputBoxRef . current ) {
141- openEditingState ( ) ;
142- return ;
143- }
144-
145- if ( isKeyboardVisible ) {
146- inputBoxRef . current ?. focus ( ) ;
147- openEditingState ( ) ;
148- return ;
149- }
150-
151- const event = Platform . OS === 'ios' ? 'keyboardWillShow' : 'keyboardDidShow' ;
152-
153- keyboardDidShowSubscriptionRef . current = KeyboardControllerPackage ?. KeyboardEvents
154- ? KeyboardControllerPackage . KeyboardEvents . addListener (
155- 'keyboardDidShow' ,
156- openEditingState ,
157- )
158- : Keyboard . addListener ( event , openEditingState ) ;
159-
160- inputBoxRef . current ?. focus ( ) ;
161- } ) ,
162- ) ;
163- } ) ;
117+ const handleEditMessage = usePortalClosingKeyboardSafeCallback ( ( ) => setEditingState ( message ) ) ;
164118
165119 const handleFlagMessage = useStableCallback ( ( ) => {
166120 if ( ! message . id ) {
0 commit comments