forked from xiaolin/react-image-gallery
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize renderItem so its memoized xiaolin#423
Deprecate imageSet
- Loading branch information
Showing
7 changed files
with
102 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React from 'react'; | ||
import { bool, func, string } from 'prop-types'; | ||
|
||
const Item = React.memo(({ | ||
description, | ||
fullscreen, // fullscreen version of img | ||
handleImageLoaded, | ||
isFullscreen, | ||
onImageError, | ||
original, | ||
originalAlt, | ||
originalHeight, | ||
originalWidth, | ||
originalTitle, | ||
sizes, | ||
srcSet, | ||
}) => { | ||
const itemSrc = isFullscreen ? (fullscreen || original) : original; | ||
|
||
return ( | ||
<React.Fragment> | ||
<img | ||
className="image-gallery-image" | ||
src={itemSrc} | ||
alt={originalAlt} | ||
srcSet={srcSet} | ||
height={originalHeight} | ||
width={originalWidth} | ||
sizes={sizes} | ||
title={originalTitle} | ||
onLoad={event => handleImageLoaded(event, original)} | ||
onError={onImageError} | ||
/> | ||
{ | ||
description && ( | ||
<span className="image-gallery-description"> | ||
{description} | ||
</span> | ||
) | ||
} | ||
</React.Fragment> | ||
); | ||
}); | ||
|
||
Item.displayName = 'Item'; | ||
|
||
Item.propTypes = { | ||
description: string, | ||
fullscreen: string, // fullscreen version of img | ||
handleImageLoaded: func.isRequired, | ||
isFullscreen: bool, | ||
onImageError: func.isRequired, | ||
original: string.isRequired, | ||
originalAlt: string, | ||
originalHeight: string, | ||
originalWidth: string, | ||
originalTitle: string, | ||
sizes: string, | ||
srcSet: string, | ||
}; | ||
|
||
Item.defaultProps = { | ||
description: '', | ||
fullscreen: '', | ||
isFullscreen: false, | ||
originalAlt: '', | ||
originalHeight: '', | ||
originalWidth: '', | ||
originalTitle: '', | ||
sizes: '', | ||
srcSet: '', | ||
}; | ||
|
||
export default Item; |
Binary file not shown.
Binary file not shown.
Binary file not shown.