Skip to content

Commit 7ab45df

Browse files
committed
FIX: 计算时宽高取绝对值
1 parent b72fba4 commit 7ab45df

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-resizable-rotatable-draggable",
3-
"version": "0.1.6",
3+
"version": "0.1.8",
44
"description": "A rectangle react component which can be resized and rotated",
55
"author": "MockingBot",
66
"license": "MIT",

src/index.example.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ handleRotateStart = () => console.log("start")
5656
<ResizableRect
5757
{...{ left, top, width, height, rotateAngle }}
5858
// aspectRatio={false}
59-
// minWidth={-Infinity}
60-
// minHeight={-Infinity}
59+
minWidth={-Infinity}
60+
minHeight={-Infinity}
6161
zoomable="n, w, s, e, nw, ne, se, sw"
6262
// rotatable={true}
6363
onRotateStart={this.handleRotateStart}

src/utils.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ const setHeightAndDeltaH = (height, deltaH, minHeight) => {
3636

3737
export const getNewStyle = (type, rect, deltaW, deltaH, ratio, minWidth, minHeight) => {
3838
let { width, height, centerX, centerY, rotateAngle } = rect
39+
const widthFlag = width < 0 ? -1 : 1
40+
const heightFlag = height < 0 ? -1 : 1
41+
width = Math.abs(width)
42+
height = Math.abs(height)
3943
switch (type) {
4044
case 'r': {
4145
const widthAndDeltaW = setWidthAndDeltaW(width, deltaW, minWidth)
@@ -178,8 +182,8 @@ export const getNewStyle = (type, rect, deltaW, deltaH, ratio, minWidth, minHeig
178182
centerY
179183
},
180184
size: {
181-
width,
182-
height
185+
width: width * widthFlag,
186+
height: height * heightFlag
183187
}
184188
}
185189
}

0 commit comments

Comments
 (0)