@@ -7,17 +7,41 @@ import TransformerComponent from './TransformerComponent.jsx';
7
7
import Rectangle from './Rectangle.jsx' ;
8
8
9
9
class KonvaStage extends Component {
10
- state = {
11
- x : undefined ,
12
- y : undefined ,
13
- } ;
14
-
15
10
constructor ( props ) {
16
11
super ( props ) ;
12
+ this . state = {
13
+ x : undefined ,
14
+ y : undefined ,
15
+ stageWidth : 1000 ,
16
+ stageHeight : 1000 ,
17
+ } ;
17
18
this . main = createRef ( ) ;
18
19
this . group = createRef ( ) ;
19
20
}
20
21
22
+ componentDidMount ( ) {
23
+ this . checkSize ( ) ;
24
+ // here we should add listener for "container" resize
25
+ // take a look here https://developers.google.com/web/updates/2016/10/resizeobserver
26
+ // for simplicity I will just listen window resize
27
+ window . addEventListener ( 'resize' , this . checkSize ) ;
28
+ }
29
+
30
+ componentWillUnmount ( ) {
31
+ window . removeEventListener ( 'resize' , this . checkSize ) ;
32
+ }
33
+
34
+ checkSize = ( ) => {
35
+ const width = this . container . offsetWidth ;
36
+ const height = this . container . offsetHeight ;
37
+ console . log ( 'setting width: ' , this . state . stageWidth , width ) ;
38
+ console . log ( 'setting height: ' , this . state . heightWidth , height ) ;
39
+ this . setState ( {
40
+ stageWidth : width ,
41
+ stageHeight : height ,
42
+ } ) ;
43
+ } ;
44
+
21
45
handleStageMouseDown = ( e ) => {
22
46
// // clicked on stage - clear selection
23
47
if ( e . target === e . target . getStage ( ) ) {
@@ -37,10 +61,6 @@ class KonvaStage extends Component {
37
61
this . props . changeFocusChild ( { childId : rectChildId } ) ;
38
62
} ;
39
63
40
- componentDidMount ( ) {
41
- // this.props.setImage();
42
- }
43
-
44
64
render ( ) {
45
65
const {
46
66
components,
@@ -56,39 +76,50 @@ class KonvaStage extends Component {
56
76
const { selectedShapeName } = this . state ;
57
77
58
78
return (
59
- < Stage
60
- // ref={(node) => {
61
- // this.stage = node;
62
- // }}
63
- onMouseDown = { this . handleStageMouseDown }
64
- width = { window . innerWidth / 2 }
65
- height = { window . innerHeight }
79
+ < div
80
+ style = { {
81
+ width : '100%' ,
82
+ height : '100%' ,
83
+ // border: '1px solid grey',
84
+ } }
85
+ ref = { ( node ) => {
86
+ this . container = node ;
87
+ } }
66
88
>
67
- < Layer >
68
- { components
69
- . find ( comp => comp . title === focusComponent . title )
70
- . childrenArray . map ( ( child , i ) => (
71
- < Rectangle
72
- key = { `${ i } ${ child . componentName } ` }
73
- components = { components }
74
- componentId = { focusComponent . id }
75
- componentName = { child . componentName }
76
- focusChild = { focusChild }
77
- childId = { child . childId }
78
- x = { child . position . x }
79
- y = { child . position . y }
80
- scaleX = { 1 }
81
- scaleY = { 1 }
82
- width = { child . position . width }
83
- height = { child . position . height }
84
- title = { child . componentName + child . childId }
85
- color = { child . color }
86
- handleTransform = { handleTransform }
87
- draggable = { true }
88
- />
89
- ) ) }
90
- </ Layer >
91
- </ Stage >
89
+ < Stage
90
+ ref = { ( node ) => {
91
+ this . stage = node ;
92
+ } }
93
+ onMouseDown = { this . handleStageMouseDown }
94
+ width = { this . state . stageWidth }
95
+ height = { this . state . stageHeight - 10 }
96
+ >
97
+ < Layer >
98
+ { components
99
+ . find ( comp => comp . title === focusComponent . title )
100
+ . childrenArray . map ( ( child , i ) => (
101
+ < Rectangle
102
+ key = { `${ i } ${ child . componentName } ` }
103
+ components = { components }
104
+ componentId = { focusComponent . id }
105
+ componentName = { child . componentName }
106
+ focusChild = { focusChild }
107
+ childId = { child . childId }
108
+ x = { child . position . x }
109
+ y = { child . position . y }
110
+ scaleX = { 1 }
111
+ scaleY = { 1 }
112
+ width = { child . position . width }
113
+ height = { child . position . height }
114
+ title = { child . componentName + child . childId }
115
+ color = { child . color }
116
+ handleTransform = { handleTransform }
117
+ draggable = { true }
118
+ />
119
+ ) ) }
120
+ </ Layer >
121
+ </ Stage >
122
+ </ div >
92
123
) ;
93
124
}
94
125
}
0 commit comments