UNPKG

@gechiui/components

Version:
71 lines (67 loc) 2.13 kB
import { createElement } from "@gechiui/element"; /** * External dependencies */ import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view'; import { FlatList } from 'react-native'; import { isEqual } from 'lodash'; /** * GeChiUI dependencies */ import { memo } from '@gechiui/element'; const List = memo(FlatList, isEqual); export const KeyboardAwareFlatList = _ref => { let { extraScrollHeight, shouldPreventAutomaticScroll, innerRef, autoScroll, scrollViewStyle, inputAccessoryViewHeight, ...listProps } = _ref; return createElement(KeyboardAwareScrollView, { style: [{ flex: 1 }, scrollViewStyle], keyboardDismissMode: "none", enableResetScrollToCoords: false, keyboardShouldPersistTaps: "handled", extraScrollHeight: extraScrollHeight, extraHeight: 0, inputAccessoryViewHeight: inputAccessoryViewHeight, enableAutomaticScroll: autoScroll === undefined ? false : autoScroll, ref: ref => { this.scrollViewRef = ref; innerRef(ref); }, onKeyboardWillHide: () => { this.keyboardWillShowIndicator = false; }, onKeyboardDidHide: () => { setTimeout(() => { if (!this.keyboardWillShowIndicator && this.latestContentOffsetY !== undefined && !shouldPreventAutomaticScroll()) { // Reset the content position if keyboard is still closed if (this.scrollViewRef) { this.scrollViewRef.scrollToPosition(0, this.latestContentOffsetY, true); } } }, 50); }, onKeyboardWillShow: () => { this.keyboardWillShowIndicator = true; }, scrollEnabled: listProps.scrollEnabled, onScroll: event => { this.latestContentOffsetY = event.nativeEvent.contentOffset.y; } }, createElement(List, listProps)); }; KeyboardAwareFlatList.handleCaretVerticalPositionChange = (scrollView, targetId, caretY, previousCaretY) => { if (previousCaretY) { //if this is not the first tap scrollView.refreshScrollForField(targetId); } }; export default KeyboardAwareFlatList; //# sourceMappingURL=index.ios.js.map