Skip to content

Commit ab22e20

Browse files
committed
[core] adapts to react-use-gesture
1 parent 111bd7e commit ab22e20

File tree

136 files changed

+1813
-9224
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+1813
-9224
lines changed

CNAME

-1
This file was deleted.

README.md

+14-9
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,31 @@ Demos will be live at http://localhost:8080
88
# Contributors
99

1010
1. clone react-spring and react-spring-examples under the same root folder
11-
````
11+
12+
```
1213
/root
13-
/react-spring
14-
/react-spring-examples
15-
````
14+
/react-use-gesture
15+
/react-use-gesture-examples
16+
```
17+
1618
2. yarn/npm install both
17-
3. cd react-spring-examples
19+
3. cd react-use-gesture-examples
1820
4. edit index.js
19-
````
21+
22+
```
2023
import examples from './components/examples-tests'
2124
2225
//const DEBUG = false
2326
const DEBUG = 'latestbug'
24-
````
27+
```
28+
2529
5. go to /demos/tests/latestbug and set up a demo that reproduces the problem
2630
6. npm start, you can now make hot-reload edits in both repos (react-spring and react-spring-examples)
2731
7. you can test integrity by running all examples, edit index.js again:
28-
````
32+
33+
```
2934
import examples from './components/examples-hooks'
3035
3136
const DEBUG = false
3237
//const DEBUG = 'latestbug'
33-
````
38+
```

components/Demo.js

+19-17
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,25 @@ export default class Demo extends React.Component {
3333
})
3434
}
3535

36-
setVisible = ({ isIntersecting }) => this.setState({ visible: isIntersecting })
36+
setVisible = ({ isIntersecting }) =>
37+
this.setState({ visible: isIntersecting })
3738

38-
enter = tag => this.props.code && this.props.code[tag] && this.setState({ code: this.props.code[tag] })
39+
enter = tag =>
40+
this.props.code &&
41+
this.props.code[tag] &&
42+
this.setState({ code: this.props.code[tag] })
3943
leave = tag => this.setState({ code: undefined })
4044

