Skip to content

Commit

Permalink
Load local assets synchronously to prevent image flicker
Browse files Browse the repository at this point in the history
Summary:
This uses `[UIImage imageNamed:]` to load local assets that are bundled using `require('../image/path.png')` and makes sure it is done synchronously on the main queue to prevent images from flickering. This improves user experience a lot when using large local images and prevents icon flickers to match the behaviour of most native apps.

This adds to methods to the ImageLoader protocol, one to tell if the image loader must be executed on the url cache queue and one to tell if the result of the image loader should be cached. I then use these to make the LocalImageLoader bypass the url cache queue and avoid caching images twice.

Note that this doesn't affect debug builds since images are loaded from the packager.

I'm not sure if we want to still support async loading of local images as I'm not sure how much of a perf difference this will make. Maybe someone at fb can benchmark this see how it affects your apps but there wasn't a noticeable one in mine. Also I only enabled this for loading png and jpg im
Closes facebook/react-native#8102

Reviewed By: bnham

Differential Revision: D3433647

Pulled By: javache

fbshipit-source-id: 37bd6aff20c0465c163db3cdbcaeaedff55f7b1f
  • Loading branch information
janicduplessis authored and Facebook Github Bot 2 committed Jul 21, 2016
1 parent 466d421 commit 49b75e9
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions UIExplorer/js/ImageExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,20 @@ exports.examples = [
},
platform: 'android',
},
{
title: 'Legacy local image',
description:
'Images shipped with the native bundle, but not managed ' +
'by the JS packager',
render: function() {
return (
<Image
source={require('image!hawk')}
style={styles.base}
/>
);
},
},
];

var fullImage = {uri: 'http://facebook.github.io/react/img/logo_og.png'};
Expand Down

0 comments on commit 49b75e9

Please sign in to comment.