Skip to content

Commit

Permalink
fix: 如果原始数据没有aspect,也没有width和height,默认设为1
Browse files Browse the repository at this point in the history
  • Loading branch information
lixue committed Sep 23, 2021
1 parent a185737 commit 35f5830
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@

# 1.1.3
- fix: 页面中同时有多个瀑布流时,共用一个cache,后渲染的瀑布流的cache.reset()会清掉所有cache,导致重新布局。

# 1.1.4
- fix: 如果原始数据没有aspect,也没有width和height,默认设为1
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
9 changes: 6 additions & 3 deletions src/h-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default <T>({
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

Expand Down

0 comments on commit 35f5830

Please sign in to comment.