-
-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stack component should not apply spacing around empty components #20
Comments
hey @jsamr, I'm looking into it, however, I think with the current implementation (that isn't based on |
What about using let visible = true
<Stack>
<SomeElement/>
<SomeElement/>
<Hidden isVisible={visible}> // isVisible by default = false
<AnotherElement/>
</Hidden>
</Stack> However I'm not sure if this wouldn't be harder to implement :D |
@Fortidude We could also write <Stack>
<SomeElement/>
<SomeElement/>
{isVisible && <AnotherElement/>}
</Stack> and that would be fine with Stack, since falsy values are not accounted as children. If the controlling component (the one rendering |
A naive implementation of Stack with such feature: import React, { Children } from "react";
import View from "react-native";
function shouldIncludeNode(element) {
if (element && typeof element === "object") {
return Children.toArray(element.children).some(shouldIncludeNode);
}
return !!element;
}
export default function Stack({ children, style }) {
return (
<View style={style}>
{Children.toArray(children)
.filter(shouldIncludeNode)
.map((c) => (
<View style={{/** conditional margins */}}>{c}</View>
))}
</View>
);
} |
We face the same problem. We let our components decide if they should be rendered or not. It would be a big refactor to move that logic out into the screen. I too wish the Stack (and other components) would check if their children return null |
Anyone figure out how to handle this case? |
Could flex-gap support in RN 0.71.0 solve this issue? facebook/react-native-website#3398 |
@happyfloat hopefully yes! I have been waiting for the |
support for |
If a children of
Stack
renders conditionally, e.g. returnsnull
on some instances, it would be expected that spaces are not added between this component and its siblings. However I don't know how easy it would be to feature given the current implementation. You would certainly have to inspect thechildren
of the element.The text was updated successfully, but these errors were encountered: