Skip to content

Commit d6e9bc8

Browse files
committed
🐛 Forward setNativeProps. Makes this component work with TouchableOpacity.
Fixes #1.
1 parent e2635f7 commit d6e9bc8

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

FastImage.js

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,34 @@
1-
import React, { PropTypes } from 'react'
1+
import React, { PropTypes, Component } from 'react'
22
import { requireNativeComponent, Image, View } from 'react-native'
33

44
const resolveAssetSource = require('react-native/Libraries/Image/resolveAssetSource')
55

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)
922
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+
/>
1130
)
1231
}
13-
14-
const resolvedSource = resolveAssetSource(source)
15-
return (
16-
<FastImageView
17-
{...props}
18-
source={resolvedSource}
19-
onFastImageError={onError}
20-
onFastImageLoad={onLoad}
21-
/>
22-
)
2332
}
2433

2534
FastImage.resizeMode = {

0 commit comments

Comments
 (0)