@wordpress/components
Version:
UI components for WordPress.
82 lines (78 loc) • 2.48 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.KeyboardAwareFlatList = void 0;
var _reactNative = require("react-native");
var _reactNativeReanimated = _interopRequireDefault(require("react-native-reanimated"));
var _element = require("@wordpress/element");
var _useScroll = _interopRequireDefault(require("./use-scroll"));
var _keyboardAvoidingView = _interopRequireDefault(require("../keyboard-avoiding-view"));
var _shared = require("./shared");
var _jsxRuntime = require("react/jsx-runtime");
/**
* External dependencies
*/
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
const AnimatedFlatList = _reactNativeReanimated.default.createAnimatedComponent(_reactNative.FlatList);
const EMPTY_OBJECT = {};
const KeyboardAwareFlatList = ({
onScroll,
...props
}, ref) => {
const {
extraScrollHeight,
scrollEnabled,
shouldPreventAutomaticScroll
} = props;
const {
scrollViewRef,
scrollHandler,
scrollToSection,
scrollToElement,
onContentSizeChange,
lastScrollTo
} = (0, _useScroll.default)({
scrollEnabled,
shouldPreventAutomaticScroll,
extraScrollHeight,
onScroll
});
const getFlatListRef = (0, _element.useCallback)(flatListRef => {
scrollViewRef.current = flatListRef?.getNativeScrollRef();
}, [scrollViewRef]);
(0, _element.useImperativeHandle)(ref, () => {
return {
scrollViewRef: scrollViewRef.current,
scrollToSection,
scrollToElement,
lastScrollTo
};
});
const optimizationProps = props.data?.length > _shared.OPTIMIZATION_ITEMS_THRESHOLD ? _shared.OPTIMIZATION_PROPS : EMPTY_OBJECT;
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_keyboardAvoidingView.default, {
style: {
flex: 1
},
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(AnimatedFlatList, {
ref: getFlatListRef,
onScroll: scrollHandler,
onContentSizeChange: onContentSizeChange
// Disable clipping to fix focus losing.
// See https://github.com/wordpress-mobile/gutenberg-mobile/pull/741#issuecomment-472746541
,
removeClippedSubviews: false,
...optimizationProps,
...props
})
});
};
exports.KeyboardAwareFlatList = KeyboardAwareFlatList;
var _default = exports.default = (0, _element.forwardRef)(KeyboardAwareFlatList);
//# sourceMappingURL=index.android.js.map