-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
Allow prefetch remote image #4420
Conversation
By analyzing the blame information on this pull request, we identified @brentvatne, @mkonicek and @sahrens to be potential reviewers. |
Can we add this facility to the existing RCTNetworking module? I don't really see the need to add a second module for making network requests when we already have one. Also, we should be providing JS wrappers for all native module functions. Accessing native modules directly makes it hard to manage cross-platform differences. |
I like the idea of this, On iOS I've been toying with adding an ImageLoader.preload() method. I might still add this, but it wouldn't be applicable to loading font files, or any non-images, which would also be useful. The advantages of making this a method of the ImageLoader module (at least on iOS) are:
The disadvantages are:
I think I need to discuss this with @dmmiller |
It's a good idea to use the 'RCTNetworking' native module. I'll fix that. |
@sospartan updated the pull request. |
@sospartan updated the pull request. |
1 similar comment
@sospartan updated the pull request. |
@nicklockwood @dmmiller I've added ios version. Like to hear your opinions on this pull request. |
mFontCache.put(fontFamilyName, fontFamily); | ||
fontFamily.setTypeface(style, typeface); | ||
} | ||
} catch (RuntimeException e) { |
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.
Consider logging.
@mkonicek thanks for the suggestions. |
@sospartan updated the pull request. |
@sospartan - thanks for your work here! looking forward to this landing 😄 |
@brentvatne Glad to contribute to this project . |
@brentvatne @mkonicek @nicklockwood Any updates? |
@sospartan updated the pull request. |
@sospartan - I'll leave this one up to @nicklockwood and @mkonicek, they are smarter than me |
The font loading logic seems quite complex. Would you mind splitting this into two PRs? One for images, one for fonts, to make it easier to review? |
How does |
|
||
{this.state.startLoadPrefetched? | ||
<Image | ||
source={this.props.sourcePrefetch} |
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.
nit: name this prefetchedSource
I agree that this font loading approach looks complicated. What we do in our own projects is implement this entirely in JS except for downloading and installing the font (on iOS at least). This way the behavior of the font loader is something that we can customize instead of having it be something arbitrarily chosen by RN core. We try to keep code in user space. Could the font loader be published as its own package to npm? |
👍 Agree with @ide. |
There is no API provided to implement 'downloading' in pure JS as far as i known, because the lacking of 'File' API. All the behaviors behind this pull request are same as the original Text did: Font file loading failed(or render before download finish) will act same as the assets' font file is missing. I'll reconsider the font part. It's uncompleted as your said and not necessary related to the image part. |
@nicklockwood I think it does actually. See here: expo@d455cb6#diff-f8703d50cf5af4c06824e2928dddb500R504 Am I doing this wrong? It seems to work for our use case. |
@skevy oh, hmm. I guess I was mistaken. |
Summary: Expose method to implement changing font family cache. Like ide suggested in facebook#4420 , this will helpful for using remote font file (use `Typeface#createFromFile` to load downloaded font file). iOS's CoreText already allow this in native code. Closes facebook#4696 Reviewed By: bestander Differential Revision: D2911762 Pulled By: andreicoman11 fb-gh-sync-id: a931e2e711dd94fa0df6fdd066827756d862a4ba
uri = Uri.parse(url); | ||
} | ||
} catch (Exception e){ | ||
//ignore malformed url |
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.
nit: space after //
@skevy Should this PR use that? Or do you want to submit your implementation instead of this PR? |
Seems reasonable for it to use my implementation. Any thoughts @sospartan ? |
@sospartan Should we close this PR then? I hope you'll continue contributing in the future :) |
@skevy I'd be happy to accept your implementation; The only changes I'd ask for are 1) not to use the |
@nicklockwood sweet. Thanks. I will submit a new PR sometime in the very near future. |
@sospartan thanks for the initial work on this! |
Summary:Adds `Image.prefetch` to prefetch remote images before they are used in an actual `Image` component. This is based off of #4420 by sospartan and skevy's work. Closes #6774 Differential Revision: D3153729 Pulled By: bestander fb-gh-sync-id: ef61412e051a49b42ae885edce7905a8ca0da23f fbshipit-source-id: ef61412e051a49b42ae885edce7905a8ca0da23f
Summary:Adds `Image.prefetch` to prefetch remote images before they are used in an actual `Image` component. This is based off of #4420 by sospartan and skevy's work. Closes facebook/react-native#6774 Differential Revision: D3153729 Pulled By: bestander fb-gh-sync-id: ef61412e051a49b42ae885edce7905a8ca0da23f fbshipit-source-id: ef61412e051a49b42ae885edce7905a8ca0da23f
Summary:Adds `Image.prefetch` to prefetch remote images before they are used in an actual `Image` component. This is based off of facebook#4420 by sospartan and skevy's work. Closes facebook#6774 Differential Revision: D3153729 Pulled By: bestander fb-gh-sync-id: ef61412e051a49b42ae885edce7905a8ca0da23f fbshipit-source-id: ef61412e051a49b42ae885edce7905a8ca0da23f
Summary:Adds `Image.prefetch` to prefetch remote images before they are used in an actual `Image` component. This is based off of facebook#4420 by sospartan and skevy's work. Closes facebook#6774 Differential Revision: D3153729 Pulled By: bestander fb-gh-sync-id: ef61412e051a49b42ae885edce7905a8ca0da23f fbshipit-source-id: ef61412e051a49b42ae885edce7905a8ca0da23f
Allow prefetch remote image to disk cache for later use .
This will be useful for prepare important image before render (e.g. background image )