mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-06-03 02:42:05 +00:00
[fix] Image 'source' prop update when missing in initial render
Close #811
This commit is contained in:
committed by
Nicolas Gallagher
parent
fb4635e013
commit
748b2d0f3f
@@ -180,6 +180,20 @@ describe('components/Image', () => {
|
|||||||
.attr('src')
|
.attr('src')
|
||||||
).toBe(uriTwo);
|
).toBe(uriTwo);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('is correctly updated when missing in initial render', () => {
|
||||||
|
jest.useFakeTimers();
|
||||||
|
const uri = 'https://testing.com/img.jpg';
|
||||||
|
const component = mount(<Image />);
|
||||||
|
component.setProps({ source: { uri } });
|
||||||
|
jest.runOnlyPendingTimers();
|
||||||
|
expect(
|
||||||
|
component
|
||||||
|
.render()
|
||||||
|
.find('img')
|
||||||
|
.attr('src')
|
||||||
|
).toBe(uri);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('prop "style"', () => {
|
describe('prop "style"', () => {
|
||||||
|
|||||||
+2
-2
@@ -168,8 +168,8 @@ class Image extends Component<*, State> {
|
|||||||
if (uri !== nextUri) {
|
if (uri !== nextUri) {
|
||||||
ImageUriCache.remove(uri);
|
ImageUriCache.remove(uri);
|
||||||
const isPreviouslyLoaded = ImageUriCache.has(nextUri);
|
const isPreviouslyLoaded = ImageUriCache.has(nextUri);
|
||||||
isPreviouslyLoaded && ImageUriCache.add(uri);
|
isPreviouslyLoaded && ImageUriCache.add(nextUri);
|
||||||
this._updateImageState(getImageState(uri, isPreviouslyLoaded));
|
this._updateImageState(getImageState(nextUri, isPreviouslyLoaded));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user