@@ -18,6 +18,11 @@ type DraggableState = {
18
18
isElementSVG : boolean
19
19
} ;
20
20
21
+ type ConstructorProps = {
22
+ position : { x : number , y : number } ,
23
+ defaultPosition : { x : number , y : number }
24
+ }
25
+
21
26
//
22
27
// Define <Draggable>
23
28
//
@@ -145,22 +150,28 @@ export default class Draggable extends React.Component {
145
150
position : null
146
151
} ;
147
152
148
- state : DraggableState = {
149
- // Whether or not we are currently dragging.
150
- dragging : false ,
153
+ state : DraggableState ;
151
154
152
- // Whether or not we have been dragged before.
153
- dragged : false ,
155
+ constructor ( props : ConstructorProps ) {
156
+ super ( props ) ;
157
+
158
+ this . state = {
159
+ // Whether or not we are currently dragging.
160
+ dragging : false ,
154
161
155
- // Current transform x and y.
156
- x : this . props . position ? this . props . position . x : this . props . defaultPosition . x ,
157
- y : this . props . position ? this . props . position . y : this . props . defaultPosition . y ,
162
+ // Whether or not we have been dragged before.
163
+ dragged : false ,
158
164
159
- // Used for compensating for out-of-bounds drags
160
- slackX : 0 , slackY : 0 ,
165
+ // Current transform x and y.
166
+ x : props . position ? props . position . x : props . defaultPosition . x ,
167
+ y : props . position ? props . position . y : props . defaultPosition . y ,
161
168
162
- // Can only determine if SVG after mounting
163
- isElementSVG : false
169
+ // Used for compensating for out-of-bounds drags
170
+ slackX : 0 , slackY : 0 ,
171
+
172
+ // Can only determine if SVG after mounting
173
+ isElementSVG : false
174
+ } ;
164
175
} ;
165
176
166
177
componentWillMount ( ) {
@@ -327,4 +338,3 @@ export default class Draggable extends React.Component {
327
338
) ;
328
339
}
329
340
}
330
-
0 commit comments