356 lines
16 KiB
React
356 lines
16 KiB
React
// Metro module 5415 (f5416).
|
|
import Module19, { useCallback, useId, useLayoutEffect, useMemo, useRef, useState, forwardRef } from "react";
|
|
import { Animated, I18nManager } from "react-native";
|
|
import { RenderTimeTracker } from "./RenderTimeTracker";
|
|
import { getInvertedTransformStyle } from "./Module5433";
|
|
import { useLayoutState } from "./Module5434";
|
|
import { useRecyclerViewManager } from "./Module5436";
|
|
import { useRecyclerViewController } from "./Module5458";
|
|
import { useOnListLoad } from "./useOnLoad";
|
|
import { useBoundDetection } from "./Module5464";
|
|
import { measureParentSize, measureFirstChildLayout, measureItemLayout, areDimensionsNotEqual } from "./Module5453";
|
|
import { WarningMessages } from "./Module5456";
|
|
import { adjustOffsetForRTL } from "./Module5462";
|
|
import { useRecyclerViewContext, RecyclerViewContextProvider } from "./Module5435";
|
|
import { useSecondaryProps } from "./Module5465";
|
|
import { ErrorMessages } from "./Module5413";
|
|
import { StickyHeaders } from "./Module5469";
|
|
import { CompatView } from "./Module5466";
|
|
import { ScrollAnchor } from "./Module5471";
|
|
import { ViewHolderCollection } from "./Module5472";
|
|
const _excluded = ["horizontal", "renderItem", "data", "extraData", "onLoad", "CellRendererComponent", "overrideProps", "refreshing", "onRefresh", "progressViewOffset", "ListEmptyComponent", "ListHeaderComponent", "ListHeaderComponentStyle", "ListFooterComponent", "ListFooterComponentStyle", "ItemSeparatorComponent", "renderScrollComponent", "style", "stickyHeaderIndices", "maintainVisibleContentPosition", "onCommitLayoutEffect", "onChangeStickyIndex", "stickyHeaderConfig", "inverted"];
|
|
const RecyclerViewComponent = (props, a1) => {
|
|
let stickyHeaderOffset, useNativeDriver, c14849_12, stickyHeaderZIndex, ref, ref2, ref3, ref4, current, current2, ref5, ref6, c14849_22, memo, recyclerViewManager, velocityTracker, applyOffsetCorrection, computeFirstVisibleIndexForOffsetCorrection, applyInitialScrollIndex, handlerMethods, ref7, checkBounds, horizontal2, callback, recyclerViewContext, id, memo2, memo3, shouldMaintainVisibleContentPosition, c14849_42;
|
|
const { horizontal, renderItem, data, extraData, onLoad, CellRendererComponent, overrideProps } = props;
|
|
props.refreshing;
|
|
props.onRefresh;
|
|
props.progressViewOffset;
|
|
props.ListEmptyComponent;
|
|
props.ListHeaderComponent;
|
|
props.ListHeaderComponentStyle;
|
|
props.ListFooterComponent;
|
|
props.ListFooterComponentStyle;
|
|
const ItemSeparatorComponent = props.ItemSeparatorComponent;
|
|
props.renderScrollComponent;
|
|
const { style, stickyHeaderIndices, maintainVisibleContentPosition, onCommitLayoutEffect: onCommitLayoutEffect2, onChangeStickyIndex: onChangeStickyIndex2, stickyHeaderConfig, inverted, ...rest } = props;
|
|
const [state] = useState(() => new RenderTimeTracker());
|
|
state.startTracking();
|
|
let r72 = stickyHeaderConfig?.offset;
|
|
if (r72 == null) {
|
|
r72 = 0;
|
|
}
|
|
stickyHeaderOffset = r72;
|
|
let r74 = stickyHeaderConfig?.useNativeDriver;
|
|
if (r74 == null) {
|
|
r74 = true;
|
|
}
|
|
useNativeDriver = r74;
|
|
let hideStickyHeaderRelatedCell = stickyHeaderConfig?.hideRelatedCell;
|
|
if (hideStickyHeaderRelatedCell == null) {
|
|
hideStickyHeaderRelatedCell = false;
|
|
}
|
|
c14849_12 = hideStickyHeaderRelatedCell;
|
|
let r13 = stickyHeaderConfig?.zIndex;
|
|
if (r13 == null) {
|
|
r13 = 2;
|
|
}
|
|
stickyHeaderZIndex = r13;
|
|
const r48 = inverted ? getInvertedTransformStyle(horizontal) : void 0;
|
|
ref = useRef(null);
|
|
ref2 = useRef(null);
|
|
ref3 = useRef(null);
|
|
ref4 = useRef(void 0);
|
|
current = useRef(new Set()).current;
|
|
current2 = useRef(new Animated.Value(0)).current;
|
|
ref5 = useRef(null);
|
|
ref6 = useRef(null);
|
|
const [, r103] = useLayoutState(0);
|
|
c14849_22 = r103;
|
|
const [, setState] = useState(0);
|
|
const [state2, setState2] = useState(-1);
|
|
memo = useMemo(() => new Map(), []);
|
|
const recyclerViewManager2 = useRecyclerViewManager(props);
|
|
recyclerViewManager = recyclerViewManager2.recyclerViewManager;
|
|
velocityTracker = recyclerViewManager2.velocityTracker;
|
|
const recyclerViewController = useRecyclerViewController(recyclerViewManager, a1, ref, ref6);
|
|
applyOffsetCorrection = recyclerViewController.applyOffsetCorrection;
|
|
computeFirstVisibleIndexForOffsetCorrection = recyclerViewController.computeFirstVisibleIndexForOffsetCorrection;
|
|
applyInitialScrollIndex = recyclerViewController.applyInitialScrollIndex;
|
|
handlerMethods = recyclerViewController.handlerMethods;
|
|
ref7 = useRef(null);
|
|
useOnListLoad(recyclerViewManager, onLoad);
|
|
checkBounds = useBoundDetection(recyclerViewManager, ref).checkBounds;
|
|
horizontal2 = I18nManager.isRTL && horizontal;
|
|
useLayoutEffect(() => {
|
|
if (ref2.current && ref3.current) {
|
|
const current3 = measureParentSize(ref2.current);
|
|
const r20 = measureFirstChildLayout(ref3.current, ref2.current);
|
|
ref4.current = current3;
|
|
const r23 = horizontal ? r20.x : r20.y;
|
|
recyclerViewManager.updateLayoutParams({
|
|
width: horizontal ? current3.width : r20.width,
|
|
height: horizontal ? r20.height : current3.height
|
|
}, horizontal2 ? recyclerViewManager.hasLayout() ? r23 - recyclerViewManager.getChildContainerDimensions().width : r23 : r23);
|
|
}
|
|
});
|
|
useLayoutEffect(() => {
|
|
if (!(current.size > 0)) {
|
|
const r13 = Array.from(memo, (a0) => {
|
|
const [index, r25] = a0;
|
|
return {
|
|
index,
|
|
dimensions: measureItemLayout(r25.current, recyclerViewManager.tryGetLayout(index))
|
|
};
|
|
});
|
|
const hasExceededMaxRendersWithoutCommit = state.hasExceededMaxRendersWithoutCommit();
|
|
if (hasExceededMaxRendersWithoutCommit) {
|
|
console.warn(WarningMessages.exceededMaxRendersWithoutCommit);
|
|
}
|
|
let r30 = data?.length;
|
|
if (r30 == null) {
|
|
r30 = 0;
|
|
}
|
|
if (recyclerViewManager.modifyChildrenLayout(r13, r30) && !hasExceededMaxRendersWithoutCommit) {
|
|
setState((prevState) => prevState + 1);
|
|
} else {
|
|
const current3 = ref7.current;
|
|
if (current3 != null) {
|
|
current3.commitLayout();
|
|
}
|
|
applyOffsetCorrection();
|
|
}
|
|
let r41 = horizontal;
|
|
if (horizontal) {
|
|
r41 = recyclerViewManager.hasLayout();
|
|
}
|
|
if (r41) {
|
|
r41 = recyclerViewManager.getWindowSize().height > 0;
|
|
}
|
|
if (r41 && recyclerViewContext != null) {
|
|
recyclerViewContext.unmarkChildLayoutAsPending(id);
|
|
}
|
|
}
|
|
});
|
|
callback = useCallback((a0) => {
|
|
if (!recyclerViewManager.ignoreScrollEvents) {
|
|
const contentOffset = a0.nativeEvent.contentOffset;
|
|
const r12 = horizontal ? contentOffset.x : contentOffset.y;
|
|
let c25453_0 = r12;
|
|
let r10 = r12;
|
|
if (horizontal2) {
|
|
const r30 = adjustOffsetForRTL(r12, a0.nativeEvent.contentSize.width, a0.nativeEvent.layoutMeasurement.width);
|
|
c25453_0 = r30;
|
|
r10 = r30;
|
|
}
|
|
velocityTracker.computeVelocity(r10, recyclerViewManager.getAbsoluteLastScrollOffset(), Boolean(horizontal), (a0, a1) => {
|
|
if (!recyclerViewManager.ignoreScrollEvents) {
|
|
if (a1) {
|
|
computeFirstVisibleIndexForOffsetCorrection();
|
|
if (!recyclerViewManager.isOffsetProjectionEnabled) {
|
|
return void 0;
|
|
}
|
|
recyclerViewManager.resetVelocityCompute();
|
|
}
|
|
if (recyclerViewManager.updateScrollOffset(c25453_0, a0)) {
|
|
setState((prevState) => prevState + 1);
|
|
}
|
|
}
|
|
});
|
|
const current3 = ref5.current;
|
|
if (current3 != null) {
|
|
current3.reportScrollEvent(a0.nativeEvent);
|
|
}
|
|
checkBounds();
|
|
if (recyclerViewManager.isInitialScrollComplete) {
|
|
recyclerViewManager.recordInteraction();
|
|
}
|
|
recyclerViewManager.computeItemViewability();
|
|
const props = recyclerViewManager.props;
|
|
const onScroll = props.onScroll;
|
|
if (onScroll != null) {
|
|
onScroll.call(props, a0);
|
|
}
|
|
}
|
|
}, [checkBounds, computeFirstVisibleIndexForOffsetCorrection, horizontal, horizontal2, recyclerViewManager, velocityTracker]);
|
|
recyclerViewContext = useRecyclerViewContext();
|
|
id = useId();
|
|
memo2 = useMemo(() => ({
|
|
layout: () => {
|
|
c14849_22((a0) => a0 + 1);
|
|
},
|
|
getRef: () => recyclerViewManager.isDisposed ? null : handlerMethods,
|
|
getParentRef: () => {
|
|
let r5 = recyclerViewContext == null ? void 0 : recyclerViewContext.getRef();
|
|
if (r5 == null) {
|
|
r5 = null;
|
|
}
|
|
return r5;
|
|
},
|
|
getParentScrollViewRef: () => {
|
|
let r5 = recyclerViewContext == null ? void 0 : recyclerViewContext.getScrollViewRef();
|
|
if (r5 == null) {
|
|
r5 = null;
|
|
}
|
|
return r5;
|
|
},
|
|
getScrollViewRef: () => ref.current,
|
|
markChildLayoutAsPending: (a0) => {
|
|
current.add(a0);
|
|
},
|
|
unmarkChildLayoutAsPending: (a0) => {
|
|
if (current.has(a0)) {
|
|
current.delete(a0);
|
|
memo2.layout();
|
|
}
|
|
}
|
|
}), [handlerMethods, recyclerViewContext, current, recyclerViewManager.isDisposed, r103]);
|
|
const callback2 = useCallback((a0, a1) => {
|
|
const layout2 = recyclerViewManager.getLayout(a0);
|
|
const r8 = Math;
|
|
const r10 = Math;
|
|
const width = layout2.width;
|
|
let maxWidth = layout2.maxWidth;
|
|
if (maxWidth == null) {
|
|
maxWidth = Infinity;
|
|
}
|
|
const r14 = r10.min(width, maxWidth);
|
|
let minWidth = layout2.minWidth;
|
|
if (minWidth == null) {
|
|
minWidth = 0;
|
|
}
|
|
const r16 = r8.max(r14, minWidth);
|
|
const r17 = Math;
|
|
const r19 = Math;
|
|
const height = layout2.height;
|
|
let maxHeight = layout2.maxHeight;
|
|
if (maxHeight == null) {
|
|
maxHeight = Infinity;
|
|
}
|
|
const r23 = r19.min(height, maxHeight);
|
|
let minHeight = layout2.minHeight;
|
|
if (minHeight == null) {
|
|
minHeight = 0;
|
|
}
|
|
const r26 = r17.max(r23, minHeight);
|
|
if (areDimensionsNotEqual(r16, a1.width) || areDimensionsNotEqual(r26, a1.height)) {
|
|
memo2.layout();
|
|
}
|
|
}, [memo2, recyclerViewManager]);
|
|
const secondaryProps = useSecondaryProps(props);
|
|
const { refreshControl, renderHeader, renderFooter, renderEmpty, CompatScrollView, renderStickyHeaderBackdrop } = secondaryProps;
|
|
const isFirstLayoutComplete = recyclerViewManager.getIsFirstLayoutComplete();
|
|
if ((isFirstLayoutComplete ? !isFirstLayoutComplete : recyclerViewManager.getDataLength() > 0) && recyclerViewContext != null) {
|
|
recyclerViewContext.markChildLayoutAsPending(id);
|
|
}
|
|
memo3 = useMemo(() => {
|
|
if (data && data.length > 0 && stickyHeaderIndices && stickyHeaderIndices.length > 0) {
|
|
if (horizontal) {
|
|
throw new Error(ErrorMessages.stickyHeadersNotSupportedForHorizontal);
|
|
}
|
|
return <StickyHeaders stickyHeaderIndices={stickyHeaderIndices} stickyHeaderOffset={stickyHeaderOffset} data={data} renderItem={renderItem} scrollY={current2} stickyHeaderRef={ref5} stickyHeaderZIndex={stickyHeaderZIndex} recyclerViewManager={recyclerViewManager} extraData={extraData} inverted={inverted} onChangeStickyIndex={(event) => {
|
|
if (c14849_12) {
|
|
setState2(event);
|
|
}
|
|
if (onChangeStickyIndex2 != null) {
|
|
onChangeStickyIndex2(event, state2);
|
|
}
|
|
}} />;
|
|
}
|
|
return null;
|
|
}, [data, stickyHeaderIndices, stickyHeaderOffset, renderItem, current2, horizontal, recyclerViewManager, extraData, state2, onChangeStickyIndex2, hideStickyHeaderRelatedCell, stickyHeaderZIndex, inverted]);
|
|
const memo4 = useMemo(() => memo3 ? Animated.event([{
|
|
nativeEvent: {
|
|
contentOffset: {
|
|
y: current2
|
|
}
|
|
}
|
|
}], {
|
|
useNativeDriver,
|
|
listener: callback
|
|
}) : callback, [callback, current2, memo3, useNativeDriver]);
|
|
shouldMaintainVisibleContentPosition = recyclerViewManager.shouldMaintainVisibleContentPosition();
|
|
const memo5 = useMemo(() => {
|
|
if (shouldMaintainVisibleContentPosition) {
|
|
return {
|
|
...maintainVisibleContentPosition,
|
|
minIndexForVisible: 0
|
|
};
|
|
}
|
|
}, [maintainVisibleContentPosition, shouldMaintainVisibleContentPosition]);
|
|
let r188 = recyclerViewManager.getDataLength() > 0;
|
|
if (r188) {
|
|
let r190 = maintainVisibleContentPosition?.startRenderingFromBottom;
|
|
if (r190 == null) {
|
|
r190 = false;
|
|
}
|
|
r188 = r190;
|
|
}
|
|
c14849_42 = r188;
|
|
const memo6 = useMemo(() => <CompatView style={{
|
|
marginTop: horizontal ? void 0 : stickyHeaderOffset,
|
|
height: horizontal ? void 0 : 0,
|
|
width: horizontal ? 0 : void 0
|
|
}} ref={ref3} />, [horizontal, stickyHeaderOffset]);
|
|
return <RecyclerViewContextProvider value={memo2}>
|
|
<CompatView style={[{
|
|
flex: horizontal ? void 0 : 1,
|
|
overflow: "hidden"
|
|
}, style, r48]} ref={ref2} collapsable={false} onLayout={(event) => {
|
|
const width = event.nativeEvent.layout.width;
|
|
let r17 = ref4.current?.width;
|
|
if (r17 == null) {
|
|
r17 = 0;
|
|
}
|
|
let r18 = areDimensionsNotEqual(width, r17);
|
|
if (!r18) {
|
|
const height = event.nativeEvent.layout.height;
|
|
let r27 = ref4.current?.height;
|
|
if (r27 == null) {
|
|
r27 = 0;
|
|
}
|
|
r18 = areDimensionsNotEqual(height, r27);
|
|
}
|
|
if (r18) {
|
|
memo2.layout();
|
|
}
|
|
}}>
|
|
<CompatScrollView {...rest} horizontal={horizontal} ref={ref} onScroll={memo4} maintainVisibleContentPosition={memo5} removeClippedSubviews={false} refreshControl={refreshControl} {...overrideProps}>
|
|
{useMemo(() => shouldMaintainVisibleContentPosition ? <ScrollAnchor horizontal={Boolean(horizontal)} scrollAnchorRef={ref6} /> : null, [horizontal, shouldMaintainVisibleContentPosition])}
|
|
{horizontal2 ? memo6 : horizontal2}
|
|
{renderHeader}
|
|
{horizontal2 ? !horizontal2 : memo6}
|
|
<ViewHolderCollection viewHolderCollectionRef={ref7} data={data} horizontal={horizontal} renderStack={recyclerViewManager.getRenderStack()} getLayout={(a0) => recyclerViewManager.getLayout(a0)} getAdjustmentMargin={() => {
|
|
if (c14849_42 && recyclerViewManager.hasLayout()) {
|
|
const windowSize = recyclerViewManager.getWindowSize();
|
|
const r5 = horizontal ? windowSize.width : windowSize.height;
|
|
const childContainerDimensions = recyclerViewManager.getChildContainerDimensions();
|
|
return Math.max(0, r5 - (horizontal ? childContainerDimensions.width : childContainerDimensions.height) - recyclerViewManager.firstItemOffset);
|
|
}
|
|
return 0;
|
|
}} refHolder={memo} onSizeChanged={callback2} renderItem={renderItem} extraData={extraData} onCommitLayoutEffect={() => {
|
|
applyInitialScrollIndex();
|
|
if (recyclerViewContext != null) {
|
|
recyclerViewContext.unmarkChildLayoutAsPending(id);
|
|
}
|
|
if (onCommitLayoutEffect2 != null) {
|
|
onCommitLayoutEffect2();
|
|
}
|
|
}} onCommitEffect={() => {
|
|
state.markRenderComplete();
|
|
recyclerViewManager.updateAverageRenderTime(state.getAverageRenderTime());
|
|
applyInitialScrollIndex();
|
|
checkBounds();
|
|
recyclerViewManager.computeItemViewability();
|
|
recyclerViewManager.animationOptimizationsEnabled = false;
|
|
}} CellRendererComponent={CellRendererComponent} ItemSeparatorComponent={ItemSeparatorComponent} isInLastRow={(a0) => recyclerViewManager.isInLastRow(a0)} getChildContainerLayout={() => recyclerViewManager.hasLayout() ? recyclerViewManager.getChildContainerDimensions() : void 0} currentStickyIndex={state2} hideStickyHeaderRelatedCell={hideStickyHeaderRelatedCell} inverted={inverted} />
|
|
{renderEmpty}
|
|
{renderFooter}
|
|
</CompatScrollView>
|
|
{stickyHeaderIndices ? stickyHeaderIndices.length > 0 ? renderStickyHeaderBackdrop : null : null}
|
|
{memo3}
|
|
</CompatView>
|
|
</RecyclerViewContextProvider>;
|
|
};
|
|
RecyclerViewComponent.displayName = "FlashList";
|
|
export const RecyclerView = Module19.memo(forwardRef(RecyclerViewComponent));
|