Skip to content

Commit

Permalink
feat: add startFixedDirection property on before event
Browse files Browse the repository at this point in the history
  • Loading branch information
daybrush committed Jul 25, 2022
1 parent 5ded1c1 commit c838c9c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/react-moveable/src/react-moveable/ables/Resizable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ export default {
});
const result = parentEvent || triggerEvent(moveable, "onResizeStart", params);

datas.startFixedDirection = datas.fixedDirection;
if (result !== false) {
datas.isResize = true;
moveable.state.snapRenderInfo = {
Expand Down Expand Up @@ -313,6 +314,7 @@ export default {
datas.setFixedDirection(datas.fixedDirection);

triggerEvent(moveable, "onBeforeResize", fillParams<OnBeforeResize>(moveable, e, {
startFixedDirection: datas.startFixedDirection,
setFixedDirection(nextFixedDirection: number[]) {
datas.setFixedDirection(nextFixedDirection);

Expand Down Expand Up @@ -440,9 +442,13 @@ export default {
setCustomDrag(e, moveable.state, inverseDelta, !!isPinch, false, "draggable"),
) as OnDrag;
const transform = drag.transform;

const nextWidth = startWidth + distWidth;
const nextHeight = startHeight + distHeight;

const params = fillParams<OnResize>(moveable, e, {
width: startWidth + distWidth,
height: startHeight + distHeight,
width: nextWidth,
height: nextHeight,
offsetWidth: Math.round(boundingWidth),
offsetHeight: Math.round(boundingHeight),
startRatio: ratio,
Expand All @@ -455,8 +461,8 @@ export default {
drag,
...fillAfterTransform({
style: {
width: `${boundingWidth}px`,
height: `${boundingHeight}px`,
width: `${nextWidth}px`,
height: `${nextHeight}px`,
},
transform,
}, drag),
Expand Down
3 changes: 3 additions & 0 deletions packages/react-moveable/src/react-moveable/ables/Scalable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ export default {
});
const result = triggerEvent(moveable, "onScaleStart", params);

datas.startFixedDirection = datas.fixedDirection;

if (result !== false) {
datas.isScale = true;
moveable.state.snapRenderInfo = {
Expand Down Expand Up @@ -233,6 +235,7 @@ export default {

return scale;
},
startFixedDirection: datas.startFixedDirection,
setScale(nextScale: number[]) {
scale = nextScale;
},
Expand Down
8 changes: 8 additions & 0 deletions packages/react-moveable/src/react-moveable/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,10 @@ export interface OnBeforeScale extends OnEvent {
* If fixedDirection is set, the scale values can be changed and can be reconfirmed as a return value.
*/
setFixedDirection: (startDirecition: number[]) => number[];
/**
* fixedDirection set by rotateStart.
*/
startFixedDirection: number[];
/**
* Set target's scale to scaling.
*/
Expand Down Expand Up @@ -900,6 +904,10 @@ export interface OnBeforeResize extends OnEvent {
* If fixedDirection is set, the boundingWidth and boundingHeight values can be changed and can be reconfirmed as a return value.
*/
setFixedDirection: (startDirecition: number[]) => number[];
/**
* fixedDirection set by resizeStart.
*/
startFixedDirection: number[];
/**
* Set the bounding size to resizing.
*/
Expand Down

0 comments on commit c838c9c

Please sign in to comment.