Skip to content
This repository has been archived by the owner on Feb 3, 2024. It is now read-only.

add resizeMode and thumbnailSource optional #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
Binary file added .DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,19 @@ import ProgressiveImage from 'react-native-progressive-image'

const TheProgressiveImage = () =>
<ProgressiveImage
placeHolderSource={require('images/placeholder.png')}
thumbnailSource={{ uri: 'http://i.imgur.com/O249H4P.png?bust' + Math.random() }}
imageSource={{ uri: 'http://i.imgur.com/741u15U.png?bust' + Math.random() }}
style={{ flex: 1, alignItems: 'stretch' }}
resizeMode="cover"
/>
```

## Properties

| Prop | Description | Default |
|---|---|---|
| **`placeHolderSource`** | PlaceHolder source (e.g. require('./image.jpg')). | None |
| **`imageSource`** | Image source (e.g. { uri: 'https://facebook.github.io/react/img/logo_og.png' }). | None |
| **`thumbnailSource`** | Should be a low resolution version of the image used in `imageSource`. | None |
| **`thumbnailBlurRadius`** | Blur radius for the low resolution thumbnail (iOS only). | `5` |
Expand All @@ -44,6 +47,7 @@ const TheProgressiveImage = () =>
| **`thumbnailFadeDuration`** | Fade-in duration for the thumbnail in ms. | `250` |
| **`onLoadThumbnail`** | Callback function that gets called when the thumbnail is loaded. | `noop` |
| **`onLoadImage`** | Callback function that gets called when the main image is loaded. | `noop` |
| **`resizeMode`** | Image resizeMode (e.g. resizeMode="cover". | None |

## Credits

Expand Down
Binary file added example/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/images/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import ProgressiveImage from 'react-native-progressive-image'

const TheProgressiveImage = () =>
<ProgressiveImage
placeHolderSource={require('images/placeholder.png')}
thumbnailSource={{ uri: 'http://i.imgur.com/W3LKLla.png?bust' + Math.random() }}
imageSource={{ uri: 'http://i.imgur.com/741u15U.png?bust' + Math.random() }}
style={{ flex: 1, alignItems: 'stretch' }}
resizeMode="cover"
/>

export default () =>
Expand Down
24 changes: 14 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,21 @@ export default class ProgressiveImage extends Component {
return (
<View style={this.props.style}>
<Image
resizeMode="cover"
resizeMode={this.props.resizeMode}
style={[styles.image, this.props.style]}
source={this.props.placeHolderSource}
/>
{this.props.thumbnailSource &&
<Animated.Image
resizeMode={this.props.resizeMode}
style={[styles.image, { opacity: this.state.thumbnailOpacity }, this.props.style]}
source={this.props.thumbnailSource}
onLoad={() => this.onLoadThumbnail()}
blurRadius={this.props.thumbnailBlurRadius}
/>
}
<Animated.Image
resizeMode="cover"
style={[styles.image, { opacity: this.state.thumbnailOpacity }, this.props.style]}
source={this.props.thumbnailSource}
onLoad={() => this.onLoadThumbnail()}
blurRadius={this.props.thumbnailBlurRadius}
/>
<Animated.Image
resizeMode="cover"
resizeMode={this.props.resizeMode}
style={[styles.image, { opacity: this.state.imageOpacity }, this.props.style]}
source={this.props.imageSource}
onLoad={() => this.onLoadImage()}
Expand All @@ -69,9 +71,10 @@ ProgressiveImage.propTypes = {
imageFadeDuration: PropTypes.number.isRequired,
onLoadThumbnail: PropTypes.func.isRequired,
onLoadImage: PropTypes.func.isRequired,
thumbnailSource: PropTypes.object.isRequired,
thumbnailSource: PropTypes.object,
thumbnailFadeDuration: PropTypes.number.isRequired,
thumbnailBlurRadius: PropTypes.number,
resizeMode: PropTypes.string.isRequired
}

ProgressiveImage.defaultProps = {
Expand All @@ -80,4 +83,5 @@ ProgressiveImage.defaultProps = {
thumbnailBlurRadius: 5,
onLoadThumbnail: Function.prototype,
onLoadImage: Function.prototype,
resizeMode: 'cover'
}