Skip to content
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

Re-render thumbnails when images change #6

Merged
merged 1 commit into from
Sep 10, 2016
Merged
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
15 changes: 8 additions & 7 deletions src/Gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class Gallery extends Component {

if(this.state.images != np.images){
this.setState({
images: np.images
images: np.images,
thumbnails: this.renderThumbs(this._gallery.clientWidth, np.images)
});
}
}
Expand Down Expand Up @@ -170,16 +171,16 @@ class Gallery extends Component {
* (item.thumbnailWidth / item.thumbnailHeight));
}

renderThumbs (containerWidth) {
if (!this.state.images) return [];
renderThumbs (containerWidth, images = this.state.images) {
if (!images) return [];
if (containerWidth == 0) return [];

var items = this.state.images.slice();
var items = images.slice();
for (var t in items) {
this.setThumbScale(items[t]);
}

var images = [];
var thumbs = [];
var rows = [];
while(items.length > 0) {
rows.push(this.buildImageRow(items, containerWidth));
Expand All @@ -188,10 +189,10 @@ class Gallery extends Component {
for(var r in rows) {
for(var i in rows[r]) {
var item = rows[r][i];
images.push(item);
thumbs.push(item);
}
}
return images;
return thumbs;
}

render () {
Expand Down