Skip to content

Add near-end threshold #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions packages/component/src/ScrollToBottom/Composer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import memoize from 'memoize-one';
import PropTypes from 'prop-types';
import React from 'react';
import updateIn from 'simple-update-in';
Expand All @@ -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) {
Expand All @@ -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 {
Expand Down