diff options
Diffstat (limited to 'src/components/KeyboardControllerPadding.android.tsx')
-rw-r--r-- | src/components/KeyboardControllerPadding.android.tsx | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/components/KeyboardControllerPadding.android.tsx b/src/components/KeyboardControllerPadding.android.tsx new file mode 100644 index 000000000..92ef1b0b0 --- /dev/null +++ b/src/components/KeyboardControllerPadding.android.tsx @@ -0,0 +1,31 @@ +import React from 'react' +import {useKeyboardHandler} from 'react-native-keyboard-controller' +import Animated, { + useAnimatedStyle, + useSharedValue, +} from 'react-native-reanimated' + +export function KeyboardControllerPadding({maxHeight}: {maxHeight?: number}) { + const keyboardHeight = useSharedValue(0) + + useKeyboardHandler( + { + onMove: e => { + 'worklet' + + if (maxHeight && e.height > maxHeight) { + keyboardHeight.value = maxHeight + } else { + keyboardHeight.value = e.height + } + }, + }, + [maxHeight], + ) + + const animatedStyle = useAnimatedStyle(() => ({ + height: keyboardHeight.value, + })) + + return <Animated.View style={animatedStyle} /> +} |