diff --git a/CHANGELOG.md b/CHANGELOG.md index 505210e..8b94e26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,3 +6,6 @@ # 1.1.3 - fix: 页面中同时有多个瀑布流时,共用一个cache,后渲染的瀑布流的cache.reset()会清掉所有cache,导致重新布局。 + +# 1.1.4 +- fix: 如果原始数据没有aspect,也没有width和height,默认设为1 \ No newline at end of file diff --git a/package.json b/package.json index b3b803e..d46bbdb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "remasonry", - "version": "1.1.3", + "version": "1.1.4", "description": "a grid layout library with react", "main": "index.cjs.js", "module": "index.js", diff --git a/src/h-layout.ts b/src/h-layout.ts index c5aad67..d31f9b1 100644 --- a/src/h-layout.ts +++ b/src/h-layout.ts @@ -27,10 +27,13 @@ export default ({ const geometry = layoutGeometry( items.map(item => { - if (typeof item.aspect === 'string') { - return parseFloat(item.aspect) || 1 + let aspect = Number(item.aspect) + + if (!item.aspect && item.width && item.height) { + aspect = Number(item.width) / Number(item.height) } - return item.aspect || item + + return aspect || 1 }), { containerWidth: width, diff --git a/src/layout.ts b/src/layout.ts index 93403be..2194f83 100644 --- a/src/layout.ts +++ b/src/layout.ts @@ -42,7 +42,7 @@ export default ({ const heights = new Array(columnCount).fill(0) return items.reduce((positions, item: any) => { - const aspect = item.aspect ? Number(item.aspect) : item.width / item.height + const aspect = (item.aspect ? Number(item.aspect) : item.width / item.height) || 1 const height = realColumnWidth / aspect let position