Skip to content

Commit

Permalink
+ onLoad prop for images
Browse files Browse the repository at this point in the history
  • Loading branch information
sk1e committed Oct 16, 2017
1 parent e07f632 commit 77d0906
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/EnlargedImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ export default class extends React.Component {
src: largeImage.src,
srcSet: largeImage.srcSet,
sizes: largeImage.sizes,
style: objectAssign({}, imageStyle, computedImageStyle)
style: objectAssign({}, imageStyle, computedImageStyle),
onLoad: largeImage.onLoad
}}/>
</div>
);
Expand Down
3 changes: 2 additions & 1 deletion src/ImageShape.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export default PropTypes.shape({
srcSet: PropTypes.string,
sizes: PropTypes.string,
width: PropTypes.number.required,
height: PropTypes.number.required
height: PropTypes.number.required,
onLoad: PropTypes.func,
});
10 changes: 9 additions & 1 deletion src/ReactImageMagnify.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class ReactImageMagnify extends React.Component {
srcSet: PropTypes.string,
sizes: PropTypes.string,
width: requiredIf(PropTypes.number, props => !props.isFluidWidth),
height: requiredIf(PropTypes.number, props => !props.isFluidWidth)
height: requiredIf(PropTypes.number, props => !props.isFluidWidth),
onLoad: PropTypes.func
}),
style: PropTypes.object,
enlargedImagePosition: PropTypes.oneOf(['beside', 'over'])
Expand All @@ -66,10 +67,17 @@ class ReactImageMagnify extends React.Component {

onSmallImageLoad() {
if (!this.props.smallImage.isFluidWidth) {
if (this.props.smallImage.onLoad) {
this.props.smallImage.onLoad.apply(null, arguments);
}
return;
}

this.setSmallImageDimensionState();

if (this.props.smallImage.onLoad) {
this.props.smallImage.onLoad.apply(null, arguments);
}
}

setSmallImageDimensionState() {
Expand Down

0 comments on commit 77d0906

Please sign in to comment.