Skip to content

Commit 264f825

Browse files
authored
Merge pull request #25 from ChristianEdwardPadilla/development
resizing children now causes correct changes
2 parents 699832f + dc525c5 commit 264f825

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

src/components/KonvaStage.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class KonvaStage extends Component {
7171
key={`${i}${child.componentName}`}
7272
draggable={false}
7373
selectedShapeName={selectedShapeName}
74+
components={components}
7475
childId={child.childId}
7576
focusChild={focusChild}
7677
focusComponent={focusComponent}

src/components/Rectangle.jsx

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

88
class Rectangle extends Component {
9-
handleResize(componentId, childId, target) {
9+
handleResize(componentId, childId, target, components) {
10+
const focChild = components
11+
.find(comp => comp.id === componentId)
12+
.childrenArray.find(child => child.childId === childId);
13+
1014
const transformation = {
1115
width: target.width() * target.scaleX(),
1216
height: target.height() * target.scaleY(),
17+
x: target.x() + focChild.position.x,
18+
y: target.y() + focChild.position.y,
1319
};
20+
1421
this.props.handleTransform(componentId, childId, transformation);
1522
}
1623

1724
handleDrag(componentId, childId, target) {
25+
console.log(target);
26+
1827
const transformation = {
1928
x: target.x(),
2029
y: target.y(),
2130
};
2231
this.props.handleTransform(componentId, childId, transformation);
2332
}
2433

34+
findDescendants(component) {
35+
36+
}
37+
2538
render() {
2639
const {
2740
color,
@@ -35,6 +48,7 @@ class Rectangle extends Component {
3548
title,
3649
focusChild,
3750
focusComponent,
51+
components,
3852
} = this.props;
3953

4054
// the Group is responsible for dragging of all children
@@ -52,8 +66,9 @@ class Rectangle extends Component {
5266
>
5367
<Rect
5468
name={`${childId}`}
55-
// x={0}
56-
// y={0}
69+
x={0}
70+
y={0}
71+
// absolutePosition={{ x, y }}
5772
childId={childId}
5873
componentId={componentId}
5974
title={title}
@@ -65,14 +80,16 @@ class Rectangle extends Component {
6580
color={color}
6681
// fill={color}
6782
// opacity={0.8}
68-
onTransformEnd={event => this.handleResize(componentId, childId, event.target)}
83+
onTransformEnd={event => this.handleResize(componentId, childId, event.target, components)
84+
}
6985
strokeWidth={4}
7086
strokeScaleEnabled={false}
7187
draggable={false}
7288
/>
7389
<Label>
7490
<Text text={title} fill={'white'} />
7591
</Label>
92+
{}
7693
<Rect
7794
// replace with grandchildren rectangles
7895
scaleX={0.2}

src/utils/componentReducer.util.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ export const addChild = (state, { title }) => {
123123
export const handleTransform = (state, {
124124
componentId, childId, x, y, width, height,
125125
}) => {
126-
console.log('componentId and childId: ', componentId, childId);
127-
console.log('state.focuscomponent: ', state.focusComponent);
128-
126+
// console.log('componentId and childId: ', componentId, childId);
127+
// console.log('state.focuscomponent: ', state.focusComponent);
128+
console.log('incoming x and y: ', x, y);
129129
const child = state.components
130130
.find(comp => comp.id === componentId)
131131
.childrenArray.find(child => child.childId === childId);

0 commit comments

Comments
 (0)