1
1
import { AnimatedVStack } from "@design-system/VStack"
2
2
import { memo , useEffect , useRef } from "react"
3
3
import { Keyboard , TextInput } from "react-native"
4
- import { useAnimatedStyle , useSharedValue } from "react-native-reanimated"
4
+ import { useAnimatedStyle } from "react-native-reanimated"
5
5
import { useSafeAreaInsets } from "react-native-safe-area-context"
6
6
import { useConversationMessageContextMenuEmojiPickerStore } from "@/features/conversation/conversation-chat/conversation-chat-message/conversation-message-context-menu/conversation-message-context-menu-emoji-picker/conversation-message-context-menu-emoji-picker.store"
7
7
import { useConversationMessageContextMenuStoreContext } from "@/features/conversation/conversation-chat/conversation-chat-message/conversation-message-context-menu/conversation-message-context-menu.store-context"
@@ -13,11 +13,10 @@ type IConversationKeyboardFillerProps = {}
13
13
export const ConversationKeyboardFiller = memo ( function ConversationKeyboardFiller (
14
14
props : IConversationKeyboardFillerProps ,
15
15
) {
16
- const { height : keyboardHeightAV } = useAnimatedKeyboard ( )
16
+ const { keyboardHeightAV, progressAV , previousOpenKeyboardHeightAV } = useAnimatedKeyboard ( )
17
17
const insets = useSafeAreaInsets ( )
18
- const lastKeyboardHeight = useSharedValue ( 0 )
18
+ const wasKeyboardOpenRef = useRef ( false )
19
19
const textInputRef = useRef < TextInput > ( null )
20
- const keyboardWasOpenRef = useRef ( false )
21
20
const isKeyboardShown = useKeyboardIsShown ( )
22
21
23
22
const messageContextMenuData = useConversationMessageContextMenuStoreContext (
@@ -33,51 +32,42 @@ export const ConversationKeyboardFiller = memo(function ConversationKeyboardFill
33
32
return
34
33
}
35
34
36
- if ( ! ! messageContextMenuData ) {
37
- // If the keyboard is open, keep track of where it was because we need to open it again when the context menu is dismissed
35
+ if ( messageContextMenuData ) {
36
+ // Store keyboard state when emoji picker opens
38
37
if ( isKeyboardShown ) {
39
38
Keyboard . dismiss ( )
40
- lastKeyboardHeight . value = keyboardHeightAV . value
41
- keyboardWasOpenRef . current = true
39
+ wasKeyboardOpenRef . current = true
42
40
}
43
41
}
44
42
// Context menu is hidden
45
43
else {
46
- // Reopen keyboard if it was open before context menu was shown
47
- if ( keyboardWasOpenRef . current ) {
44
+ // Restore keyboard state when emoji picker closes
45
+ if ( wasKeyboardOpenRef . current ) {
48
46
textInputRef . current ?. focus ( )
49
- keyboardWasOpenRef . current = false
47
+ wasKeyboardOpenRef . current = false
50
48
}
51
49
}
52
- } , [
53
- isEmojiPickerOpen ,
54
- messageContextMenuData ,
55
- isKeyboardShown ,
56
- keyboardHeightAV ,
57
- lastKeyboardHeight ,
58
- ] )
50
+ } , [ isEmojiPickerOpen , messageContextMenuData , isKeyboardShown ] )
59
51
60
- // Reset the last height when context menu is dismissed
61
- // And make sure to wait until the keyboard is open to that the height animates back to what it was before
62
- useEffect ( ( ) => {
63
- if ( ! messageContextMenuData && isKeyboardShown ) {
64
- lastKeyboardHeight . value = 0
52
+ const fillerAnimatedStyle = useAnimatedStyle ( ( ) => {
53
+ if ( messageContextMenuData ) {
54
+ return {
55
+ height : previousOpenKeyboardHeightAV . value - insets . bottom ,
56
+ }
65
57
}
66
- } , [ messageContextMenuData , isKeyboardShown , keyboardHeightAV , lastKeyboardHeight ] )
67
58
68
- const fillerAnimatedStyle = useAnimatedStyle ( ( ) => {
59
+ const baseHeight = typeof keyboardHeightAV . value === "number" ? keyboardHeightAV . value : 0
60
+ const currentHeight = baseHeight * progressAV . value
61
+
69
62
return {
70
- height : Math . max (
71
- Math . max ( lastKeyboardHeight . value , keyboardHeightAV . value ) - insets . bottom ,
72
- 0 ,
73
- ) ,
63
+ height : Math . max ( currentHeight - insets . bottom , 0 ) ,
74
64
}
75
65
} )
76
66
77
67
return (
78
68
< >
79
69
< AnimatedVStack style = { fillerAnimatedStyle } />
80
- { /* Need for focus on keyboard */ }
70
+ { /* Hidden TextInput for keyboard focus management */ }
81
71
< TextInput
82
72
ref = { textInputRef }
83
73
style = { { height : 0 , width : 0 , opacity : 0 , position : "absolute" } }
0 commit comments