Skip to content

Commit

Permalink
[General] Fixes scrolling to section not work when index is 0 and sti…
Browse files Browse the repository at this point in the history
…ckySectionHeadersEnabled
  • Loading branch information
zhongwuzw committed Dec 5, 2024
1 parent f402ed1 commit add03ec
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1668,7 +1668,11 @@ class ScrollView extends React.Component<Props, State> {
nextHeaderLayoutY={this._headerLayoutYs.get(
this._getKeyForIndex(nextIndex, children),
)}
onLayout={event => this._onStickyHeaderLayout(index, event, key)}
onLayout={event => {
this._onStickyHeaderLayout(index, event, key);
const {onCellLayout, cellKey, index: cellIndex} = child.props;
onCellLayout?.(event, cellKey, cellIndex);
}}
scrollAnimatedValue={this._scrollAnimatedValue}
inverted={this.props.invertStickyHeaders}
hiddenOnScroll={this.props.stickyHeaderHiddenOnScroll}
Expand Down
3 changes: 3 additions & 0 deletions packages/virtualized-lists/Lists/VirtualizedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -789,8 +789,10 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
const key = VirtualizedList._keyExtractor(item, ii, this.props);

this._indicesToKeys.set(ii, key);
let isStickyHeader = false;
if (stickyIndicesFromProps.has(ii + stickyOffset)) {
stickyHeaderIndices.push(cells.length);
isStickyHeader = true;
}

const shouldListenForLayout =
Expand All @@ -811,6 +813,7 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
onUpdateSeparators={this._onUpdateSeparators}
onCellFocusCapture={this._onCellFocusCapture}
onUnmount={this._onCellUnmount}
isStickyHeader={isStickyHeader}
ref={ref => {
this._cellRefs[key] = ref;
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export type Props<ItemT> = {
) => void,
prevCellKey: ?string,
renderItem?: ?RenderItemType<ItemT>,
isStickyHeader?: boolean,
...
};

Expand Down Expand Up @@ -118,6 +119,10 @@ export default class CellRenderer<ItemT> extends React.PureComponent<
}

_onLayout = (nativeEvent: LayoutEvent): void => {
const {isStickyHeader} = this.props;
if (isStickyHeader) {
return;
}
this.props.onCellLayout?.(
nativeEvent,
this.props.cellKey,
Expand Down

0 comments on commit add03ec

Please sign in to comment.