@@ -2,36 +2,48 @@ import React from 'react'
22import { useKeyboardHandler } from 'react-native-keyboard-controller'
33import Animated , { useAnimatedStyle , useSharedValue } from 'react-native-reanimated'
44
5- const PADDING_BOTTOM = 0
5+ const LOG_KEYBOARD_EVENTS = false
66
77const useGradualAnimation = ( ) => {
8- const height = useSharedValue ( PADDING_BOTTOM )
8+ const height = useSharedValue ( 0 )
9+ const progress = useSharedValue ( 0 )
910
1011 useKeyboardHandler (
1112 {
13+ onStart : ( event ) => {
14+ 'worklet'
15+ if ( LOG_KEYBOARD_EVENTS ) console . log ( '[KeyboardHandler] onStart' , event )
16+ } ,
1217 onMove : ( event ) => {
1318 'worklet'
14- height . value = Math . max ( event . height , PADDING_BOTTOM )
19+ if ( LOG_KEYBOARD_EVENTS ) console . log ( '[KeyboardHandler] onMove' , event )
20+ height . value = event . height
21+ progress . value = event . progress
22+ } ,
23+ onEnd : ( event ) => {
24+ 'worklet'
25+ if ( LOG_KEYBOARD_EVENTS ) console . log ( '[KeyboardHandler] onEnd' , event )
26+ progress . value = event . progress
27+ height . value = event . height
1528 } ,
1629 } ,
1730 [ ] ,
1831 )
1932
20- return { height }
33+ return { height, progress }
2134}
2235
2336const KeyboardHandler : React . FC = ( ) => {
24- const { height } = useGradualAnimation ( )
37+ const { height, progress } = useGradualAnimation ( )
2538
2639 const animatedStyle = useAnimatedStyle ( ( ) => {
2740 return {
28- height : Math . abs ( height . value ) ,
29- marginBottom : height . value > 0 ? 0 : PADDING_BOTTOM ,
30- width : 'auto' ,
41+ // Use height as-is, but fallback to 0 if progress indicates keyboard is hidden
42+ height : progress . value === 0 ? 0 : height . value ,
3143 }
3244 } )
3345
34- return < Animated . View style = { animatedStyle } > </ Animated . View >
46+ return < Animated . View style = { animatedStyle } / >
3547}
3648
3749export default KeyboardHandler
0 commit comments