88} from 'react-native' ;
99import {
1010 runOnUI ,
11+ useAnimatedReaction ,
1112 useSharedValue ,
1213 useWorkletCallback ,
1314} from 'react-native-reanimated' ;
@@ -36,12 +37,19 @@ export const useKeyboard = () => {
3637 const keyboardAnimationEasing =
3738 useSharedValue < KeyboardEventEasing > ( 'keyboard' ) ;
3839 const keyboardAnimationDuration = useSharedValue ( 500 ) ;
40+ const temporaryCachedKeyboardEvent = useSharedValue < any > ( [ ] ) ;
3941 //#endregion
4042
4143 //#region worklets
4244 const handleKeyboardEvent = useWorkletCallback (
4345 ( state , height , duration , easing ) => {
4446 if ( state === KEYBOARD_STATE . SHOWN && ! shouldHandleKeyboardEvents . value ) {
47+ /**
48+ * if the keyboard event was fired before the `onFocus` on TextInput,
49+ * then we cache the input, and wait till the `shouldHandleKeyboardEvents`
50+ * to be updated then fire this function again.
51+ */
52+ temporaryCachedKeyboardEvent . value = [ state , height , duration , easing ] ;
4553 return ;
4654 }
4755 keyboardHeight . value =
@@ -53,6 +61,7 @@ export const useKeyboard = () => {
5361 keyboardAnimationDuration . value = duration ;
5462 keyboardAnimationEasing . value = easing ;
5563 keyboardState . value = state ;
64+ temporaryCachedKeyboardEvent . value = [ ] ;
5665 } ,
5766 [ ]
5867 ) ;
@@ -99,6 +108,21 @@ export const useKeyboard = () => {
99108 ) ;
100109 } ;
101110 } , [ handleKeyboardEvent ] ) ;
111+
112+ /**
113+ * This reaction is needed to handle the issue with multiline text input.
114+ *
115+ * @link https://github.com/gorhom/react-native-bottom-sheet/issues/411
116+ */
117+ useAnimatedReaction (
118+ ( ) => shouldHandleKeyboardEvents . value ,
119+ result => {
120+ const params = temporaryCachedKeyboardEvent . value ;
121+ if ( result && params . length > 0 ) {
122+ handleKeyboardEvent ( params [ 0 ] , params [ 1 ] , params [ 2 ] , params [ 3 ] ) ;
123+ }
124+ }
125+ ) ;
102126 //#endregion
103127
104128 return {
0 commit comments