I am building sort of an image editor, with Konva. I have a menu where images get selected and added to the stage. It was working normally until I added the possibility to add multiple images.
To publish the code would be very time consuming for anyone to read, but in case anybody has experienced the same problem,...
A function sets a variable 'active' to true when an element gets selected. In the same elements gets selected again, 'active' would get set to false. This works perfectly, the problem appears when I set the element's 'active' variable to false by clicking anywhere around it.
It used to simply get deselected and stay in its place, but now when I deselect it from outside, the whole element turns invisible. I have a 'visible' property on each element too, but it is set to true and it doesn't change during this process.
1. Elements onClick function:
onClick(){
if (this.props.ElementReducer.element === null){
// console.log("There is no element selected || I´m getting selected");
this.setState({
active: true
});
this.props.selectedElement(this.state);
}else{
if (this.props.ElementReducer.element.identity == this.state.identity){
// console.log("I am already selected || I´m getting deselected");
this.setState({
active: false
});
this.props.unSelectedElement();
}else{
// console.log("Something else is selected || I´m getting selected");
this.props.prepareToUnSelectElement();
setTimeout(()=> {
this.props.unSelectedElement();
this.setState({
active: true
});
this.props.selectedElement(this.state);
},10);
}
}
}
2. External deselection function:
deselectElement() {
if (this.props.ElementReducer.selectedId !== -1) {
this.props.prepareToUnSelectElement();
setTimeout(this.props.unSelectedElement, 100);
}
}
Now even though any of them is changing any other property of the elements, and no other function is been called, I don't understand why the elements turn invisible when deselected.
Any ideas or comments are well received, Thanks.
To make it clear, the '2. External deselection function' calls a couple of functions in another component that does the same thing as the '1. Elements onClick function'. Sets the active property to false and it then removes the element from the element's edition reducer file.