Skip to content

Commit 43d311c

Browse files
committed
feat: itemSecondarySize
1 parent 6339e72 commit 43d311c

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ When the user scrolls inside RecycleScroller, the views are mostly just moved ar
187187
- `direction` (default: `'vertical'`): scrolling direction, either `'vertical'` or `'horizontal'`.
188188
- `itemSize` (default: `null`): display height (or width in horizontal mode) of the items in pixels used to calculate the scroll size and position. If it is set to `null` (the default value), it will use [variable size mode](#variable-size-mode).
189189
- `gridItems`: display that many items on the same line to create a grid. You must put a value for `itemSize` to use this prop (dynamic sizes are not supported).
190+
- `itemSecondarySize`: size in pixels (width in vertical mode, height in horizontal mode) of the items in the grid when `gridItems` is set. If `itemSecondarySize` is not set, it will use the value of `itemSize`.
190191
- `minItemSize`: minimum size used if the height (or width in horizontal mode) of a item is unknown.
191192
- `sizeField` (default: `'size'`): field used to get the item's size in variable size mode.
192193
- `typeField` (default: `'type'`): field used to differentiate different kinds of components in the list. For each distinct type, a pool of recycled items will be created.

docs-src/src/components/GridDemo.vue

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export default {
5151
:items="list"
5252
:item-size="128"
5353
:grid-items="gridItems"
54+
:item-secondary-size="100"
5455
>
5556
<template #default="{ item, index }">
5657
<div class="item">
@@ -92,6 +93,7 @@ export default {
9293
9394
.item {
9495
position: relative;
96+
height: 100%;
9597
}
9698
9799
.index {
@@ -108,5 +110,6 @@ img {
108110
width: 100%;
109111
height: 100%;
110112
background: #eee;
113+
object-fit: cover;
111114
}
112115
</style>

src/components/RecycleScroller.vue

+13-3
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
:key="view.nr.id"
3333
:style="ready ? {
3434
transform: `translate${direction === 'vertical' ? 'Y' : 'X'}(${view.position}px) translate${direction === 'vertical' ? 'X' : 'Y'}(${view.offset}px)`,
35-
width: gridItems ? `${itemSize}px` : undefined,
36-
height: gridItems ? `${itemSize}px` : undefined,
35+
width: gridItems ? `${direction === 'vertical' ? itemSecondarySize || itemSize : itemSize}px` : undefined,
36+
height: gridItems ? `${direction === 'horizontal' ? itemSecondarySize || itemSize : itemSize}px` : undefined,
3737
} : null"
3838
class="vue-recycle-scroller__item-view"
3939
:class="[
@@ -107,6 +107,11 @@ export default {
107107
default: undefined,
108108
},
109109
110+
itemSecondarySize: {
111+
type: Number,
112+
default: undefined,
113+
},
114+
110115
minItemSize: {
111116
type: [Number, String],
112117
default: null,
@@ -227,6 +232,10 @@ export default {
227232
gridItems () {
228233
this.updateVisibleItems(true)
229234
},
235+
236+
itemSecondarySize () {
237+
this.updateVisibleItems(true)
238+
},
230239
},
231240
232241
created () {
@@ -347,6 +356,7 @@ export default {
347356
updateVisibleItems (checkItem, checkPositionDiff = false) {
348357
const itemSize = this.itemSize
349358
const gridItems = this.gridItems
359+
const itemSecondarySize = this.itemSecondarySize || itemSize
350360
const minItemSize = this.$_computedMinItemSize
351361
const typeField = this.typeField
352362
const keyField = this.simpleArray ? null : this.keyField
@@ -570,7 +580,7 @@ export default {
570580
view.offset = 0
571581
} else {
572582
view.position = Math.floor(i / gridItems) * itemSize
573-
view.offset = (i % gridItems) * itemSize
583+
view.offset = (i % gridItems) * itemSecondarySize
574584
}
575585
}
576586

0 commit comments

Comments
 (0)