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) 825 B
import React, { forwardRef, useImperativeHandle } from 'react'; import { FlatList } from 'react-native'; import { KeyboardAvoidingContainer, useKeyboardAvoidingContainerProps, } from './KeyboardAvoidingContainer'; import { generic } from './utils/react'; export const KeyboardAvoidingFlatList = 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={FlatList} scrollViewRef={scrollViewRef}/>); }));