Skip to content

Commit 62f10eb

Browse files
committed
fix(*): fix disabled updates caused by latest version of react-viewport-utils
1 parent 1091c4d commit 62f10eb

File tree

5 files changed

+743
-848
lines changed

5 files changed

+743
-848
lines changed

examples/index.tsx

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
import * as React from 'react';
22
import { render } from 'react-dom';
3-
import { ObserveViewport } from 'react-viewport-utils';
3+
import { ObserveViewport, useRect } from 'react-viewport-utils';
44

55
import { Sticky, StickyScrollUp, StickyProvider } from '../lib/index';
66

77
import './styles.css';
88

99
const Placeholder = () => <div className="placeholder" />;
10-
11-
class Example extends React.PureComponent<{}, { disableHeader: boolean }> {
10+
const Test = () => {
11+
const div = React.useRef(null);
12+
const rect = useRect(div);
13+
return <div ref={div} />;
14+
};
15+
16+
class Example extends React.PureComponent<
17+
{},
18+
{ disableHeader: boolean; disableAll: boolean }
19+
> {
1220
private container1: React.RefObject<any>;
1321
private container2: React.RefObject<any>;
1422
private container3: React.RefObject<any>;
@@ -26,6 +34,7 @@ class Example extends React.PureComponent<{}, { disableHeader: boolean }> {
2634
this.container6 = React.createRef();
2735
this.state = {
2836
disableHeader: false,
37+
disableAll: false,
2938
};
3039
}
3140

@@ -35,9 +44,20 @@ class Example extends React.PureComponent<{}, { disableHeader: boolean }> {
3544
});
3645
}
3746

47+
toggleAll() {
48+
this.setState({
49+
disableAll: !this.state.disableAll,
50+
});
51+
}
52+
3853
render() {
54+
if (this.state.disableAll) {
55+
return <button onClick={() => this.toggleAll()}>Toggle All</button>;
56+
}
3957
return (
4058
<>
59+
<button onClick={() => this.toggleAll()}>Toggle All</button>
60+
<Test />
4161
<ObserveViewport disableDimensionsUpdates priority="low">
4262
{({ scroll }) => (
4363
<div className="scrollPosition">

lib/Sticky.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,8 @@ class Sticky extends React.PureComponent<IProps, IState> {
344344
}
345345

346346
recalculateLayoutBeforeUpdate = (): ILayoutSnapshot => {
347-
const stickyRect = this.stickyRef.current.getBoundingClientRect();
348347
const containerRect = this.container.current.getBoundingClientRect();
348+
const stickyRect = this.stickyRef.current.getBoundingClientRect();
349349
return {
350350
stickyRect,
351351
containerRect,
@@ -356,6 +356,9 @@ class Sticky extends React.PureComponent<IProps, IState> {
356356
{ scroll, dimensions }: { scroll: IScroll; dimensions: IDimensions },
357357
{ stickyRect, containerRect }: ILayoutSnapshot,
358358
) => {
359+
if (this.props.disabled) {
360+
return;
361+
}
359362
// in case children is not a function renderArgs will never be used
360363
const willRenderAsAFunction = typeof this.props.children === 'function';
361364
const appliedOverflowScroll = this.getOverflowScrollType(

lib/StickyScrollUp.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ class StickyScrollUp extends React.PureComponent<IProps, IState> {
170170
placeholderRect,
171171
}: { stickyRect: IRect; placeholderRect: IRect },
172172
) => {
173+
if (this.props.disabled) {
174+
return;
175+
}
173176
// in case children is not a function renderArgs will never be used
174177
const willRenderAsAFunction = typeof this.props.children === 'function';
175178

0 commit comments

Comments
 (0)