Skip to content

Commit

Permalink
fix: h5 set attr rewrite width & height fix #7585
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakaryCode committed Sep 16, 2020
1 parent b2ca04a commit bc103d5
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions packages/taro-components/src/components/canvas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@ class Canvas extends Taro.PureComponent {
if (ref) this.canvasRef = ref
}
setSize = (width, height) => {
this.canvasRef.setAttribute('width', width)
this.canvasRef.setAttribute('height', height)
this.width = width
this.height = height
const w = this.wrapDom.getAttribute('width') || width
const h = this.wrapDom.getAttribute('height') || height
if (this.width !== w) {
this.canvasRef.setAttribute('width', w)
this.width = w
}
if (this.height !== h) {
this.canvasRef.setAttribute('height', h)
this.height = h
}
}
componentDidMount () {
if (!this.wrapDom) return
Expand All @@ -48,9 +54,7 @@ class Canvas extends Taro.PureComponent {
}
componentDidUpdate () {
const { width, height } = this.wrapDom.getBoundingClientRect()
if (this.width !== width || this.height !== height) {
this.setSize(width, height)
}
this.setSize(width, height)
}
componentDidCatch (e) {
const onError = this.props.onError
Expand Down

0 comments on commit bc103d5

Please sign in to comment.