@@ -14,6 +14,22 @@ import { Tween, Timeline, SplitWords, SplitChars, Controls, PlayState } from 're
14
14
15
15
const TimelineStyled = styled . div `` ;
16
16
17
+ const StyledTarget1 = styled . div `
18
+ height: 200px;
19
+ background-color: #accef7;
20
+ ` ;
21
+
22
+ const StyledTarget2 = styled . div `
23
+ height: 50px;
24
+ background-color: #ff4757;
25
+ padding: 50px;
26
+ ` ;
27
+
28
+ const Inline = styled . div `
29
+ display: inline-block;
30
+ font-size: 40px;
31
+ ` ;
32
+
17
33
const TimelinePlayState = ( ) => {
18
34
const [ playing , setPlaying ] = React . useState ( false ) ;
19
35
const [ progress , setProgress ] = React . useState ( 0 ) ;
@@ -147,6 +163,44 @@ const TargetWithNames = forwardRef((props, ref: any) => {
147
163
) ;
148
164
} ) ;
149
165
166
+ const TargetWithNames2 = forwardRef ( ( props , ref : any ) => {
167
+ const div4 = useRef ( null ) ;
168
+ const div5 = useRef < MutableRefObject < any > [ ] > ( [ ] ) ;
169
+ const div6 = useRef ( null ) ;
170
+ useImperativeHandle ( ref , ( ) => ( {
171
+ div4,
172
+ div5,
173
+ div6,
174
+ } ) ) ;
175
+ return (
176
+ < div >
177
+ < div ref = { div4 } > first</ div >
178
+ < SplitChars
179
+ ref = { ( charRef : MutableRefObject < any > ) => div5 . current . push ( charRef ) }
180
+ wrapper = { < span style = { { display : 'inline-block' } } /> }
181
+ >
182
+ second
183
+ </ SplitChars >
184
+ < div ref = { div6 } > third</ div >
185
+ </ div >
186
+ ) ;
187
+ } ) ;
188
+
189
+ const TargetWithNamesCombined = forwardRef ( ( props , ref : any ) => {
190
+ const target1 = useRef ( { } ) ;
191
+ const target2 = useRef ( { } ) ;
192
+ useImperativeHandle ( ref , ( ) => ( {
193
+ ...target1 . current ,
194
+ ...target2 . current ,
195
+ } ) ) ;
196
+ return (
197
+ < >
198
+ < TargetWithNames ref = { target1 } />
199
+ < TargetWithNames2 ref = { target2 } />
200
+ </ >
201
+ ) ;
202
+ } ) ;
203
+
150
204
const TimelineTargets = ( ) => {
151
205
return (
152
206
< Timeline target = { < TargetWithNames /> } >
@@ -159,6 +213,16 @@ const TimelineTargets = () => {
159
213
160
214
//export default TimelineTargets;
161
215
216
+ const ForwardRefComponent = forwardRef ( ( { children } , ref : any ) => {
217
+ return (
218
+ < div >
219
+ < StyledTarget1 ref = { ref } >
220
+ < span > { children } </ span >
221
+ </ StyledTarget1 >
222
+ </ div >
223
+ ) ;
224
+ } ) ;
225
+
162
226
const Component = forwardRef ( ( { children } , ref ?) => {
163
227
const div1 = useRef ( null ) ;
164
228
const div2 = useRef ( null ) ;
@@ -213,34 +277,98 @@ const Out = () => {
213
277
const divRef1 = useCallback ( ref => {
214
278
if ( ref !== null ) {
215
279
// Ref never updates
216
- console . log ( ref ) ;
280
+ // console.log(ref);
217
281
}
218
282
} , [ ] ) ;
219
283
220
284
const divRef2 = useRef ( null ) ;
221
285
222
286
useEffect ( ( ) => {
223
287
// Ref never updates
224
- console . log ( divRef2 . current ) ;
288
+ // console.log(divRef2.current);
225
289
} , [ ] ) ;
226
290
227
291
return (
228
292
< div className = "App" >
229
- < Timeline target = { < TargetWithNames /> } >
230
- < Tween from = { { x : - 100 } } to = { { x : 100 } } >
231
- < div ref = { divRef1 } style = { { width : 200 , height : 200 , background : 'rebeccapurple' } } />
232
- </ Tween >
293
+ < Timeline
294
+ // target={
295
+ // <>
296
+ // <StyledTarget1>
297
+ // <StyledTarget2 />
298
+ // </StyledTarget1>
299
+ // <StyledTarget1>
300
+ // <StyledTarget2 />
301
+ // </StyledTarget1>
302
+ // </>
303
+ // }
304
+ // target={<div style={{ height: '300px', backgroundColor: '#ccc' }} /> }
305
+ // target={<TargetWithNames />}
306
+ target = {
307
+ < >
308
+ < TargetWithNames />
309
+ < TargetWithNames2 />
310
+ </ >
311
+ }
312
+ // target={<TargetWithNamesCombined />}
313
+ // target={
314
+ // <>
315
+ // <TargetWithNames />
316
+ // <ForwardRefComponent>ForwardRefComponent 1</ForwardRefComponent>
317
+ // <ForwardRefComponent>ForwardRefComponent 2</ForwardRefComponent>
318
+ // </>
319
+ // }
320
+ >
321
+ { /*<Tween from={{ x: -100 }} to={{ x: 100 }}>*/ }
322
+ { /* <div ref={divRef1} style={{ width: 200, height: 200, background: 'rebeccapurple' }} />*/ }
323
+ { /*</Tween>*/ }
233
324
234
- < Tween from = { { x : - 100 } } to = { { x : 100 } } >
235
- < div ref = { divRef2 } style = { { width : 200 , height : 200 , background : 'fuchsia' } } />
236
- </ Tween >
325
+ { /* <Tween from={{ x: -100 }} to={{ x: 100 }}>*/ }
326
+ { /* <div ref={divRef2} style={{ width: 200, height: 200, background: 'fuchsia' }} />*/ }
327
+ { /* </Tween>*/ }
237
328
238
329
< Tween to = { { x : '200px' } } target = "div3" position = "0" />
239
330
< Tween to = { { x : '200px' } } target = "div1" position = "0.5" />
240
331
< Tween to = { { x : '200px' } } target = "div2" position = "1" stagger = { 0.1 } />
332
+
333
+ < Tween to = { { x : '200px' } } target = "div6" position = "2" />
334
+ < Tween to = { { x : '200px' } } target = "div4" position = "2.5" />
335
+ < Tween to = { { x : '200px' } } target = "div5" position = "3" stagger = { 0.1 } />
336
+
337
+ { /*<Tween to={{ x: '200px' }} target={3} />*/ }
338
+ { /*<Tween to={{ x: '200px' }} target={4} />*/ }
241
339
</ Timeline >
242
340
</ div >
243
341
) ;
244
342
} ;
245
343
246
- export default Out ;
344
+ //export default Out;
345
+
346
+ const Test = ( ) => {
347
+ // the array gets filled up with every new render!
348
+ // can SplitWords outputs it's refs as array, so that we don't need to push into?
349
+ const ref = useRef < MutableRefObject < any > [ ] > ( [ ] ) ;
350
+
351
+ useEffect ( ( ) => {
352
+ console . log ( ref ) ;
353
+ } , [ ] ) ;
354
+
355
+ return (
356
+ < Controls playState = { PlayState . stop } >
357
+ < Timeline
358
+ target = {
359
+ < Fragment >
360
+ < SplitWords ref = { ( charRef : any ) => ref . current . push ( charRef ) } wrapper = { < Inline /> } >
361
+ This text gets splitted by words.
362
+ </ SplitWords >
363
+ </ Fragment >
364
+ }
365
+ >
366
+ < Tween to = { { y : '-20px' } } position = { 0.5 } duration = { 0.1 } target = { 1 } />
367
+ < Tween to = { { y : '-20px' } } position = "+=0.5" duration = { 0.1 } target = { 3 } />
368
+ < Tween to = { { y : '-20px' } } position = "+=0.5" duration = { 0.1 } target = { 5 } />
369
+ </ Timeline >
370
+ </ Controls >
371
+ ) ;
372
+ } ;
373
+
374
+ export default Test ;
0 commit comments