From ec1f9e8f3ac1d1bfd323e54de6a72574688f533c Mon Sep 17 00:00:00 2001 From: William Wong Date: Tue, 12 Feb 2019 21:37:15 -0800 Subject: [PATCH] Add near-end threshold --- CHANGELOG.md | 5 +++-- packages/component/src/ScrollToBottom/Composer.js | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9539d7..b01b207 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,8 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] ### Changed -- `Composer`: fix [#13](https://github.com/compulim/react-scroll-to-bottom/pull/13), user scrolling in Firefox may have the scroll position locked occasionally, in PR [#12](https://github.com/compulim/react-scroll-to-bottom/pull/12) -- `SpineTo`: fix [#10](https://github.com/compulim/react-scroll-to-bottom/pull/10) set stopping threshold from `0.5` to `1.5`, in PR [#14](https://github.com/compulim/react-scroll-to-bottom/pull/14) +- `Composer`: fix [#13](https://github.com/compulim/react-scroll-to-bottom/issue/13), user scrolling in Firefox may have the scroll position locked occasionally, in PR [#12](https://github.com/compulim/react-scroll-to-bottom/pull/12) +- `SpineTo`: fix [#10](https://github.com/compulim/react-scroll-to-bottom/issue/10), set stopping threshold from `0.5` to `1.5`, in PR [#14](https://github.com/compulim/react-scroll-to-bottom/pull/14) +- `Composer`: fix [#15](https://github.com/compulim/react-scroll-to-bottom/issue/15), set near-end threshold from `0` to (less than) `1`, in PR [#16](https://github.com/compulim/react-scroll-to-bottom/pull/16) ## [1.3.0] - 2019-01-21 ### Changed diff --git a/packages/component/src/ScrollToBottom/Composer.js b/packages/component/src/ScrollToBottom/Composer.js index fec8e69..cebd512 100644 --- a/packages/component/src/ScrollToBottom/Composer.js +++ b/packages/component/src/ScrollToBottom/Composer.js @@ -1,4 +1,3 @@ -import memoize from 'memoize-one'; import PropTypes from 'prop-types'; import React from 'react'; import updateIn from 'simple-update-in'; @@ -10,6 +9,7 @@ import SpineTo from '../SpineTo'; import StateContext from './StateContext'; const MIN_CHECK_INTERVAL = 17; // 1 frame +const NEAR_END_THRESHOLD = 1; const SCROLL_DECISION_DURATION = 34; // 2 frames function setImmediateInterval(fn, ms) { @@ -19,8 +19,8 @@ function setImmediateInterval(fn, ms) { } function computeViewState({ stateContext: { mode }, target: { offsetHeight, scrollHeight, scrollTop } }) { - const atBottom = scrollHeight - scrollTop - offsetHeight <= 0; - const atTop = scrollTop <= 0; + const atBottom = scrollHeight - scrollTop - offsetHeight < NEAR_END_THRESHOLD; + const atTop = scrollTop < NEAR_END_THRESHOLD; const atEnd = mode === 'top' ? atTop : atBottom; return {