UNPKG

@fivecar/react-native-keyboard-avoiding-scrollview

Version:

React Native ScrollView extension that prevents inputs from being covered by the keyboard

14 lines (13 loc) 834 B
import React, { forwardRef, useImperativeHandle } from 'react'; import { SectionList } from 'react-native'; import { KeyboardAvoidingContainer, useKeyboardAvoidingContainerProps, } from './KeyboardAvoidingContainer'; import { generic } from './utils/react'; export const KeyboardAvoidingSectionList = generic(forwardRef((props, ref) => { const { scrollViewRef, ...KeyboardAvoidingContainerProps } = useKeyboardAvoidingContainerProps(props); // Use useImperativeHandle to expose the internal scrollViewRef to the parent useImperativeHandle(ref, () => { // @ts-expect-error We know it's a scrollview return scrollViewRef.current?.getScrollResponder(); }); return (<KeyboardAvoidingContainer {...KeyboardAvoidingContainerProps} ScrollViewComponent={SectionList} scrollViewRef={scrollViewRef}/>); }));