Skip to content
Open
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
11 changes: 11 additions & 0 deletions __test__/Gallery.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,15 @@ describe('Gallery', () => {
wrapper = mount(<Gallery photos={photos} onClick={handleClick} columns={columns} direction="column" />);
expect(columns).toBeCalledWith(1140);
});

it('calls the callback when all images finish loading', () => {
const callback = jest.fn();
wrapper = mount(<Gallery photos={photos} onClick={handleClick} direction="column" onLoadCallback={callback} />);
let images = wrapper.find('img');
images.forEach(node => {
node.simulate('load');
});

expect(callback).toHaveBeenCalled();
});
});
40 changes: 40 additions & 0 deletions __test__/__snapshots__/Gallery.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ exports[`Gallery it matches correct snapshot 1`] = `
height={250.44444444444446}
key="40673436833"
onClick={[Function]}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/40673436833_5fc1ab52fe_b.jpg"
srcSet={
Expand All @@ -353,6 +354,7 @@ exports[`Gallery it matches correct snapshot 1`] = `
height={250.44444444444446}
key="47587238132"
onClick={[Function]}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/47587238132_4683fdabb2_b.jpg"
srcSet={
Expand All @@ -378,6 +380,7 @@ exports[`Gallery it matches correct snapshot 1`] = `
height={250.44444444444446}
key="32697497947"
onClick={[Function]}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/32697497947_7d6dfaf5ec_b.jpg"
srcSet={
Expand All @@ -403,6 +406,7 @@ exports[`Gallery it matches correct snapshot 1`] = `
height={250.44444444444446}
key="32697497647"
onClick={[Function]}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/32697497647_31cd88c0b5_b.jpg"
srcSet={
Expand All @@ -428,6 +432,7 @@ exports[`Gallery it matches correct snapshot 1`] = `
height={250.44444444444446}
key="47587238242"
onClick={[Function]}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/47587238242_6776b8a582_b.jpg"
srcSet={
Expand All @@ -453,6 +458,7 @@ exports[`Gallery it matches correct snapshot 1`] = `
height={250.44444444444446}
key="40673437163"
onClick={[Function]}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/40673437163_703ffe416d_b.jpg"
srcSet={
Expand All @@ -478,6 +484,7 @@ exports[`Gallery it matches correct snapshot 1`] = `
height={332.64705882352945}
key="47587238362"
onClick={[Function]}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/47587238362_5d355937cb_b.jpg"
srcSet={
Expand All @@ -503,6 +510,7 @@ exports[`Gallery it matches correct snapshot 1`] = `
height={332.64705882352945}
key="32697498187"
onClick={[Function]}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/32697498187_7a74849c76_b.jpg"
srcSet={
Expand All @@ -528,6 +536,7 @@ exports[`Gallery it matches correct snapshot 1`] = `
height={241.32762312633832}
key="40673436913"
onClick={[Function]}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/40673436913_c48ac9e6d5_b.jpg"
srcSet={
Expand All @@ -553,6 +562,7 @@ exports[`Gallery it matches correct snapshot 1`] = `
height={241.32762312633832}
key="40673437213"
onClick={[Function]}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/40673437213_3480e88c8b_b.jpg"
srcSet={
Expand All @@ -578,6 +588,7 @@ exports[`Gallery it matches correct snapshot 1`] = `
height={241.32762312633832}
key="47587238482"
onClick={[Function]}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/47587238482_5ac51de790_b.jpg"
srcSet={
Expand All @@ -603,6 +614,7 @@ exports[`Gallery it matches correct snapshot 1`] = `
height={252.1252796420582}
key="32697498227"
onClick={[Function]}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/32697498227_a3bc50aa6c_b.jpg"
srcSet={
Expand All @@ -628,6 +640,7 @@ exports[`Gallery it matches correct snapshot 1`] = `
height={252.1252796420582}
key="40673437263"
onClick={[Function]}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/40673437263_b03be98bae_b.jpg"
srcSet={
Expand All @@ -653,6 +666,7 @@ exports[`Gallery it matches correct snapshot 1`] = `
height={252.1252796420582}
key="32697497717"
onClick={[Function]}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/32697497717_1fb25b32be_b.jpg"
srcSet={
Expand All @@ -678,6 +692,7 @@ exports[`Gallery it matches correct snapshot 1`] = `
height={250.44444444444446}
key="47587238552"
onClick={[Function]}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/47587238552_cfce31cc10_b.jpg"
srcSet={
Expand All @@ -703,6 +718,7 @@ exports[`Gallery it matches correct snapshot 1`] = `
height={250.44444444444446}
key="47640016631"
onClick={[Function]}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/47640016631_cfffe28dd0_b.jpg"
srcSet={
Expand All @@ -728,6 +744,7 @@ exports[`Gallery it matches correct snapshot 1`] = `
height={250.44444444444446}
key="47640017061"
onClick={[Function]}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/47640017061_d6f554a175_b.jpg"
srcSet={
Expand All @@ -753,6 +770,7 @@ exports[`Gallery it matches correct snapshot 1`] = `
height={254.4018058690745}
key="32697497787"
onClick={[Function]}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/32697497787_ebd9165050_b.jpg"
srcSet={
Expand All @@ -778,6 +796,7 @@ exports[`Gallery it matches correct snapshot 1`] = `
height={254.4018058690745}
key="40673437303"
onClick={[Function]}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/40673437303_ec8b5a7246_b.jpg"
srcSet={
Expand All @@ -803,6 +822,7 @@ exports[`Gallery it matches correct snapshot 1`] = `
height={254.4018058690745}
key="46724351385"
onClick={[Function]}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/46724351385_a6ff50ddda_b.jpg"
srcSet={
Expand Down Expand Up @@ -1154,6 +1174,7 @@ exports[`Gallery renders correctly with direction set to column 1`] = `
height={250.4}
key="40673436833"
onClick={null}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/40673436833_5fc1ab52fe_b.jpg"
srcSet={
Expand Down Expand Up @@ -1181,6 +1202,7 @@ exports[`Gallery renders correctly with direction set to column 1`] = `
height={250.4}
key="47587238132"
onClick={null}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/47587238132_4683fdabb2_b.jpg"
srcSet={
Expand Down Expand Up @@ -1208,6 +1230,7 @@ exports[`Gallery renders correctly with direction set to column 1`] = `
height={250.4}
key="32697497947"
onClick={null}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/32697497947_7d6dfaf5ec_b.jpg"
srcSet={
Expand Down Expand Up @@ -1235,6 +1258,7 @@ exports[`Gallery renders correctly with direction set to column 1`] = `
height={250.4}
key="32697497647"
onClick={null}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/32697497647_31cd88c0b5_b.jpg"
srcSet={
Expand Down Expand Up @@ -1262,6 +1286,7 @@ exports[`Gallery renders correctly with direction set to column 1`] = `
height={250.4}
key="47587238242"
onClick={null}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/47587238242_6776b8a582_b.jpg"
srcSet={
Expand Down Expand Up @@ -1289,6 +1314,7 @@ exports[`Gallery renders correctly with direction set to column 1`] = `
height={250.4}
key="40673437163"
onClick={null}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/40673437163_703ffe416d_b.jpg"
srcSet={
Expand Down Expand Up @@ -1316,6 +1342,7 @@ exports[`Gallery renders correctly with direction set to column 1`] = `
height={250.4}
key="47587238362"
onClick={null}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/47587238362_5d355937cb_b.jpg"
srcSet={
Expand Down Expand Up @@ -1343,6 +1370,7 @@ exports[`Gallery renders correctly with direction set to column 1`] = `
height={197.7}
key="32697498187"
onClick={null}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/32697498187_7a74849c76_b.jpg"
srcSet={
Expand Down Expand Up @@ -1370,6 +1398,7 @@ exports[`Gallery renders correctly with direction set to column 1`] = `
height={250.4}
key="40673436913"
onClick={null}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/40673436913_c48ac9e6d5_b.jpg"
srcSet={
Expand Down Expand Up @@ -1397,6 +1426,7 @@ exports[`Gallery renders correctly with direction set to column 1`] = `
height={225}
key="40673437213"
onClick={null}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/40673437213_3480e88c8b_b.jpg"
srcSet={
Expand Down Expand Up @@ -1424,6 +1454,7 @@ exports[`Gallery renders correctly with direction set to column 1`] = `
height={250.4}
key="47587238482"
onClick={null}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/47587238482_5ac51de790_b.jpg"
srcSet={
Expand Down Expand Up @@ -1451,6 +1482,7 @@ exports[`Gallery renders correctly with direction set to column 1`] = `
height={250.4}
key="32697498227"
onClick={null}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/32697498227_a3bc50aa6c_b.jpg"
srcSet={
Expand Down Expand Up @@ -1478,6 +1510,7 @@ exports[`Gallery renders correctly with direction set to column 1`] = `
height={255.6}
key="40673437263"
onClick={null}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/40673437263_b03be98bae_b.jpg"
srcSet={
Expand Down Expand Up @@ -1505,6 +1538,7 @@ exports[`Gallery renders correctly with direction set to column 1`] = `
height={250.4}
key="32697497717"
onClick={null}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/32697497717_1fb25b32be_b.jpg"
srcSet={
Expand Down Expand Up @@ -1532,6 +1566,7 @@ exports[`Gallery renders correctly with direction set to column 1`] = `
height={250.4}
key="47587238552"
onClick={null}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/47587238552_cfce31cc10_b.jpg"
srcSet={
Expand Down Expand Up @@ -1559,6 +1594,7 @@ exports[`Gallery renders correctly with direction set to column 1`] = `
height={250.4}
key="47640016631"
onClick={null}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/47640016631_cfffe28dd0_b.jpg"
srcSet={
Expand Down Expand Up @@ -1586,6 +1622,7 @@ exports[`Gallery renders correctly with direction set to column 1`] = `
height={250.4}
key="47640017061"
onClick={null}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/47640017061_d6f554a175_b.jpg"
srcSet={
Expand Down Expand Up @@ -1613,6 +1650,7 @@ exports[`Gallery renders correctly with direction set to column 1`] = `
height={166.2}
key="32697497787"
onClick={null}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/32697497787_ebd9165050_b.jpg"
srcSet={
Expand Down Expand Up @@ -1640,6 +1678,7 @@ exports[`Gallery renders correctly with direction set to column 1`] = `
height={560.9}
key="40673437303"
onClick={null}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/40673437303_ec8b5a7246_b.jpg"
srcSet={
Expand Down Expand Up @@ -1667,6 +1706,7 @@ exports[`Gallery renders correctly with direction set to column 1`] = `
height={250.4}
key="46724351385"
onClick={null}
onLoad={[Function]}
sizes="(min-width: 480px) 50vw, (min-width: 1024px) 33.3vw, 100vw"
src="https://live.staticflickr.com/65535/46724351385_a6ff50ddda_b.jpg"
srcSet={
Expand Down
4 changes: 2 additions & 2 deletions examples/src/ExampleBasic.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react';
import Gallery from 'react-photo-gallery';

const ExampleBasic = ({photos, title, direction}) => {
const ExampleBasic = ({ photos, title, direction, onLoadCallback }) => {
return (
<div>
<h2>{title}</h2>
<Gallery photos={photos} direction={direction}/>
<Gallery photos={photos} direction={direction} onLoadCallback={onLoadCallback}/>
</div>
);
}
Expand Down
5 changes: 4 additions & 1 deletion examples/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ class App extends React.Component {
render() {
if (this.state.photos) {
const width = this.state.width;
const onLoad = () => {
console.log('Finished Loading Images');
}
return (
<div className="App">
<ExampleBasic title={'Basic Row Layout'} photos={this.state.photos.slice(0, 20)} />
<ExampleBasic title={'Basic Row Layout'} photos={this.state.photos.slice(0, 20)} onLoadCallback={onLoad} />
<ExampleBasic title={'Basic Column Layout'} direction="column" photos={this.state.photos.slice(40, 60)} />
<ExampleWithLightbox photos={this.state.photos.slice(60, 75)} />
<ExampleCustomComponentSelection photos={this.state.photos.slice(75, 90)} />
Expand Down
Loading