Skip to content

Commit 9c1fa2b

Browse files
naive recursive rendering working
1 parent 87baba0 commit 9c1fa2b

File tree

2 files changed

+48
-28
lines changed

2 files changed

+48
-28
lines changed

src/components/KonvaStage.jsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,21 @@ class KonvaStage extends Component {
6969
.childrenArray.map((child, i) => (
7070
<Rectangle
7171
key={`${i}${child.componentName}`}
72-
draggable={false}
73-
selectedShapeName={selectedShapeName}
7472
components={components}
75-
childId={child.childId}
76-
focusChild={focusChild}
77-
focusComponent={focusComponent}
7873
componentId={focusComponent.id}
74+
componentName={child.componentName}
75+
focusChild={focusChild}
76+
childId={child.childId}
7977
x={child.position.x}
8078
y={child.position.y}
79+
scaleX={1}
80+
scaleY={1}
8181
width={child.position.width}
8282
height={child.position.height}
8383
title={child.componentName + child.childId}
8484
color={child.color}
8585
handleTransform={handleTransform}
86+
draggable={true}
8687
/>
8788
))}
8889
</Layer>

src/components/Rectangle.jsx

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import TransformerComponent from './TransformerComponent.jsx';
66
// import PropTypes from 'prop-types';
77

88
class Rectangle extends Component {
9-
handleResize(componentId, childId, target, components) {
10-
const focChild = components
9+
handleResize(componentId, childId, target) {
10+
const focChild = this.props.components
1111
.find(comp => comp.id === componentId)
1212
.childrenArray.find(child => child.childId === childId);
1313

@@ -31,42 +31,41 @@ class Rectangle extends Component {
3131
this.props.handleTransform(componentId, childId, transformation);
3232
}
3333

34-
findDescendants(component, components, descendants = []) {
35-
// fix this stuff Adam
36-
if (!component) return;
37-
component.childrenArray.forEach((child) => {
38-
descendants.push(child);
39-
const childComponent = components.find(comp => comp.title === child.componentName);
40-
this.findDescendants(childComponent, components, descendants);
41-
});
42-
return descendants;
34+
getComponentOfThisChild() {
35+
console.log('title of this child: ', componentName);
36+
console.log(
37+
'component of this child: ',
38+
this.props.components.find(comp => comp.title === componentName),
39+
);
4340
}
4441

4542
render() {
4643
const {
4744
color,
4845
x,
4946
y,
47+
scaleX,
48+
scaleY,
5049
childId,
5150
componentId,
52-
draggable,
51+
componentName,
5352
width,
5453
height,
5554
title,
5655
focusChild,
57-
focusComponent,
5856
components,
57+
draggable,
5958
} = this.props;
6059

6160
// the Group is responsible for dragging of all children
6261
// the Rect emits changes to child width and height with help from Transformer
6362
return (
6463
<Group
65-
draggable={true}
64+
draggable={draggable}
6665
x={x}
6766
y={y}
68-
scaleX={1}
69-
scaleY={1}
67+
scaleX={scaleX}
68+
scaleY={scaleY}
7069
width={width}
7170
height={height}
7271
onDragEnd={event => this.handleDrag(componentId, childId, event.target)}
@@ -87,17 +86,37 @@ class Rectangle extends Component {
8786
color={color}
8887
// fill={color}
8988
// opacity={0.8}
90-
onTransformEnd={event => this.handleResize(componentId, childId, event.target, components)
91-
}
89+
onTransformEnd={event => this.handleResize(componentId, childId, event.target)}
9290
strokeWidth={4}
9391
strokeScaleEnabled={false}
9492
draggable={false}
9593
/>
9694
<Label>
9795
<Text text={title} fill={'white'} />
9896
</Label>
99-
{/* {this.findDescendants().map} */}
100-
<Rect
97+
{components
98+
.find(comp => comp.title === componentName)
99+
.childrenArray.map((grandchild, i) => (
100+
<Rectangle
101+
key={i}
102+
components={components}
103+
componentId={componentId}
104+
componentName={grandchild.componentName}
105+
focusChild={focusChild}
106+
childId={grandchild.childId}
107+
x={grandchild.position.x}
108+
y={grandchild.position.y}
109+
scaleX={0.8}
110+
scaleY={0.8}
111+
width={grandchild.position.width}
112+
height={grandchild.position.height}
113+
// title={child.componentName + child.childId}
114+
color={color}
115+
handleTransform={() => {}}
116+
draggable={false}
117+
/>
118+
))}
119+
{/* <Rect
101120
// replace with grandchildren rectangles
102121
scaleX={0.2}
103122
scaleY={0.2}
@@ -107,9 +126,9 @@ class Rectangle extends Component {
107126
color={color}
108127
strokeWidth={4}
109128
draggable={false}
110-
/>
111-
{focusChild.childId === childId ? (
112-
<TransformerComponent focusComponent={focusComponent} focusChild={focusChild} />
129+
/> */}
130+
{focusChild.childId === childId && draggable ? (
131+
<TransformerComponent focusChild={focusChild} />
113132
) : (
114133
<Label />
115134
)}

0 commit comments

Comments
 (0)