From 123516d5563037d09d3a15485281a274fd6b55ad Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Mon, 19 Oct 2015 10:24:01 -0700 Subject: [PATCH] Reload RCTImageView when it's displaying the default image Summary: public If the frame is set, or the image view moves to a window, we should attempt to load the "real" image. The sizing logic shouldn't kick in if we're only displaying the default image. Resolves https://github.com/facebook/react-native/issues/3460. Reviewed By: tadeuzagallo Differential Revision: D2555316 fb-gh-sync-id: c0c13070ee080bad2b30ca01d9d5173bead406e3 --- .../blue_square.imageset/Contents.json | 21 +++++++++ .../blue_square.imageset/blue_square.png | Bin 0 -> 128 bytes .../red_square.imageset/Contents.json | 21 +++++++++ .../red_square.imageset/red_square.png | Bin 0 -> 129 bytes .../testImageSnapshotTest_1@2x.png | Bin 0 -> 15582 bytes .../UIExplorerIntegrationTests.m | 1 + .../blue_square.png | Bin 0 -> 128 bytes .../js/ImageSnapshotTest.js | 42 ++++++++++++++++++ .../js/IntegrationTestsApp.js | 1 + .../UIExplorerIntegrationTests/red_square.png | Bin 0 -> 129 bytes Libraries/Image/RCTImageView.m | 5 ++- 11 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 Examples/UIExplorer/UIExplorer/Images.xcassets/blue_square.imageset/Contents.json create mode 100644 Examples/UIExplorer/UIExplorer/Images.xcassets/blue_square.imageset/blue_square.png create mode 100644 Examples/UIExplorer/UIExplorer/Images.xcassets/red_square.imageset/Contents.json create mode 100644 Examples/UIExplorer/UIExplorer/Images.xcassets/red_square.imageset/red_square.png create mode 100644 Examples/UIExplorer/UIExplorerIntegrationTests/ReferenceImages/Examples-UIExplorer-UIExplorerIntegrationTests-js-IntegrationTestsApp/testImageSnapshotTest_1@2x.png create mode 100644 Examples/UIExplorer/UIExplorerIntegrationTests/blue_square.png create mode 100644 Examples/UIExplorer/UIExplorerIntegrationTests/js/ImageSnapshotTest.js create mode 100644 Examples/UIExplorer/UIExplorerIntegrationTests/red_square.png diff --git a/Examples/UIExplorer/UIExplorer/Images.xcassets/blue_square.imageset/Contents.json b/Examples/UIExplorer/UIExplorer/Images.xcassets/blue_square.imageset/Contents.json new file mode 100644 index 000000000..5de78da51 --- /dev/null +++ b/Examples/UIExplorer/UIExplorer/Images.xcassets/blue_square.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x", + "filename" : "blue_square.png" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Examples/UIExplorer/UIExplorer/Images.xcassets/blue_square.imageset/blue_square.png b/Examples/UIExplorer/UIExplorer/Images.xcassets/blue_square.imageset/blue_square.png new file mode 100644 index 0000000000000000000000000000000000000000..4974e084c6365279b9dc6651a76e74bfda71f527 GIT binary patch literal 128 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz!4lVqlHmNblJdl&REC1Q^yH$_ z;tYpU&(Aaw2e08*!0}4oxtq9@$kyX(C?FdjC NgQu&X%Q~loCID_YCKLbw literal 0 HcmV?d00001 diff --git a/Examples/UIExplorer/UIExplorerIntegrationTests/ReferenceImages/Examples-UIExplorer-UIExplorerIntegrationTests-js-IntegrationTestsApp/testImageSnapshotTest_1@2x.png b/Examples/UIExplorer/UIExplorerIntegrationTests/ReferenceImages/Examples-UIExplorer-UIExplorerIntegrationTests-js-IntegrationTestsApp/testImageSnapshotTest_1@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..41492574c587490b1724e70c2153b9eac87a8652 GIT binary patch literal 15582 zcmeI3F>4e-6vy9gF7b>Ww+1942-jK|&fa1T7tDbMQ45>Ei5SHqYP=Bb7SqIDM7w+d z71N}!@(Tze#6TJ?Ed&d#w9px3VK{c5`+v$~Sm&C+4*&P&X5Me#n>Uw-=NHbjCXY@M zQL8`SyFe6YMD5Mygn4pv`}vOfb7(ksd3f>G(s1p{$~C&ZeEsUm>fIaZYX2+Isf~W` z^rd@ypWkn_sGGzmzy0`fc6)yP#1`!=zME;&;LSK?$K!-jim5{pCB}X;C2DkxuY@RS zQbvuU;gZMyUR6E?&KINlF!u7?<9*bf&SnVs!nrqWndB;bORO(krM8hKrUbs2jbs88 zS24yI7;qJ1i~&ze#Y};DHQ*}77{eE?>d+#AFE$xPGL?V_zbUej5ZJ?cu&-?`6;6>2 zQ(VP>%w#ECmC`HnIq%^-_)U?G1b_2h-6-;%J@nilO_akZRF6@Gb6F9Zp?dV2B3m*^ z@}3rZg$;nBKy!)&L1`O(ibM6NR|m>!PG^h%5CQHmuEKfnn TestModule.verifySnapshot(this.done)} /> + ); + } +}); + +ImageSnapshotTest.displayName = 'ImageSnapshotTest'; + +module.exports = ImageSnapshotTest; diff --git a/Examples/UIExplorer/UIExplorerIntegrationTests/js/IntegrationTestsApp.js b/Examples/UIExplorer/UIExplorerIntegrationTests/js/IntegrationTestsApp.js index ce9704f80..5ab306386 100644 --- a/Examples/UIExplorer/UIExplorerIntegrationTests/js/IntegrationTestsApp.js +++ b/Examples/UIExplorer/UIExplorerIntegrationTests/js/IntegrationTestsApp.js @@ -31,6 +31,7 @@ var TESTS = [ require('./LayoutEventsTest'), require('./AppEventsTest'), require('./SimpleSnapshotTest'), + require('./ImageSnapshotTest'), require('./PromiseTest'), ]; diff --git a/Examples/UIExplorer/UIExplorerIntegrationTests/red_square.png b/Examples/UIExplorer/UIExplorerIntegrationTests/red_square.png new file mode 100644 index 0000000000000000000000000000000000000000..0977a3e8cf337e4643e10293b92e129711ce106c GIT binary patch literal 129 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz!4lVqlHmNblJdl&REC1Q^yH$_ z;tYpU&(Aaw2e08*!0}4oxtq9@$kyX(C?FdjC NgQu&X%Q~loCID_YCKLbw literal 0 HcmV?d00001 diff --git a/Libraries/Image/RCTImageView.m b/Libraries/Image/RCTImageView.m index 5926f6331..049eb36ac 100644 --- a/Libraries/Image/RCTImageView.m +++ b/Libraries/Image/RCTImageView.m @@ -210,7 +210,8 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init) - (void)reactSetFrame:(CGRect)frame { [super reactSetFrame:frame]; - if (self.image == nil) { + + if (!self.image || self.image == _defaultImage) { _targetSize = frame.size; [self reloadImage]; } else if ([RCTImageView srcNeedsReload:_src]) { @@ -254,7 +255,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init) [strongSelf clearImage]; } }); - } else if (!self.image && self.src) { + } else if (!self.image || self.image == _defaultImage) { [self reloadImage]; } }