Skip to content

Commit cedb4e6

Browse files
committed
[#119] Object centered rotation
1 parent 565c7f7 commit cedb4e6

File tree

6 files changed

+342
-284
lines changed

6 files changed

+342
-284
lines changed

src/components/canvas/Canvas.tsx

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import ResizeObserver from 'resize-observer-polyfill';
55
import union from 'lodash/union';
66

77
import Handler, { HandlerOptions } from './handlers/Handler';
8-
import { FabricCanvas, WorkareaObject } from './utils';
8+
import { FabricCanvas, WorkareaObject, FabricObjectOption } from './utils';
99

1010
import '../../styles/core/canvas.less';
1111
import '../../styles/core/tooltip.less';
@@ -69,6 +69,12 @@ const defaultWorkareaOption: Partial<WorkareaObject> = {
6969
isElement: false,
7070
};
7171

72+
const defaultObjectOption: Partial<FabricObjectOption> = {
73+
rotation: 0,
74+
centeredRotation: true,
75+
strokeUniform: true,
76+
};
77+
7278
const defaultPropertiesToInclude = ['id', 'name', 'locke', 'editable'];
7379

7480
export type CanvasProps = HandlerOptions & {
@@ -95,7 +101,7 @@ class Canvas extends Component<CanvasProps, IState> {
95101
canvasOption: {
96102
selection: true,
97103
},
98-
defaultOption: {},
104+
defaultOption: defaultObjectOption,
99105
activeSelection: {
100106
hasControls: true,
101107
},
@@ -153,7 +159,7 @@ class Canvas extends Component<CanvasProps, IState> {
153159
canvasOption: mergedCanvasOption,
154160
guidelineOption,
155161
editable,
156-
defaultOption,
162+
defaultOption: Object.assign({}, defaultObjectOption, defaultOption),
157163
propertiesToInclude: mergedPropertiesToInclude,
158164
gridOption: Object.assign({}, defaultGripOption, gridOption),
159165
width,
@@ -252,12 +258,16 @@ class Canvas extends Component<CanvasProps, IState> {
252258
};
253259

254260
handleLoad = () => {
255-
if (this.props.onLoad) {
256-
this.props.onLoad(this.handler, this.canvas);
257-
}
258-
this.setState({
259-
loaded: true,
260-
});
261+
this.setState(
262+
{
263+
loaded: true,
264+
},
265+
() => {
266+
if (this.props.onLoad) {
267+
this.props.onLoad(this.handler, this.canvas);
268+
}
269+
},
270+
);
261271
};
262272

263273
render() {

0 commit comments

Comments
 (0)