Skip to content

Commit e4ad31e

Browse files
committed
Replace @researchgate/react-intersection-observer with react-intersection-observer
1 parent e792b85 commit e4ad31e

5 files changed

Lines changed: 18 additions & 18 deletions

File tree

__tests__/src/components/GalleryViewThumbnail.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { shallow } from 'enzyme';
33
import { Utils } from 'manifesto.js';
44
import Chip from '@material-ui/core/Chip';
5-
import IntersectionObserver from '@researchgate/react-intersection-observer';
5+
import { InView } from 'react-intersection-observer';
66
import manifestJson from '../../fixtures/version-2/019.json';
77
import { GalleryViewThumbnail } from '../../../src/components/GalleryViewThumbnail';
88
import IIIFThumbnail from '../../../src/containers/IIIFThumbnail';
@@ -78,7 +78,7 @@ describe('GalleryView', () => {
7878
};
7979
wrapper = createWrapper({ annotationsCount: 0, canvas, requestCanvasAnnotations });
8080

81-
wrapper.find(IntersectionObserver).simulate('change', { isIntersecting: true });
81+
wrapper.find(InView).simulate('change', { isIntersecting: true });
8282
expect(requestCanvasAnnotations).toHaveBeenCalled();
8383
});
8484
it('does nothing if there is no intersection', () => {
@@ -89,7 +89,7 @@ describe('GalleryView', () => {
8989
};
9090
wrapper = createWrapper({ canvas, requestCanvasAnnotations });
9191

92-
wrapper.find(IntersectionObserver).simulate('change', { isIntersecting: false });
92+
wrapper.find(InView).simulate('change', { isIntersecting: false });
9393
expect(requestCanvasAnnotations).not.toHaveBeenCalled();
9494
});
9595
it('does nothing if there are already some annotations', () => {
@@ -100,7 +100,7 @@ describe('GalleryView', () => {
100100
};
101101
wrapper = createWrapper({ annotationsCount: 5, canvas, requestCanvasAnnotations });
102102

103-
wrapper.find(IntersectionObserver).simulate('change', { isIntersecting: true });
103+
wrapper.find(InView).simulate('change', { isIntersecting: true });
104104
expect(requestCanvasAnnotations).not.toHaveBeenCalled();
105105
});
106106
});

__tests__/src/components/IIIFThumbnail.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { shallow } from 'enzyme';
3-
import IntersectionObserver from '@researchgate/react-intersection-observer';
3+
import { InView } from 'react-intersection-observer';
44
import Typography from '@material-ui/core/Typography';
55
import { IIIFThumbnail } from '../../../src/components/IIIFThumbnail';
66

@@ -26,9 +26,9 @@ describe('IIIFThumbnail', () => {
2626
it('renders properly', () => {
2727
expect(wrapper.matchesElement(
2828
<div>
29-
<IntersectionObserver onChange={wrapper.instance().handleIntersection}>
29+
<InView onChange={wrapper.instance().handleIntersection}>
3030
<img alt="" />
31-
</IntersectionObserver>
31+
</InView>
3232
</div>,
3333
)).toBe(true);
3434
});
@@ -37,9 +37,9 @@ describe('IIIFThumbnail', () => {
3737
wrapper = createWrapper({});
3838
expect(wrapper.matchesElement(
3939
<div>
40-
<IntersectionObserver onChange={wrapper.instance().handleIntersection}>
40+
<InView onChange={wrapper.instance().handleIntersection}>
4141
<img alt="" />
42-
</IntersectionObserver>
42+
</InView>
4343
</div>,
4444
)).toBe(true);
4545
expect(wrapper.find('img').props().src).toMatch(/data:image\/png;base64/);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
"@material-ui/core": "^4.12.3",
3737
"@material-ui/icons": "^4.9.1",
3838
"@material-ui/lab": "^4.0.0-alpha.53",
39-
"@researchgate/react-intersection-observer": "^1.0.0",
4039
"classnames": "^2.2.6",
4140
"clsx": "^1.0.4",
4241
"deepmerge": "^4.2.2",
@@ -62,6 +61,7 @@
6261
"react-full-screen": "^0.2.4",
6362
"react-i18next": "^11.7.0",
6463
"react-image": "^4.0.1",
64+
"react-intersection-observer": "^9.0.0",
6565
"react-mosaic-component": "^4.0.1",
6666
"react-redux": "^7.1.0",
6767
"react-resize-observer": "^1.1.1",

src/components/GalleryViewThumbnail.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Chip from '@material-ui/core/Chip';
55
import AnnotationIcon from '@material-ui/icons/CommentSharp';
66
import SearchIcon from '@material-ui/icons/SearchSharp';
77
import classNames from 'classnames';
8-
import IntersectionObserver from '@researchgate/react-intersection-observer';
8+
import { InView } from 'react-intersection-observer';
99
import MiradorCanvas from '../lib/MiradorCanvas';
1010
import IIIFThumbnail from '../containers/IIIFThumbnail';
1111

@@ -108,7 +108,7 @@ export class GalleryViewThumbnail extends Component {
108108
const miradorCanvas = new MiradorCanvas(canvas);
109109

110110
return (
111-
<IntersectionObserver onChange={this.handleIntersection}>
111+
<InView onChange={this.handleIntersection}>
112112
<div
113113
key={canvas.index}
114114
className={
@@ -167,7 +167,7 @@ export class GalleryViewThumbnail extends Component {
167167
</div>
168168
</IIIFThumbnail>
169169
</div>
170-
</IntersectionObserver>
170+
</InView>
171171
);
172172
}
173173
}

src/components/IIIFThumbnail.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { Component } from 'react';
22
import PropTypes from 'prop-types';
33
import Typography from '@material-ui/core/Typography';
4-
import IntersectionObserver from '@researchgate/react-intersection-observer';
4+
import { InView } from 'react-intersection-observer';
55
import classNames from 'classnames';
66
import getThumbnail from '../lib/ThumbnailFactory';
77

@@ -47,10 +47,10 @@ export class IIIFThumbnail extends Component {
4747
* Handles the intersection (visibility) of a given thumbnail, by requesting
4848
* the image and then updating the state.
4949
*/
50-
handleIntersection(event) {
50+
handleIntersection(inView, _entry) {
5151
const { loaded } = this.state;
5252

53-
if (loaded || !event.isIntersecting) return;
53+
if (loaded || !inView) return;
5454

5555
this.setState(state => ({ ...state, loaded: true }));
5656
}
@@ -151,15 +151,15 @@ export class IIIFThumbnail extends Component {
151151

152152
return (
153153
<div className={classNames(classes.root, { [classes[`${variant}Root`]]: variant })}>
154-
<IntersectionObserver onChange={this.handleIntersection}>
154+
<InView as="span" onChange={this.handleIntersection}>
155155
<img
156156
alt=""
157157
role="presentation"
158158
src={src}
159159
style={this.imageStyles()}
160160
className={classes.image}
161161
/>
162-
</IntersectionObserver>
162+
</InView>
163163
{ labelled && (
164164
<div className={classNames(classes.label, { [classes[`${variant}Label`]]: variant })}>
165165
<Typography variant="caption" classes={{ root: classNames(classes.caption, { [classes[`${variant}Caption`]]: variant }) }}>

0 commit comments

Comments
 (0)