Skip to content

Commit

Permalink
feat: use destructuring and pass remaining props to container component
Browse files Browse the repository at this point in the history
  • Loading branch information
n1ru4l committed May 27, 2019
1 parent 14f13f1 commit e130ef0
Showing 1 changed file with 43 additions and 5 deletions.
48 changes: 43 additions & 5 deletions src/PanZoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,19 @@ class PanZoom extends React.Component<Props> {
}

onDoubleClick = (e) => {
const { doubleZoomSpeed } = this.props
const { doubleZoomSpeed, onDoubleClick } = this.props
if (onDoubleClick !== undefined) {
onDoubleClick(e)
}
const offset = this.getOffset(e)
this.zoomTo(offset.x, offset.y, doubleZoomSpeed)
}

onMouseDown = (e) => {
const { preventPan } = this.props
const { preventPan, onMouseDown } = this.props
if (onMouseDown !== undefined) {
onMouseDown(e)
}
if (this.props.disabled) {
return
}
Expand Down Expand Up @@ -224,7 +230,10 @@ class PanZoom extends React.Component<Props> {
}

onKeyDown = (e) => {
const { keyMapping, disableKeyInteraction } = this.props
const { keyMapping, disableKeyInteraction, onKeyDown } = this.props
if (onKeyDown !== undefined) {
onKeyDown(e)
}

if (disableKeyInteraction) {
return
Expand Down Expand Up @@ -265,7 +274,10 @@ class PanZoom extends React.Component<Props> {
}

onTouchStart = (e) => {
const { preventPan } = this.props
const { preventPan, onTouchStart } = this.props
if (onTouchStart !== undefined) {
onTouchStart(e)
}
if (e.touches.length === 1) {
// Drag
const touch = e.touches[0]
Expand Down Expand Up @@ -671,7 +683,33 @@ class PanZoom extends React.Component<Props> {
}

render() {
const { children, style, disabled, disableKeyInteraction } = this.props
const {
children,
autoCenter,
autoCenterZoomLevel,
zoomSpeed,
doubleZoomSpeed,
disabled,
disableKeyInteraction,
realPinch,
keyMapping,
minZoom,
maxZoom,
enableBoundingBox,
boundaryRatioVertical,
boundaryRatioHorizontal,
noStateUpdate,
onPanStart,
onPan,
onPanEnd,
preventPan,
style,
onDoubleClick,
onMouseDown,
onKeyDown,
onTouchStart,
...props
} = this.props
const { x, y, scale, rotate } = this.state
const { a, b, c, d, x: transformX, y: transformY} = this.getTransformMatrix(x, y, scale, rotate)
const transform = this.getTransformMatrixString(a, b, c, d, transformX, transformY)
Expand Down

0 comments on commit e130ef0

Please sign in to comment.