Skip to content

Commit

Permalink
feat: Use forwardRef to allow access to ref.measure and others.
Browse files Browse the repository at this point in the history
This uses forwardRef to allow access to the View that wraps the native FastImage component.

closes #69
  • Loading branch information
DylanVann committed Feb 25, 2019
1 parent 1ae24fc commit d345850
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Component } from 'react'
import React, { forwardRef } from 'react'
import PropTypes from 'prop-types'
import {
View,
Expand All @@ -11,15 +11,9 @@ import {

const FastImageViewNativeModule = NativeModules.FastImageView

class FastImage extends Component {
setNativeProps(nativeProps) {
this._root.setNativeProps(nativeProps)
}

captureRef = e => (this._root = e)

render() {
const {
const FastImage = forwardRef(
(
{
source,
onLoadStart,
onProgress,
Expand All @@ -30,17 +24,15 @@ class FastImage extends Component {
children,
fallback,
...props
} = this.props

},
ref,
) => {
const resolvedSource = Image.resolveAssetSource(source)

if (fallback) {
return (
<View
style={[styles.imageContainer, style]}
ref={this.captureRef}
>
<FastImageView
<View style={[styles.imageContainer, style]} ref={ref}>
<FastImage
{...props}
style={StyleSheet.absoluteFill}
source={resolvedSource}
Expand All @@ -56,7 +48,7 @@ class FastImage extends Component {
}

return (
<View style={[styles.imageContainer, style]} ref={this.captureRef}>
<View style={[styles.imageContainer, style]} ref={ref}>
<FastImageView
{...props}
style={StyleSheet.absoluteFill}
Expand All @@ -70,8 +62,10 @@ class FastImage extends Component {
{children}
</View>
)
}
}
},
)

FastImage.displayName = 'FastImage'

const styles = StyleSheet.create({
imageContainer: {
Expand Down

0 comments on commit d345850

Please sign in to comment.