4145
render() {
42-
const { title, description, tags, link, code, overlayCode = true, fullscreen = false } = this.props
46+
const {
47+
title,
48+
description,
49+
tags,
50+
link,
51+
code,
52+
overlayCode = true,
53+
fullscreen = false,
54+
} = this.props
4355
return (
4456
<Container fullscreen={fullscreen}>
4557
<Header>
@@ -72,18 +84,7 @@ export default class Demo extends React.Component {
7284
<Content>
7385
<ErrorBoundary>
7486
<Observer onChange={this.setVisible}>
75-
<div>
76-
{this.state.visible && <this.component />}
77-
78-
{/*overlayCode && (
79-
<Spring
80-
native
81-
from={{ opacity: 0 }}
82-
to={{ opacity: this.state.code ? 1 : 0 }}>
83-
{props => <Code style={props} children={this.state.code} />}
84-
</Spring>
85-
)*/}
86-
</div>
87+
<div>{this.state.visible && <this.component />}</div>
8788
</Observer>
8889
</ErrorBoundary>
8990
</Content>
@@ -102,8 +103,9 @@ const Container = styled('div')`
102103

103104
const Header = styled('div')`
104105
margin-bottom: 10px;
105-
font-family: 'Chinese Quote', -apple-system, system-ui, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB',
106-
'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji',
106+
font-family: 'Chinese Quote', -apple-system, system-ui, 'Segoe UI',
107+
'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Helvetica Neue',
108+
Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji',
107109
'Segoe UI Symbol';
108110
109111
& > h1 {

components/examples-hooks.js

+7-234
Original file line numberDiff line numberDiff line change
@@ -1,249 +1,22 @@
11
export default [
2-
{
3-
name: 'hooks/goo',
4-
title: 'Goo blobs',
5-
link: 'https://codesandbox.io/embed/8zx4ppk01l',
6-
tags: ['useTrail'],
7-
code: {
8-
useSpring: `const [trail, set] = useTrail(3, () => ({ xy: [0, 0] }))
9-
const tr = (x, y) => \`translate3d(\${x}px,\${y}px,0)\`
10-
return (
11-
<div onMouseMove={({ clientX: x, clientY: y }) => set({ p1: [x, y] })}>
12-
{trail.map(({ xy }, index) => (
13-
<animated.div key={index} style={{ transform: xy.interpolate(tr) }} />
14-
))}
15-
</div>
16-
)`,
17-
},
18-
},
19-
{
20-
name: 'hooks/card',
21-
title: '3D card',
22-
link: 'https://codesandbox.io/embed/rj998k4vmm',
23-
tags: ['useSpring'],
24-
code: {
25-
useSpring: `const [props, set] = useSpring(() => ({ xys: [0, 0, 1] }))
26-
const calc = (x, y) => [-(y - height / 2), (x - width / 2), 1.1]
27-
const trans = (x, y, s) =>
28-
\`perspective(600px) rotateX(\${x}deg) rotateY(\${y}deg) scale(\${s})\`
29-
return (
30-
<animated.div
31-
onMouseMove={({ clientX: x, clientY: y }) => set({ xys: calc(x, y) })}
32-
onMouseLeave={() => set({ xys: [0, 0, 1] })}
33-
style={{ transform: props.xys.interpolate(trans) }}
34-
/>
35-
)`,
36-
},
37-
},
38-
{
39-
name: 'hooks/flip-card',
40-
title: 'Flip card',
41-
link: 'https://codesandbox.io/embed/01yl7knw70',
42-
tags: ['useSpring'],
43-
code: {
44-
useSpring: `const { transform, opacity } = useSpring({
45-
opacity: flipped ? 1 : 0,
46-
transform: \`perspective(1400px) rotateX(\${flipped ? 180 : 0}deg)\`,
47-
})
48-
return (
49-
<a.div style={{ opacity: opacity.interpolate(o => 1 - o), transform }} />
50-
<a.div style={{ opacity, transform: transform.interpolate(t =>
51-
\`\${t} rotateX(180deg)\`) }} />
52-
)`,
53-
},
54-
},
55-
{
56-
name: 'hooks/slider',
57-
title: 'Gesture slider',
58-
link: 'https://codesandbox.io/embed/zrj66y8714',
59-
tags: ['useSpring'],
60-
code: {
61-
useSpring: `const { x, bg, size } = useSpring({
62-
x: down ? xDelta : 0,
63-
size: down ? 1.1 : 1,
64-
immediate: name => down && name === 'x'
65-
})
66-
const transform =
67-
interpolate([x, size], (x, s) => \`translate3d(\${x}px,0,0) scale(\${s})\`)
68-
return <animated.div style={{ transform }} children="Slide">`,
69-
},
70-
},
712
{
723
name: 'hooks/draggable-list',
734
title: 'Draggable list',
74-
link: 'https://codesandbox.io/embed/r5qmj8m6lq',
755
tags: ['useSprings'],
766
},
777
{
78-
name: 'hooks/mouse-parallax',
79-
title: 'Mouse parallax',
80-
link: 'https://codesandbox.io/embed/r5x34869vq',
81-
tags: ['useSpring'],
82-
},
83-
{
84-
name: 'hooks/scroll-parallax',
85-
title: 'Scroll parallax',
86-
link: 'https://codesandbox.io/embed/py912w5k6m',
87-
tags: ['useSpring'],
88-
},
89-
{
90-
name: 'hooks/trails',
91-
title: 'Trails',
92-
link: 'https://codesandbox.io/embed/zn2q57vn13',
93-
tags: ['useTrail'],
94-
code: {
95-
useTrail: `const trail = useTrail(items.length, {
96-
items,
97-
opacity: toggle ? 1 : 0,
98-
x: toggle ? 0 : 20,
99-
height: toggle ? 80 : 0,
100-
from: { opacity: 0, x: 20, height: 0 },
101-
})
102-
const transform = x.interpolate(x => \`translate3d(0,\${x}px,0)\`)
103-
return trail.map(({ x, height, opacity }, index) => (
104-
<animated.div key={item} style={{ opacity, transform }}>
105-
<animated.div style={{ height }}>{items[index]}</animated.div>
106-
</animated.div>
107-
))`,
108-
},
109-
},
110-
{
111-
name: 'hooks/simple-transition',
112-
title: 'Simple transition',
113-
link: 'https://codesandbox.io/embed/1y3yyqpq7q',
114-
tags: ['useTransition'],
115-
code: {
116-
useTransition: `const transitions = useTransition({
117-
items: pages[index],
118-
from: { opacity: 0, transform: 'translate3d(100%,0,0)' },
119-
enter: { opacity: 1, transform: 'translate3d(0%,0,0)' },
120-
leave: { opacity: 0, transform: 'translate3d(-50%,0,0)' },
121-
})
122-
return transitions.map(({ item: Page, props, key }) => (
123-
<Page key={key} style={props} />
124-
))`,
125-
},
126-
},
127-
{
128-
name: 'hooks/image-fade',
129-
title: 'Image fade',
130-
link: 'https://codesandbox.io/embed/morr206pv8',
131-
tags: ['useTransition'],
132-
code: {
133-
useTransition: `const transitions = useTransition({
134-
items: slides[index],
135-
keys: item => item.id,
136-
from: { opacity: 0 },
137-
enter: { opacity: 1 },
138-
leave: { opacity: 0 },
139-
})
140-
return transitions.map(({ item, props, key }) => (
141-
<animated.div
142-
key={key}
143-
style={{ ...props, backgroundImage: \`url(\${item.url})\` }}
144-
/>
145-
))`,
146-
},
147-
},
148-
{
149-
name: 'hooks/multistage-transitions',
150-
title: 'Multistage transitions',
151-
link: 'https://codesandbox.io/embed/vqpqx5vrl0',
152-
tags: ['useTransition'],
153-
},
154-
{
155-
name: 'hooks/keyframes',
156-
title: 'Emulating css keyframes',
157-
link: 'https://codesandbox.io/embed/88lmnl6w88',
158-
tags: ['useSpring'],
159-
},
160-
{
161-
name: 'hooks/list-reordering',
162-
title: 'List-reordering',
163-
link: 'https://codesandbox.io/embed/1wqpz5mzqj',
164-
tags: ['useTransition'],
165-
},
166-
{
167-
name: 'hooks/chain-animation',
168-
title: 'Chain animation',
169-
link: 'https://codesandbox.io/embed/2v716k56pr',
170-
tags: ['useChain'],
171-
},
172-
{
173-
name: 'hooks/notification-hub',
174-
title: 'Notification hub',
175-
link: 'https://codesandbox.io/embed/7mqy09jyq',
176-
tags: ['useTransition'],
177-
},
178-
{
179-
name: 'hooks/script',
180-
title: 'Spring scripting',
181-
link: 'https://codesandbox.io/embed/141nrz6v73',
182-
tags: ['useSpring'],
183-
},
184-
{
185-
name: 'hooks/auto',
186-
title: 'Animating auto',
187-
link: 'https://codesandbox.io/embed/q3ypxr5yp4',
188-
tags: ['useSpring'],
189-
},
190-
{
191-
name: 'hooks/tree',
192-
title: 'Treeview (nested auto)',
193-
link: 'https://codesandbox.io/embed/lp80n9z7v9',
194-
tags: ['useSpring'],
195-
},
196-
{
197-
name: 'hooks/blackflag',
198-
title: 'Spring reset script',
199-
link: 'https://codesandbox.io/embed/8ypj5vq6m9',
200-
tags: ['useSpring'],
201-
code: {
202-
useKeyframes: `const interp = i => r =>
203-
\`translate3d(0, \${15 * Math.sin(r + (i * 2 * Math.PI) / 1.6)}px, 0)\`
204-
const useScript = useKeyframes.spring(async next => {
205-
while (1)
206-
await next({
207-
r: 2 * Math.PI,
208-
from: { r: 0 },
209-
config: { duration: 3500 },
210-
reset: true,
211-
})
212-
})
213-
214-
const props = useScript()
215-
return items.map(i =>
216-
<animated.div style={{ transform: props.r.interpolate(interp(i)) }} />)`,
217-
},
218-
},
219-
{
220-
name: 'hooks/gestures-pull',
221-
title: 'Gestures (pull & release)',
222-
link: 'https://codesandbox.io/embed/r24mzvo3q',
223-
tags: ['useSpring'],
224-
},
225-
{
226-
name: 'hooks/gestures-pager',
227-
title: 'View pager',
228-
link: 'https://codesandbox.io/embed/n9vo1my91p',
8+
name: 'hooks/card',
9+
title: 'Multi-gesture card',
22910
tags: ['useSprings'],
23011
},
23112
{
232-
name: 'hooks/card-flick',
233-
title: 'Card stack',
234-
link: 'https://codesandbox.io/embed/j0y0vpz59',
13+
name: 'hooks/viewpager',
14+
title: 'Viewpager',
23515
tags: ['useSprings'],
23616
},
23717
{
238-
name: 'hooks/masonry-grid',
239-
title: 'Masonry grid',
240-
link: 'https://codesandbox.io/embed/26mjowzpr',
241-
tags: ['useTransition'],
242-
},
243-
{
244-
name: 'hooks/liquid',
245-
title: 'Svg filter',
246-
link: 'https://codesandbox.io/embed/rloj7nw3pn',
247-
tags: ['useSpring'],
18+
name: 'hooks/cards',
19+
title: 'Deck of cards',
20+
tags: ['useSprings'],
24821
},
24922
]

0 commit comments

Comments
 (0)