virtual-scroller 1.12.6 → 1.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -5
- package/bundle/virtual-scroller-dom.js +1 -1
- package/bundle/virtual-scroller-dom.js.map +1 -1
- package/bundle/virtual-scroller-react.js +1 -1
- package/bundle/virtual-scroller-react.js.map +1 -1
- package/bundle/virtual-scroller.js +1 -1
- package/bundle/virtual-scroller.js.map +1 -1
- package/commonjs/VirtualScroller.layout.js +12 -1
- package/commonjs/VirtualScroller.layout.js.map +1 -1
- package/commonjs/getVerticalSpacing.js +4 -2
- package/commonjs/getVerticalSpacing.js.map +1 -1
- package/commonjs/react/VirtualScroller.js +12 -6
- package/commonjs/react/VirtualScroller.js.map +1 -1
- package/commonjs/react/useVirtualScrollerStartStop.js +41 -7
- package/commonjs/react/useVirtualScrollerStartStop.js.map +1 -1
- package/dom/index.d.ts +2 -2
- package/index.d.ts +3 -3
- package/modules/VirtualScroller.layout.js +12 -1
- package/modules/VirtualScroller.layout.js.map +1 -1
- package/modules/getVerticalSpacing.js +4 -2
- package/modules/getVerticalSpacing.js.map +1 -1
- package/modules/react/VirtualScroller.js +12 -6
- package/modules/react/VirtualScroller.js.map +1 -1
- package/modules/react/useVirtualScrollerStartStop.js +39 -8
- package/modules/react/useVirtualScrollerStartStop.js.map +1 -1
- package/package.json +2 -2
- package/react/index.d.ts +21 -8
- package/source/VirtualScroller.layout.js +12 -1
- package/source/getVerticalSpacing.js +4 -2
- package/source/react/VirtualScroller.js +8 -6
- package/source/react/useVirtualScrollerStartStop.js +39 -6
|
@@ -27,7 +27,7 @@ import { warn } from '../utility/debug.js'
|
|
|
27
27
|
// * The React component re-renders itself the second time.
|
|
28
28
|
|
|
29
29
|
function VirtualScroller({
|
|
30
|
-
as: AsComponent,
|
|
30
|
+
as: AsComponent = 'div',
|
|
31
31
|
items: itemsProperty,
|
|
32
32
|
itemComponent: Component,
|
|
33
33
|
itemComponentProps,
|
|
@@ -50,6 +50,7 @@ function VirtualScroller({
|
|
|
50
50
|
getColumnsCount,
|
|
51
51
|
getItemId,
|
|
52
52
|
className,
|
|
53
|
+
readyToStart,
|
|
53
54
|
onMount,
|
|
54
55
|
// `onItemFirstRender(i)` is deprecated, use `onItemInitialRender(item)` instead.
|
|
55
56
|
onItemFirstRender,
|
|
@@ -122,7 +123,7 @@ function VirtualScroller({
|
|
|
122
123
|
|
|
123
124
|
// Start `VirtualScroller` on mount.
|
|
124
125
|
// Stop `VirtualScroller` on unmount.
|
|
125
|
-
useVirtualScrollerStartStop(virtualScroller)
|
|
126
|
+
useVirtualScrollerStartStop(virtualScroller, { readyToStart })
|
|
126
127
|
|
|
127
128
|
// List items are rendered with `key`s so that React doesn't
|
|
128
129
|
// "reuse" `itemComponent`s in cases when `items` are changed.
|
|
@@ -233,6 +234,10 @@ function VirtualScroller({
|
|
|
233
234
|
// The new property name is `setState`.
|
|
234
235
|
// The old property name `onStateChange` is deprecated.
|
|
235
236
|
//
|
|
237
|
+
// * Passing `onHeightChange` property for legacy reasons.
|
|
238
|
+
// The new property name is `onHeightDidChange`.
|
|
239
|
+
// The old property name `onHeightChange` is deprecated.
|
|
240
|
+
//
|
|
236
241
|
return (
|
|
237
242
|
<Component
|
|
238
243
|
item={item}
|
|
@@ -291,6 +296,7 @@ VirtualScroller.propTypes = {
|
|
|
291
296
|
getColumnsCount: PropTypes.func,
|
|
292
297
|
getItemId: PropTypes.func,
|
|
293
298
|
className: PropTypes.string,
|
|
299
|
+
readyToStart: PropTypes.bool,
|
|
294
300
|
onMount: PropTypes.func,
|
|
295
301
|
onItemInitialRender: PropTypes.func,
|
|
296
302
|
// `onItemFirstRender(i)` is deprecated, use `onItemInitialRender(item)` instead.
|
|
@@ -311,7 +317,3 @@ VirtualScroller.propTypes = {
|
|
|
311
317
|
}),
|
|
312
318
|
getInitialItemState: PropTypes.func
|
|
313
319
|
}
|
|
314
|
-
|
|
315
|
-
VirtualScroller.defaultProps = {
|
|
316
|
-
as: 'div'
|
|
317
|
-
}
|
|
@@ -1,12 +1,45 @@
|
|
|
1
|
-
import { useLayoutEffect } from 'react'
|
|
1
|
+
import { useLayoutEffect, useEffect, useRef } from 'react'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
import log from '../utility/debug.js'
|
|
4
|
+
|
|
5
|
+
export default function useVirtualScrollerStartStop(virtualScroller, { readyToStart }) {
|
|
6
|
+
const hasStarted = useRef(false)
|
|
7
|
+
|
|
8
|
+
const startIfReadyToStartAndNotStarted = () => {
|
|
9
|
+
if (!hasStarted.current) {
|
|
10
|
+
if (readyToStart === false) {
|
|
11
|
+
log('Could\'ve started but isn\'t ready to start')
|
|
12
|
+
} else {
|
|
13
|
+
hasStarted.current = true
|
|
14
|
+
// Start listening to scroll events.
|
|
15
|
+
virtualScroller.start()
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const stopIfStarted = () => {
|
|
21
|
+
if (hasStarted.current) {
|
|
8
22
|
// Stop listening to scroll events.
|
|
9
23
|
virtualScroller.stop()
|
|
24
|
+
// Can be re-started.
|
|
25
|
+
hasStarted.current = false
|
|
10
26
|
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Uses `useLayoutEffect()` here rather than just `useEffect()`
|
|
30
|
+
// in order to reduce the timeframe of showing an empty list to the user.
|
|
31
|
+
useLayoutEffect(() => {
|
|
32
|
+
startIfReadyToStartAndNotStarted()
|
|
33
|
+
return stopIfStarted
|
|
11
34
|
}, [])
|
|
35
|
+
|
|
36
|
+
const readyToStartPrev = useRef(readyToStart)
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (readyToStartPrev.current === false && readyToStart !== false) {
|
|
40
|
+
readyToStartPrev.current = readyToStart
|
|
41
|
+
log('Is ready to start')
|
|
42
|
+
startIfReadyToStartAndNotStarted()
|
|
43
|
+
}
|
|
44
|
+
}, [readyToStart])
|
|
12
45
|
}
|