Skip to content

Commit e7d148e

Browse files
authored
Feature: Add useObserveScrollPosition and useScrollTo (#49)
* Add new hooks * Rename * Clean up * Clean up * Clean up * Clean up * Rename and ESLint * Add useObserveScrollPosition * Update entry * Clean up * Move ESLint out * Add breaking changes * Clean up * Clean up * Add badge
1 parent a034d6f commit e7d148e

16 files changed

+1682
-897
lines changed

.eslintrc.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ extends:
66
- eslint:recommended
77
globals:
88
React: readonly
9-
parser: babel-eslint
10-
parserOptions:
11-
ecmaFeatures:
12-
jsx: true
13-
ecmaVersion: 10
14-
sourceType: module
159
root: true
1610
rules:
1711
# Only list rules that are not in *:recommended set

CHANGELOG.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
# Changelog
2+
23
All notable changes to this project will be documented in this file.
34

45
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
56
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
67

78
## [Unreleased]
89

9-
### Added
10+
### Breaking changes
1011

11-
- Added version number to `<meta name="react-scroll-to-bottom:version">` for diagnostic purpose, in PR [#51](https://github.com/compulim/react-scroll-to-bottom/pull/51)
12+
- `scrollToBottom`/`scrollToEnd`/`scrollToStart`/`scrollToTop` now accept an option `{ behavior: 'auto' | 'smooth' }`
13+
- Without the option, it is by default to artificial smooth scrolling (`smooth`), to keep existing behavior
14+
- This behavior may change in the future, by defaulting to discrete scrolling (`auto`), to better align with HTML `DOMElement.scrollIntoView` standard
15+
- During the transition, please always pass `{ behavior: 'smooth' }` to keep existing behavior
1216

1317
### Changed
1418

@@ -23,6 +27,22 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2327
- [`eslint-plugin-react@7.20.0`](https://www.npmjs.com/package/eslint-plugin-react)
2428
- [`eslint-plugin-react-hooks@4.0.4`](https://www.npmjs.com/package/eslint-plugin-react-hooks)
2529

30+
### Added
31+
32+
- Added version number to `<meta name="react-scroll-to-bottom:version">` for diagnostic purpose, in PR [#51](https://github.com/compulim/react-scroll-to-bottom/pull/51)
33+
- Added `useAnimatingToEnd` getter to indicate if it is animating towards to the end, in PR [#49](https://github.com/compulim/react-scroll-to-bottom/pull/49)
34+
- The existing `useAnimating` getter only indicate if it is animating to any scroll positions
35+
- Added `scrollTo` function to scroll to a specific `scrollTop` value, this is similar to `DOMElement.scrollIntoView()`, in PR [#49](https://github.com/compulim/react-scroll-to-bottom/pull/49)
36+
- The signature is `scrollTo(scrollTop: number, options: { behavior: 'auto' | 'smooth' })`
37+
- Pass `{ behavior: 'smooth' }` for synthetic smooth scrolling
38+
- Added `useObserveScrollTop` hook to observe scroll event, in PR [#49](https://github.com/compulim/react-scroll-to-bottom/pull/49)
39+
- This effect function will be called rapidly on scroll, please avoid expensive code such as calling setter of `useState` and any code that would cause re-render
40+
41+
### Fixed
42+
43+
- Cancel scroll animation on mouse wheel or touch gesture, in PR [#49](https://github.com/compulim/react-scroll-to-bottom/pull/49)
44+
- Calling `scrollTo` should cancel any existing scroll animation, in PR [#49](https://github.com/compulim/react-scroll-to-bottom/pull/49)
45+
2646
## [2.0.0] - 2020-05-07
2747

2848
### Breaking changes

README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# react-scroll-to-bottom
22

3-
[![npm version](https://badge.fury.io/js/react-scroll-to-bottom.svg)](https://badge.fury.io/js/react-scroll-to-bottom) [![Build Status](https://travis-ci.org/compulim/react-scroll-to-bottom.svg?branch=master)](https://travis-ci.org/compulim/react-scroll-to-bottom)
3+
[![npm version](https://badge.fury.io/js/react-scroll-to-bottom.svg)](https://badge.fury.io/js/react-scroll-to-bottom) ![Node.js CI](https://github.com/compulim/react-scroll-to-bottom/workflows/Node.js%20CI/badge.svg)
44

55
React container that will auto scroll to bottom or top if new content is added and viewport is at the bottom, similar to `tail -f`. Otherwise, a "jump to bottom" button will be shown to allow user to quickly jump to bottom.
66

@@ -10,7 +10,16 @@ Try out the demo at [https://compulim.github.io/react-scroll-to-bottom/](https:/
1010

1111
# Breaking changes
1212

13-
Starting from `react-scroll-to-bottom@2`, we requires React 16.8.6 or above. This enable developers to use React Hooks to add features to the scroll view.
13+
## Upcoming
14+
15+
- `scrollToBottom`/`scrollToEnd`/`scrollToStart`/`scrollToTop` now accept an option `{ behavior: 'auto' | 'smooth' }`
16+
- Without the option, it is by default to artificial smooth scrolling (`smooth`), to keep existing behavior
17+
- This behavior may change in the future, by defaulting to discrete scrolling (`auto`), to better align with HTML `DOMElement.scrollIntoView` standard
18+
- During the transition, please always pass `{ behavior: 'smooth' }` to keep existing behavior
19+
20+
## [2.0.0] - 2020-05-07
21+
22+
- Starting from `react-scroll-to-bottom@2`, we requires React 16.8.6 or above. This enable developers to use React Hooks to add features to the scroll view.
1423

1524
# Sample code
1625

@@ -182,6 +191,11 @@ This context contains functions used to manipulate the container. And will not u
182191
</tr>
183192
</thead>
184193
<tbody>
194+
<tr>
195+
<td><code>useObserveScrollPosition</code></td>
196+
<td><code>(observer: (({ scrollTop: number }) => void) | false) => void</code></td>
197+
<td>Observe scroll position change by passing a callback function</td>
198+
</tr>
185199
<tr>
186200
<td><code>useScrollTo</code></td>
187201
<td><code>(scrollTop: number | '100%') => void</code></td>
@@ -210,6 +224,8 @@ This context contains functions used to manipulate the container. And will not u
210224
</tbody>
211225
</table>
212226

227+
> Callback function passed to `useObserveScrollPosition` will be called rapidly during scrolling. To unsubscribe, pass a falsy value.
228+
213229
### State context
214230

215231
This context contains state of the container.
@@ -228,6 +244,11 @@ This context contains state of the container.
228244
<td><code>boolean</code></td>
229245
<td><code>true</code> if the panel is animating scroll effect</td>
230246
</tr>
247+
<tr>
248+
<td><code>useAnimatingToEnd</code></td>
249+
<td><code>boolean</code></td>
250+
<td><code>true</code> if the panel is animating scroll effect and towards the end (depends on <code>mode</code>)</td>
251+
</tr>
231252
<tr>
232253
<td><code>useAtBottom</code></td>
233254
<td><code>boolean</code></td>

0 commit comments

Comments
 (0)