pmndrs / react-three-flex

💪📦 Flexbox for react-three-fiber
MIT License
1.65k stars 42 forks source link

disableSizeRecalc option in Flex #49

Closed bbohlender closed 3 years ago

bbohlender commented 3 years ago

Fixes #48

Option to disable the automatic calculation of the bounding box, through the Flex-Element. Allows the developer to talk to the yoga node directly and change the node's size without any rerender from react and gives much more control over the yoga node.

I've also added 3 hooks:

useSetSize and useSyncGeometrySize might be very specific, but useNode would be required to make these implementations (since I think the context is not exported). Having the useSyncGeometrySize hook allows to implement sth. like this:

import React from "react"
import { useSyncGeometrySize } from "@react-three/flex"
import { Text } from "@react-three/drei"

export function FlexText({ ...props }: React.ComponentProps<typeof Text>) {
    const onSync = useSyncGeometrySize()
    return (
        <Text onSync={onSync} {...props} />
    )
}

which would then be used inside a flex & box element:

<Flex disableSizeRecalc><Box><FlexText>Hello World!</FlexText></Box></Flex>

But as soon as someone uses disableSizeRecalc he now has to have every element declare its own size explicitly (which is intended in this case).

giulioz commented 3 years ago

Is it ready for merge now?

bbohlender commented 3 years ago

Is it ready for merge now?

Regarding the prettier change, it seems like it's done automatically by the pre-commit pipeline. So I can't remove the prettier change directly. If that's fine, then the PR would be done. 😄 Thank you for your fast responses 👍