File tree Expand file tree Collapse file tree 4 files changed +56
-13
lines changed Expand file tree Collapse file tree 4 files changed +56
-13
lines changed Original file line number Diff line number Diff line change
1
+ import React from 'react'
2
+ import { Spring , animated } from 'react-spring'
3
+ import { TimingAnimation } from '../../../src/addons'
4
+ import { GradientPinkRed as Gradient } from '@vx/gradient'
5
+
6
+ export default class App extends React . Component {
7
+ state = { offset : 0 }
8
+ path = React . createRef ( )
9
+ componentDidMount ( ) {
10
+ this . setState ( { offset : this . path . current . getTotalLength ( ) } )
11
+ }
12
+ render ( ) {
13
+ const { offset } = this . state
14
+ return (
15
+ < svg width = "500" viewBox = "0 0 23 23" >
16
+ < Gradient id = "gradient" />
17
+ < g fill = "transparent" stroke = "url(#gradient)" strokeWidth = "0.2" >
18
+ < Spring
19
+ native
20
+ reset
21
+ from = { { dash : offset } }
22
+ to = { { dash : 0 } }
23
+ impl = { TimingAnimation }
24
+ config = { { duration : 5000 } } >
25
+ { props => (
26
+ < animated . path
27
+ ref = { this . path }
28
+ strokeDasharray = { offset }
29
+ strokeDashoffset = { props . dash }
30
+ d = "M12 17.27L18.18 21l-1.64-7.03L22 9.24l-7.19-.61L12 2 9.19 8.63 2 9.24l5.46 4.73L5.82 21z"
31
+ />
32
+ ) }
33
+ </ Spring >
34
+ </ g >
35
+ </ svg >
36
+ )
37
+ }
38
+ }
Original file line number Diff line number Diff line change @@ -24,7 +24,8 @@ const components = [
24
24
'script' ,
25
25
'auto' ,
26
26
'router' ,
27
- 'scroll' ,
27
+ //'scroll',
28
+ //'dashoffset'
28
29
] . reduce (
29
30
( acc , path ) => ( {
30
31
...acc ,
@@ -37,7 +38,7 @@ const components = [
37
38
)
38
39
39
40
const DEBUG = false
40
- const DebugComponent = components [ 'timing ' ]
41
+ const DebugComponent = components [ 'dashoffset ' ]
41
42
42
43
ReactDOM . render (
43
44
DEBUG ? (
Original file line number Diff line number Diff line change @@ -60,22 +60,25 @@ export default function createAnimatedComponent(Component) {
60
60
this . attachProps ( nextProps )
61
61
}
62
62
63
+ setRef = node => {
64
+ this . node = node
65
+ const forwardRef = this . props . forwardRef
66
+ if ( forwardRef ) {
67
+ // If it's a function, assume it's a ref callback
68
+ if ( typeof forwardRef === 'function' ) forwardRef ( node )
69
+ // If it's an object and has a 'current' property, assume it's a ref object
70
+ else if ( typeof forwardRef === 'object' ) forwardRef . current = node
71
+ }
72
+ }
73
+
63
74
render ( ) {
64
75
const forwardRef = this . props . forwardRef
65
76
const {
66
77
scrollTop,
67
78
scrollLeft,
68
79
...animatedProps
69
80
} = this . _propsAnimated . __getValue ( )
70
- return (
71
- < Component
72
- { ...animatedProps }
73
- ref = { node => {
74
- this . node = node
75
- if ( forwardRef ) forwardRef ( node )
76
- } }
77
- />
78
- )
81
+ return < Component { ...animatedProps } ref = { this . setRef } />
79
82
}
80
83
}
81
84
return React . forwardRef ( ( props , ref ) => (
Original file line number Diff line number Diff line change @@ -101,8 +101,9 @@ Globals.injectApplyAnimatedValues(
101
101
102
102
// Set attributes ...
103
103
for ( let name in attributes ) {
104
- if ( instance . getAttribute ( name ) )
105
- instance . setAttribute ( name , attributes [ name ] )
104
+ let dashCase = name . replace ( / ( [ A - Z ] ) / g, $1 => '-' + $1 . toLowerCase ( ) )
105
+ if ( typeof instance . getAttribute ( dashCase ) !== 'undefined' )
106
+ instance . setAttribute ( dashCase , attributes [ name ] )
106
107
}
107
108
} else return false
108
109
} ,
You can’t perform that action at this time.
0 commit comments