-
Notifications
You must be signed in to change notification settings - Fork 468
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
Major fixes #59
Closed
Closed
Major fixes #59
Changes from 4 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6da64f0
Upgrade to RN 0.46
iegik 4c5c8b2
Add console-network, fix Promise
iegik adeee0e
Add preload for specific time
iegik 66147b4
Add preload for specific time
iegik 83286b7
Fix source may be string
iegik 949f96e
Prefer ImageBackground in RN 0.46<
iegik 8d3d00f
Add _clearDepricated on evry 1000 ms
iegik 674a65f
Update react-native-clcashier to 1.0.0
iegik f8afff4
Clean
iegik 3b0a7d0
Fix FS File exists check
iegik 8137cff
Merge branch 'master' into master
iegik 5be0bcd
Add error message
iegik bfe1438
Merge conflicts
iegik d9c8f7f
Merge branch 'master' of https://github.com/iegik/react-native-cached…
iegik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,11 @@ const ImageCacheProvider = require('./ImageCacheProvider'); | |
|
||
const { | ||
View, | ||
Image, | ||
ImageBackground, | ||
ActivityIndicator, | ||
NetInfo, | ||
Platform | ||
Platform, | ||
Text, | ||
} = ReactNative; | ||
|
||
|
||
|
@@ -34,7 +35,7 @@ const styles = StyleSheet.create({ | |
}); | ||
|
||
function getImageProps(props) { | ||
return _.omit(props, ['source', 'defaultSource', 'fallbackSource', 'LoadingIndicator', 'activityIndicatorProps', 'style', 'useQueryParamsInCacheKey', 'renderImage', 'resolveHeaders']); | ||
return _.omit(props, ['source', 'defaultSource', 'fallbackSource', 'LoadingIndicator', 'activityIndicatorProps', 'style', 'useQueryParamsInCacheKey', 'renderImage']); | ||
} | ||
|
||
const CACHED_IMAGE_REF = 'cachedImage'; | ||
|
@@ -47,15 +48,13 @@ const CachedImage = React.createClass({ | |
React.PropTypes.bool, | ||
React.PropTypes.array | ||
]).isRequired, | ||
resolveHeaders: React.PropTypes.func | ||
}, | ||
|
||
getDefaultProps() { | ||
return { | ||
renderImage: props => (<Image ref={CACHED_IMAGE_REF} {...props}/>), | ||
renderImage: props => (<ImageBackground ref={CACHED_IMAGE_REF} {...props}/>), | ||
activityIndicatorProps: {}, | ||
useQueryParamsInCacheKey: false, | ||
resolveHeaders: () => Promise.resolve({}) | ||
}; | ||
}, | ||
|
||
|
@@ -72,7 +71,8 @@ const CachedImage = React.createClass({ | |
return { | ||
isCacheable: false, | ||
cachedImagePath: null, | ||
networkAvailable: true | ||
networkAvailable: true, | ||
errorLoading: false, | ||
}; | ||
}, | ||
|
||
|
@@ -117,20 +117,25 @@ const CachedImage = React.createClass({ | |
processSource(source) { | ||
const url = _.get(source, ['uri'], null); | ||
if (ImageCacheProvider.isCacheable(url)) { | ||
const options = _.pick(this.props, ['useQueryParamsInCacheKey', 'cacheGroup']); | ||
const options = _.pick(this.props, ['useQueryParamsInCacheKey', 'cacheGroup', 'source']); | ||
// try to get the image path from cache | ||
ImageCacheProvider.getCachedImagePath(url, options) | ||
.then(ImageCacheProvider.isExpired) | ||
// try to put the image in cache if | ||
.catch(() => ImageCacheProvider.cacheImage(url, options, this.props.resolveHeaders)) | ||
.catch(() => ImageCacheProvider.cacheImage(url, options)) | ||
.then(cachedImagePath => { | ||
if(!cachedImagePath) { | ||
throw new Error('Failed to cache image') | ||
} | ||
this.safeSetState({ | ||
cachedImagePath | ||
}); | ||
}) | ||
.catch(err => { | ||
this.safeSetState({ | ||
cachedImagePath: null, | ||
isCacheable: false | ||
isCacheable: false, | ||
errorLoading: true, | ||
}); | ||
}); | ||
this.safeSetState({ | ||
|
@@ -147,6 +152,9 @@ const CachedImage = React.createClass({ | |
if (this.state.isCacheable && !this.state.cachedImagePath) { | ||
return this.renderLoader(); | ||
} | ||
if( this.state.errorLoading ) { | ||
return this.renderError(); | ||
} | ||
const props = getImageProps(this.props); | ||
const style = this.props.style || styles.image; | ||
const source = (this.state.isCacheable && this.state.cachedImagePath) ? { | ||
|
@@ -211,6 +219,16 @@ const CachedImage = React.createClass({ | |
style={activityIndicatorStyle}/> | ||
) | ||
}); | ||
}, | ||
|
||
renderError() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We would probably want to give the users a way to render their own errors. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good. |
||
const imageStyle = [this.props.style, styles.loaderPlaceholder]; | ||
const activityIndicatorStyle = this.props.activityIndicatorProps.style || styles.loader; | ||
return ( | ||
<View style={[imageStyle, activityIndicatorStyle]}> | ||
<Text>Error</Text> | ||
</View> | ||
); | ||
} | ||
}); | ||
|
||
|
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"presets": ["react-native"] | ||
} | ||
"presets": ["react-native"] | ||
} |
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
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
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
keystore( | ||
name = 'debug', | ||
store = 'debug.keystore', | ||
properties = 'debug.keystore.properties', | ||
visibility = [ | ||
'PUBLIC', | ||
], | ||
name = "debug", | ||
properties = "debug.keystore.properties", | ||
store = "debug.keystore", | ||
visibility = [ | ||
"PUBLIC", | ||
], | ||
) |
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,4 @@ | ||
{ | ||
"name": "CachedImageExample", | ||
"displayName": "CachedImageExample" | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you prefer
ImageBackground
overImage
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
React recommends to use ImageBackground.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To confirm, using
ImageBackground
would require implementors ofreact-native-cached-image
to update to 0.46? If so and @kfiroo is happy with this, this should probably be denoted as apeerDependency
in thepackage.json
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added alternative in "progressive enhancement" style for ImageBackground facebook/react-native@9637dd4