Skip to content
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

Nested flex #13

Merged
merged 7 commits into from
Sep 3, 2020
Merged

Nested flex #13

merged 7 commits into from
Sep 3, 2020

Conversation

giulioz
Copy link
Member

@giulioz giulioz commented Sep 2, 2020

Closes #10
and also regards #7 if some optimizations are considered

This fixes some things to make nested Flexbox work again properly.
README is still a WIP.

This changes nested flex semantic:

OLD

<Flex flexDirection="row" flexWrap="wrap" size={[50, 0, 0]}>
  <Box>
    <Flex flexDirection="column" flexWrap="no-wrap">
      <Box>
        <mesh geometry={sphere} />
      </Box>
      <Box>
        <mesh geometry={box} />
      </Box>
    </Flex>
  </Box>
</Flex>

NEW

<Flex flexDirection="row" flexWrap="wrap" size={[50, 0, 0]}>
  <Box flexDirection="column" flexWrap="no-wrap">
    <Box>
      <mesh geometry={sphere} />
    </Box>
    <Box>
      <mesh geometry={box} />
    </Box>
  </Box>
</Flex>

@@ -125,14 +184,14 @@ export function Box({
// Make child known to the parents yoga instance *before* it calculates layout
useLayoutEffect(() => {
parent.insertChild(node, parent.getChildCount())
registerBox(group.current, node)
registerBox(group.current, node, flexProps, centerAnchor)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that passing flexProps can be a bit slow BTW

@@ -15,6 +15,7 @@ import { useReflow } from './Flex'
export function Box({
// Non-flex props
children,
centerAnchor,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

centerAnchor is a new prop that you have to set if your children has position centered.
While a inside another is relative to the upper left corner, all THREE standard shapes are referred to the center.

src/Flex.tsx Outdated
boundingBox.setFromObject(group).getSize(vec)
node.setWidth(vec[state.mainAxis])
node.setHeight(vec[state.crossAxis])
node.setWidth(flexProps.width || vec[state.mainAxis])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way we can force width and height directly, ignoring the content bounding box.
This could be optimized preventing the bounding box calculation if props are present.

@giulioz giulioz force-pushed the nested-flex branch 2 times, most recently from 6e0ab8a to 4735f2e Compare September 3, 2020 09:19
@giulioz giulioz changed the title Nested flex (WIP) Nested flex Sep 3, 2020
@giulioz giulioz merged commit 412338d into master Sep 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nested Flex not working
1 participant