Skip to content

Commit

Permalink
feat(core): allow forwarding space if a child component has "shouldFo…
Browse files Browse the repository at this point in the history
…rwardSpace" set onto the component instance, and only one child exists of this type
  • Loading branch information
natew committed Dec 15, 2022
1 parent f178112 commit 46fae11
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/core/src/createComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,16 @@ export function spacedChildren({
return children
}
const childrenList = Children.toArray(children)
if (childrenList.length <= 1 && !isZStack) {
const len = childrenList.length
if (len <= 1 && !isZStack) {
if (len === 1) {
// forward space! only when one component
// doesn't make sense to forward space to all children
const [onlyChild] = childrenList
if (React.isValidElement(onlyChild) && onlyChild.type?.['shouldForwardSpace']) {
return React.cloneElement(onlyChild, { space } as any)
}
}
return childrenList
}
const final: React.ReactNode[] = []
Expand Down

0 comments on commit 46fae11

Please sign in to comment.