Skip to content

Commit c9f3561

Browse files
authored
Merge pull request #6 from cust0dian/fix-no-render-on-props-change
Re-render thumbnails when images change.
2 parents 3becb86 + 0216f8e commit c9f3561

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/Gallery.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ class Gallery extends Component {
3838

3939
if(this.state.images != np.images){
4040
this.setState({
41-
images: np.images
41+
images: np.images,
42+
thumbnails: this.renderThumbs(this._gallery.clientWidth, np.images)
4243
});
4344
}
4445
}
@@ -170,16 +171,16 @@ class Gallery extends Component {
170171
* (item.thumbnailWidth / item.thumbnailHeight));
171172
}
172173

173-
renderThumbs (containerWidth) {
174-
if (!this.state.images) return [];
174+
renderThumbs (containerWidth, images = this.state.images) {
175+
if (!images) return [];
175176
if (containerWidth == 0) return [];
176177

177-
var items = this.state.images.slice();
178+
var items = images.slice();
178179
for (var t in items) {
179180
this.setThumbScale(items[t]);
180181
}
181182

182-
var images = [];
183+
var thumbs = [];
183184
var rows = [];
184185
while(items.length > 0) {
185186
rows.push(this.buildImageRow(items, containerWidth));
@@ -188,10 +189,10 @@ class Gallery extends Component {
188189
for(var r in rows) {
189190
for(var i in rows[r]) {
190191
var item = rows[r][i];
191-
images.push(item);
192+
thumbs.push(item);
192193
}
193194
}
194-
return images;
195+
return thumbs;
195196
}
196197

197198
render () {

0 commit comments

Comments
 (0)