Skip to content

Commit

Permalink
Merge branch '2.x' of https://github.com/myl0204/taro into myl0204-2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakaryCode committed Jul 31, 2020
1 parent 57fafed commit cabde71
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 27 deletions.
14 changes: 2 additions & 12 deletions packages/taro-components/src/components/image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ class Image extends Nerv.Component {
constructor () {
super(...arguments)
this.state = {
isLoaded: false,
aspectFillMode: 'width'
isLoaded: false
}
this.imageOnLoad = this.imageOnLoad.bind(this)
this.observer = {}
Expand Down Expand Up @@ -46,11 +45,6 @@ class Image extends Nerv.Component {
height: this.imgRef.height
}
})
if (this.imgRef.naturalWidth > this.imgRef.naturalHeight) {
this.setState({ aspectFillMode: 'width' })
} else {
this.setState({ aspectFillMode: 'height' })
}
onLoad && onLoad(e)
}

Expand All @@ -65,7 +59,6 @@ class Image extends Nerv.Component {
imgProps,
...reset
} = this.props
const { aspectFillMode } = this.state
const cls = classNames(
'taro-img',
{
Expand All @@ -75,10 +68,7 @@ class Image extends Nerv.Component {
)
const imgCls = classNames(
'taro-img__mode-' +
(mode || 'scaleToFill').toLowerCase().replace(/\s/g, ''),
{
[`taro-img__mode-aspectfill--${aspectFillMode}`]: mode === 'aspectFill'
}
(mode || 'scaleToFill').toLowerCase().replace(/\s/g, '')
)

return (
Expand Down
21 changes: 6 additions & 15 deletions packages/taro-components/src/components/image/style/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,21 @@ img[src=""] {
}

.taro-img__mode-scaletofill {
object-fit: contain;
width: 100%;
height: 100%;
}

.taro-img__mode-aspectfit {
max-width: 100%;
max-height: 100%;
}

.taro-img__mode-aspectfill {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}

.taro-img__mode-aspectfill--width {
min-width: 100%;
object-fit: contain;
width: 100%;
height: 100%;
}

.taro-img__mode-aspectfill--height {
.taro-img__mode-aspectfill {
object-fit: cover;
width: 100%;
min-height: 100%;
height: 100%;
}

.taro-img__mode-widthfix {
Expand Down

0 comments on commit cabde71

Please sign in to comment.