|
1 | | -import React, { PropTypes } from 'react' |
| 1 | +import React, { PropTypes, Component } from 'react' |
2 | 2 | import { requireNativeComponent, Image, View } from 'react-native' |
3 | 3 |
|
4 | 4 | const resolveAssetSource = require('react-native/Libraries/Image/resolveAssetSource') |
5 | 5 |
|
6 | | -const FastImage = ({ source, onError, onLoad, ...props }) => { |
7 | | - // If there's no source or source uri just fallback to Image. |
8 | | - if (!source || !source.uri) { |
| 6 | +class FastImage extends Component { |
| 7 | + setNativeProps(nativeProps) { |
| 8 | + this._root.setNativeProps(nativeProps) |
| 9 | + } |
| 10 | + |
| 11 | + render() { |
| 12 | + const { source, onError, onLoad, ...props } = this.props |
| 13 | + |
| 14 | + // If there's no source or source uri just fallback to Image. |
| 15 | + if (!source || !source.uri) { |
| 16 | + return ( |
| 17 | + <Image {...props} source={source} onError={onError} onLoad={onLoad} /> |
| 18 | + ) |
| 19 | + } |
| 20 | + |
| 21 | + const resolvedSource = resolveAssetSource(source) |
9 | 22 | return ( |
10 | | - <Image {...props} source={source} onError={onError} onLoad={onLoad} /> |
| 23 | + <FastImageView |
| 24 | + ref={e => this._root = e} |
| 25 | + {...props} |
| 26 | + source={resolvedSource} |
| 27 | + onFastImageError={onError} |
| 28 | + onFastImageLoad={onLoad} |
| 29 | + /> |
11 | 30 | ) |
12 | 31 | } |
13 | | - |
14 | | - const resolvedSource = resolveAssetSource(source) |
15 | | - return ( |
16 | | - <FastImageView |
17 | | - {...props} |
18 | | - source={resolvedSource} |
19 | | - onFastImageError={onError} |
20 | | - onFastImageLoad={onLoad} |
21 | | - /> |
22 | | - ) |
23 | 32 | } |
24 | 33 |
|
25 | 34 | FastImage.resizeMode = { |
|
0 commit comments