Skip to content

react-spring, ordering and decoupling #65

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

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions .storybook/stories/List.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
import React from 'react'
import { ComponentStory, ComponentMeta } from '@storybook/react'
import { a } from '@react-spring/three'

import { Flex, Box } from '../../src'
import { Flex, Box, SpringBox } from '../../src'
import { Setup } from '../Setup'

const List = ({ width, height }: { width: number; height: number }) => {
return (
<Flex position={[-width / 2, height / 2, -2]} size={[width, height, 0]} flexDirection="row" flexWrap="wrap">
{new Array(8).fill(undefined).map((_, i) => (
<Box margin={0.3} key={i} width={1.6} height={2} centerAnchor>
{(width, height) => (
<mesh>
<planeBufferGeometry args={[width, height]} />
<meshBasicMaterial color={0x0000ff} />
</mesh>
)}
</Box>
))}
</Flex>
<group position={[-width / 2, height / 2, 0]}>
<Flex size={[width, height, 0]} flexDirection="row" flexWrap="wrap">
{new Array(8).fill(undefined).map((_, i) => (
<SpringBox margin={0.3} key={i} width={1.6} height={2} centerAnchor>
{(width, height) => (
<a.mesh scale-x={width} scale-y={height}>
<planeBufferGeometry args={[1, 1]} />
<meshBasicMaterial color={0x0000ff} />
</a.mesh>
)}
</SpringBox>
))}
</Flex>
</group>
)
}

Expand Down
24 changes: 13 additions & 11 deletions .storybook/stories/NestedBoxes.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box, Flex } from '../../src'
import { AutomaticBox, Box, Flex } from '../../src'
import React, { Suspense } from 'react'
import { ComponentMeta, ComponentStory } from '@storybook/react'
import { Box as Cube } from '@react-three/drei'
Expand All @@ -9,26 +9,28 @@ import { Setup } from '../Setup'
const Block = ({ color1, color2 }: { color1: Color; color2: Color }) => {
return (
<Box alignItems="flex-start" marginLeft={20} flexDirection="row">
<Box centerAnchor>
<AutomaticBox centerAnchor>
<Cube args={[100, 100, 1]}>
<meshBasicMaterial color={color1} />
<meshBasicMaterial toneMapped={false} color={color1} />
</Cube>
</Box>
<Box centerAnchor>
</AutomaticBox>
<AutomaticBox centerAnchor>
<Cube args={[100, 100, 1]}>
<meshBasicMaterial color={color2} />
<meshBasicMaterial toneMapped={false} color={color2} />
</Cube>
</Box>
</AutomaticBox>
</Box>
)
}

const NestedBoxes = ({ width, height }: { width: number; height: number }) => {
return (
<Flex flexDirection="row" position={[-200, 50, -200]}>
<Block color1="red" color2="green" />
<Block color1="yellow" color2="white" />
</Flex>
<group position={[-200, 50, -200]}>
<Flex flexDirection="row">
<Block color1="red" color2="green" />
<Block color1="yellow" color2="white" />
</Flex>
</group>
)
}

Expand Down
55 changes: 32 additions & 23 deletions .storybook/stories/Rotation.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box, Flex } from '../../src'
import { Box, AutomaticBox, ReferenceGroup, Flex } from '../../src'
import React, { Suspense } from 'react'
import { ComponentMeta, ComponentStory } from '@storybook/react'

Expand All @@ -25,28 +25,37 @@ const Rotation = ({
const width = 3
const height = 1
return (
<Flex
size={[width, height, 0]}
flexDirection="row"
flexWrap="no-wrap"
alignItems="stretch"
justifyContent="flex-start"
position={[0, 0, 3]}
rotation={[degToRad(rotationX), degToRad(rotationY), degToRad(rotationZ)]}
>
<Box rotation={[degToRad(rotationXItems), degToRad(rotationYItems), degToRad(rotationZItems)]} centerAnchor>
<mesh scale={1}>
<boxGeometry args={[1, 1, 1]} />
<meshBasicMaterial color="red" wireframe />
</mesh>
</Box>
<Box rotation={[degToRad(rotationXItems), degToRad(rotationYItems), degToRad(rotationZItems)]} centerAnchor>
<mesh>
<boxGeometry args={[1, 1, 1]} />
<meshBasicMaterial color="orange" wireframe />
</mesh>
</Box>
</Flex>
<group position={[0, 0, 3]} rotation={[degToRad(rotationX), degToRad(rotationY), degToRad(rotationZ)]}>
<Flex
size={[width, height, 0]}
flexDirection="row"
flexWrap="no-wrap"
alignItems="stretch"
justifyContent="flex-start"
>
<ReferenceGroup>
<AutomaticBox
rotation={[degToRad(rotationXItems), degToRad(rotationYItems), degToRad(rotationZItems)]}
centerAnchor
>
<mesh>
<boxGeometry args={[1, 1, 1]} />
<meshBasicMaterial color="red" wireframe />
</mesh>
</AutomaticBox>

<AutomaticBox
rotation={[degToRad(rotationXItems), degToRad(rotationYItems), degToRad(rotationZItems)]}
centerAnchor
>
<mesh>
<boxGeometry args={[1, 1, 1]} />
<meshBasicMaterial color="orange" wireframe />
</mesh>
</AutomaticBox>
</ReferenceGroup>
</Flex>
</group>
)
}

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"prettier": "^2.0.5",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"@react-spring/three": "^9.2.4",
"rimraf": "^3.0.2",
"rollup": "^2.26.10",
"rollup-plugin-filesize": "^9.1.1",
Expand All @@ -113,6 +114,7 @@
"peerDependencies": {
"@react-three/fiber": ">=6.0",
"react": "^17.0.2",
"@react-spring/three": "^9.2.4",
"three": ">=0.126"
}
}
Loading