Add component will unmount to deactivate to all tools ()

This commit is contained in:
DD Liu 2018-09-11 10:35:08 -04:00 committed by GitHub
parent 2b462eb676
commit 45018e4f64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 89 additions and 8 deletions

View file

@ -142,10 +142,6 @@ $border-radius: 0.25rem;
margin-left: calc(2 * $grid-unit);
}
.hidden {
display: none;
}
.zoom-controls {
display: flex;
flex-direction: row-reverse;

View file

@ -132,8 +132,8 @@ const PaintEditorComponent = props => (
<div className={styles.topAlignRow}>
{/* Modes */}
{props.canvas !== null ? ( // eslint-disable-line no-negated-condition
<div className={isVector(props.format) ? styles.modeSelector : styles.hidden}>
{props.canvas !== null && isVector(props.format) ? ( // eslint-disable-line no-negated-condition
<div className={styles.modeSelector}>
<SelectMode
onUpdateImage={props.onUpdateImage}
/>
@ -165,8 +165,8 @@ const PaintEditorComponent = props => (
</div>
) : null}
{props.canvas !== null ? ( // eslint-disable-line no-negated-condition
<div className={isBitmap(props.format) ? styles.modeSelector : styles.hidden}>
{props.canvas !== null && isBitmap(props.format) ? ( // eslint-disable-line no-negated-condition
<div className={styles.modeSelector}>
<BitBrushMode
onUpdateImage={props.onUpdateImage}
/>

View file

@ -44,6 +44,11 @@ class BitBrushMode extends React.Component {
shouldComponentUpdate (nextProps) {
return nextProps.isBitBrushModeActive !== this.props.isBitBrushModeActive;
}
componentWillUnmount () {
if (this.tool) {
this.deactivateTool();
}
}
activateTool () {
clearSelection(this.props.clearSelectedItems);
this.props.clearGradient();

View file

@ -38,6 +38,11 @@ class BitEraserMode extends React.Component {
shouldComponentUpdate (nextProps) {
return nextProps.isBitEraserModeActive !== this.props.isBitEraserModeActive;
}
componentWillUnmount () {
if (this.tool) {
this.deactivateTool();
}
}
activateTool () {
clearSelection(this.props.clearSelectedItems);
this.tool = new BitBrushTool(

View file

@ -51,6 +51,11 @@ class BitFillMode extends React.Component {
shouldComponentUpdate (nextProps) {
return nextProps.isFillModeActive !== this.props.isFillModeActive;
}
componentWillUnmount () {
if (this.tool) {
this.deactivateTool();
}
}
activateTool () {
clearSelection(this.props.clearSelectedItems);

View file

@ -44,6 +44,11 @@ class BitLineMode extends React.Component {
shouldComponentUpdate (nextProps) {
return nextProps.isBitLineModeActive !== this.props.isBitLineModeActive;
}
componentWillUnmount () {
if (this.tool) {
this.deactivateTool();
}
}
activateTool () {
clearSelection(this.props.clearSelectedItems);
this.props.clearGradient();

View file

@ -53,6 +53,11 @@ class BitOvalMode extends React.Component {
shouldComponentUpdate (nextProps) {
return nextProps.isOvalModeActive !== this.props.isOvalModeActive;
}
componentWillUnmount () {
if (this.tool) {
this.deactivateTool();
}
}
activateTool () {
clearSelection(this.props.clearSelectedItems);
this.props.clearGradient();

View file

@ -53,6 +53,11 @@ class BitRectMode extends React.Component {
shouldComponentUpdate (nextProps) {
return nextProps.isRectModeActive !== this.props.isRectModeActive;
}
componentWillUnmount () {
if (this.tool) {
this.deactivateTool();
}
}
activateTool () {
clearSelection(this.props.clearSelectedItems);
this.props.clearGradient();

View file

@ -39,6 +39,11 @@ class BitSelectMode extends React.Component {
shouldComponentUpdate (nextProps) {
return nextProps.isSelectModeActive !== this.props.isSelectModeActive;
}
componentWillUnmount () {
if (this.tool) {
this.deactivateTool();
}
}
activateTool () {
this.props.clearGradient();
this.tool = new BitSelectTool(

View file

@ -45,6 +45,11 @@ class BrushMode extends React.Component {
shouldComponentUpdate (nextProps) {
return nextProps.isBrushModeActive !== this.props.isBrushModeActive;
}
componentWillUnmount () {
if (this.blob.tool) {
this.deactivateTool();
}
}
activateTool () {
// TODO: Instead of clearing selection, consider a kind of "draw inside"
// analogous to how selection works with eraser

View file

@ -39,6 +39,11 @@ class EraserMode extends React.Component {
shouldComponentUpdate (nextProps) {
return nextProps.isEraserModeActive !== this.props.isEraserModeActive;
}
componentWillUnmount () {
if (this.blob.tool) {
this.deactivateTool();
}
}
activateTool () {
this.blob.activateTool({isEraser: true, ...this.props.eraserModeState});
}

View file

@ -55,6 +55,11 @@ class FillMode extends React.Component {
shouldComponentUpdate (nextProps) {
return nextProps.isFillModeActive !== this.props.isFillModeActive;
}
componentWillUnmount () {
if (this.tool) {
this.deactivateTool();
}
}
activateTool () {
clearSelection(this.props.clearSelectedItems);

View file

@ -51,6 +51,11 @@ class LineMode extends React.Component {
shouldComponentUpdate (nextProps) {
return nextProps.isLineModeActive !== this.props.isLineModeActive;
}
componentWillUnmount () {
if (this.tool) {
this.deactivateTool();
}
}
activateTool () {
clearSelection(this.props.clearSelectedItems);

View file

@ -46,6 +46,11 @@ class OvalMode extends React.Component {
shouldComponentUpdate (nextProps) {
return nextProps.isOvalModeActive !== this.props.isOvalModeActive;
}
componentWillUnmount () {
if (this.tool) {
this.deactivateTool();
}
}
activateTool () {
clearSelection(this.props.clearSelectedItems);
this.props.clearGradient();

View file

@ -46,6 +46,11 @@ class RectMode extends React.Component {
shouldComponentUpdate (nextProps) {
return nextProps.isRectModeActive !== this.props.isRectModeActive;
}
componentWillUnmount () {
if (this.tool) {
this.deactivateTool();
}
}
activateTool () {
clearSelection(this.props.clearSelectedItems);
this.props.clearGradient();

View file

@ -39,6 +39,11 @@ class ReshapeMode extends React.Component {
shouldComponentUpdate (nextProps) {
return nextProps.isReshapeModeActive !== this.props.isReshapeModeActive;
}
componentWillUnmount () {
if (this.tool) {
this.deactivateTool();
}
}
activateTool () {
this.tool = new ReshapeTool(
this.props.setHoveredItem,

View file

@ -39,6 +39,11 @@ class RoundedRectMode extends React.Component {
shouldComponentUpdate (nextProps) {
return nextProps.isRoundedRectModeActive !== this.props.isRoundedRectModeActive;
}
componentWillUnmount () {
if (this.tool) {
this.deactivateTool();
}
}
activateTool () {
this.tool = new RoundedRectTool(
this.props.setHoveredItem,

View file

@ -43,6 +43,11 @@ class SelectMode extends React.Component {
shouldComponentUpdate (nextProps) {
return nextProps.isSelectModeActive !== this.props.isSelectModeActive;
}
componentWillUnmount () {
if (this.tool) {
this.deactivateTool();
}
}
activateTool () {
this.tool = new SelectTool(
this.props.setHoveredItem,

View file

@ -64,6 +64,11 @@ class TextMode extends React.Component {
shouldComponentUpdate (nextProps) {
return nextProps.isTextModeActive !== this.props.isTextModeActive;
}
componentWillUnmount () {
if (this.tool) {
this.deactivateTool();
}
}
activateTool (nextProps) {
const selected = getSelectedLeafItems();
let textBoxToStartEditing = null;