@fivecar/react-native-keyboard-avoiding-scrollview
Version:
React Native ScrollView extension that prevents inputs from being covered by the keyboard
13 lines (12 loc) • 807 B
JavaScript
import React, { forwardRef, useImperativeHandle } from 'react';
import { ScrollView } from 'react-native';
import { KeyboardAvoidingContainer, useKeyboardAvoidingContainerProps, } from './KeyboardAvoidingContainer';
export const KeyboardAvoidingScrollView = forwardRef((props, ref) => {
const { scrollViewRef, ...KeyboardAvoidingContainerProps } = useKeyboardAvoidingContainerProps(props);
// Use useImperativeHandle to expose the internal scrollViewRef to the parent
useImperativeHandle(ref, () => {
// @ts-expect-error This is how other parts of the codebase use the ref
return scrollViewRef.current?.getScrollResponder();
});
return (<KeyboardAvoidingContainer {...KeyboardAvoidingContainerProps} ScrollViewComponent={ScrollView} scrollViewRef={scrollViewRef}/>);
});