You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+11Lines changed: 11 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
7
7
8
8
## [Unreleased]
9
9
10
+
### Added
11
+
12
+
- Added `scroller` prop for limiting scroll distance when `mode` is set to `bottom`, in PR [#73](https://github.com/compulim/react-scroll-to-bottom/pull/73)
13
+
- Added `initialScrollBehavior` prop for first scroll behavior. When set to `"auto"` (discrete scrolling), it will jump to end on initialization. in PR [#73](https://github.com/compulim/react-scroll-to-bottom/pull/73)
14
+
- Added `debug` prop for dumping debug log to console, in PR [#73](https://github.com/compulim/react-scroll-to-bottom/pull/73)
15
+
- Improved performance by separating `StateContext` into 2 tiers, in PR [#73](https://github.com/compulim/react-scroll-to-bottom/pull/73)
16
+
17
+
### Fixed
18
+
19
+
- Emptying container should regain stickiness, in PR [#73](https://github.com/compulim/react-scroll-to-bottom/pull/73)
|`checkInterval`|`number`| 150 | Recurring interval of stickiness check, in milliseconds (minimum is 17 ms) |
68
+
|`className`|`string`|| Set the class name for the root element |
69
+
|`debounce`|`number`|`17`| Set the debounce for tracking the `onScroll` event |
70
+
|`debug`|`bool`| false | Show debug information in console |
71
+
|`followButtonClassName`|`string`|| Set the class name for the follow button |
72
+
|`initialScrollBehavior`|`string`|`smooth`| Set the initial scroll behavior, either `"auto"` (discrete scrolling) or `"smooth"`|
73
+
|`mode`|`string`|`"bottom"`| Set it to `"bottom"` for scroll-to-bottom, `"top"` for scroll-to-top |
74
+
|`nonce`|`string`|| Set the nonce for [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy)|
75
+
|`scroller`|`function`|`() => Infinity`| A function to determine how far should scroll when scroll is needed |
76
+
|`scrollViewClassName`|`string`|| Set the class name for the container element that house all `props.children`|
74
77
75
78
## Hooks
76
79
@@ -369,6 +372,60 @@ export default () => (
369
372
);
370
373
```
371
374
375
+
## Observing scroll position
376
+
377
+
You can use `useObserveScrollPosition` to listen to scroll change.
378
+
379
+
```js
380
+
// This is the content rendered inside the scrollable container
381
+
constScrollContent= () => {
382
+
constobserver=useCallback(({ scrollTop }) => {
383
+
console.log(scrollTop);
384
+
}, []);
385
+
386
+
useObserveScrollPosition(observer);
387
+
388
+
return<div>Hello, World!</div>;
389
+
};
390
+
```
391
+
392
+
> If you want to turn off the hook, in the render call, pass a falsy value, e.g. `useObserveScrollPosition(false)`.
393
+
394
+
Please note that the observer will called very frequently, it is recommended:
395
+
396
+
- Only observe the scroll position when needed
397
+
- Don't put too much logic inside the callback function
398
+
- If logic is needed, consider deferring handling using `setTimeout` or similar functions
399
+
- Make sure the callback function passed on each render call is memoized appropriately, e.g. `useCallback`
400
+
401
+
For best practices on handling `scroll` event, please read [this article](https://developer.mozilla.org/en-US/docs/Web/API/Document/scroll_event).
402
+
403
+
## Programmatically pausing scroll
404
+
405
+
> This only works when `mode` prop is set to `bottom` (default).
406
+
407
+
You can pass a function to the `scroller` prop to customize how far the scrollable should animate/scroll (in pixel) when its content changed. The signature of the scroller function is:
|`maxValue`|`number`| Maximum distance (in pixel) to scroll |
416
+
|`minValue`|`number`| Minimum distance (in pixel) to scroll, see notes below |
417
+
|`offsetHeight`|`number`| View height of the scrollable container |
418
+
|`scrollHeight`|`number`| Total height of the content in the container, must be equal or greater than `offsetHeight`|
419
+
|`scrollTop`|`number`| Current scroll position (in pixel) |
420
+
421
+
Note: the `scroller` function will get called when the scrollable is sticky and the content size change. If the scrollable is not sticky, the function will not be called as animation is not needed.
422
+
423
+
When the scrollable is animating, if there are new contents added to the scrollable, the `scroller` function will get called again with `minValue` set to the current position. The `minValue` means how far the animation has already scrolled.
424
+
425
+
By default, the `scroller` function will returns `Infinity`. When new content is added, it will scroll all the way to the bottom.
426
+
427
+
You can return a different value (in number) to indicates how far you want to scroll when the content has changed. If you return `0`, the scrollable will stop scrolling for any new content. Returning any values less than `maxValue` will make the scrollable to lose its stickiness after animation. After the scrollable lose its stickiness, the `scroller` function will not be called again for any future content change, until the scrollable regains its stickiness.
428
+
372
429
# Security
373
430
374
431
We support nonce-based [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy). To enable, the following directive is required:
0 commit comments