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 487d410 commit a0676bc
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 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,16 +24,14 @@ 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}
>
<View style={[styles.imageContainer, style]} ref={ref}>
<Image
{...props}
style={StyleSheet.absoluteFill}
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 a0676bc

Please sign in to comment.