Skip to content

Commit

Permalink
chore: fix listemptycomponent definition
Browse files Browse the repository at this point in the history
  • Loading branch information
azimgd committed Jan 14, 2025
1 parent 0048a47 commit ce75d85
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ void SLContainerShadowNode::layout(LayoutContext layoutContext) {
nextStateData.scrollPositionUpdated = true;
}

/*
* Guard case when list was emptied
*/
if (nextStateData.scrollIndex > props.uniqueIds.size()) {
nextStateData.scrollIndex = 0;
nextStateData.scrollPositionUpdated = true;
nextStateData.scrollIndexUpdated = true;
}

/*
* If data is prepended, extend the measurements tree from the beginning
* to match the new data size. If data is appended, resize the tree at the end
Expand Down Expand Up @@ -239,7 +248,7 @@ void SLContainerShadowNode::layout(LayoutContext layoutContext) {
},
componentRegistry["ListEmptyComponentUniqueId"]);

scrollContentBelowOffset.add(1, templateRegistryItem.size);
scrollContentBelowOffset.add(0, templateRegistryItem.size);
}

/*
Expand Down Expand Up @@ -272,17 +281,15 @@ void SLContainerShadowNode::layout(LayoutContext layoutContext) {
*/
this->children_ = containerShadowNodeChildren;
yogaNode_.setDirty(true);

/*
* Bailout without any state update
*/
if (!props.uniqueIds.size()) {
return;

if (props.uniqueIds.size()) {
nextStateData.firstChildUniqueId = props.uniqueIds.front();
nextStateData.lastChildUniqueId = props.uniqueIds.back();
} else {
nextStateData.firstChildUniqueId = {};
nextStateData.lastChildUniqueId = {};
}

nextStateData.firstChildUniqueId = props.uniqueIds.front();
nextStateData.lastChildUniqueId = props.uniqueIds.back();

if (props.horizontal) {
nextStateData.scrollContent.height = nextStateData.scrollContainer.height;
nextStateData.scrollContent.width = (
Expand Down
5 changes: 3 additions & 2 deletions src/Shadowlist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@ export const Shadowlist = React.forwardRef(
<SLContainer
{...props}
ref={forwardedRef}
style={[props.style, props.contentContainerStyle]}
style={props.contentContainerStyle}
>
{ListHeaderComponent}
{props.data.length ? ListChildrenComponent : ListEmptyComponent}
{ListChildrenComponent}
{ListEmptyComponent}
{ListFooterComponent}
</SLContainer>
);
Expand Down

0 comments on commit ce75d85

Please sign in to comment.