mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-06-01 18:15:13 +00:00
@@ -1,12 +1,10 @@
|
|||||||
/* eslint-env jasmine, jest */
|
/* eslint-env jasmine, jest */
|
||||||
|
|
||||||
import ExecutionEnvironment from 'fbjs/lib/ExecutionEnvironment';
|
|
||||||
import Image from '../';
|
import Image from '../';
|
||||||
import ImageUriCache from '../ImageUriCache';
|
import ImageUriCache from '../ImageUriCache';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { mount, render, shallow } from 'enzyme';
|
import { mount, shallow } from 'enzyme';
|
||||||
|
|
||||||
const originalCanUseDOM = ExecutionEnvironment.canUseDOM;
|
|
||||||
const originalImage = window.Image;
|
const originalImage = window.Image;
|
||||||
|
|
||||||
describe('components/Image', () => {
|
describe('components/Image', () => {
|
||||||
@@ -137,15 +135,6 @@ describe('components/Image', () => {
|
|||||||
.attr('src')
|
.attr('src')
|
||||||
).toBe(uriTwo);
|
).toBe(uriTwo);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('is set immediately when rendered on the server', () => {
|
|
||||||
ExecutionEnvironment.canUseDOM = false;
|
|
||||||
const uri = 'https://google.com/favicon.ico';
|
|
||||||
const component = render(<Image source={{ uri }} />);
|
|
||||||
expect(component.find('img').attr('src')).toBe(uri);
|
|
||||||
expect(ImageUriCache.has(uri)).toBe(true);
|
|
||||||
ExecutionEnvironment.canUseDOM = originalCanUseDOM;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('prop "style"', () => {
|
describe('prop "style"', () => {
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import applyNativeMethods from '../../modules/applyNativeMethods';
|
import applyNativeMethods from '../../modules/applyNativeMethods';
|
||||||
import { canUseDOM } from 'fbjs/lib/ExecutionEnvironment';
|
|
||||||
import createElement from '../../modules/createElement';
|
import createElement from '../../modules/createElement';
|
||||||
import { getAssetByID } from '../../modules/AssetRegistry';
|
import { getAssetByID } from '../../modules/AssetRegistry';
|
||||||
import ImageLoader from '../../modules/ImageLoader';
|
import ImageLoader from '../../modules/ImageLoader';
|
||||||
@@ -131,7 +130,7 @@ class Image extends Component {
|
|||||||
super(props, context);
|
super(props, context);
|
||||||
// If an image has been loaded before, render it immediately
|
// If an image has been loaded before, render it immediately
|
||||||
const uri = resolveAssetSource(props.source);
|
const uri = resolveAssetSource(props.source);
|
||||||
const shouldDisplaySource = ImageUriCache.has(uri) || !canUseDOM;
|
const shouldDisplaySource = ImageUriCache.has(uri);
|
||||||
this.state = { shouldDisplaySource };
|
this.state = { shouldDisplaySource };
|
||||||
this._imageState = getImageState(uri, shouldDisplaySource);
|
this._imageState = getImageState(uri, shouldDisplaySource);
|
||||||
shouldDisplaySource && ImageUriCache.add(uri);
|
shouldDisplaySource && ImageUriCache.add(uri);
|
||||||
|
|||||||
Reference in New Issue
Block a user