Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Use forwardRef to allow access to ref.measure and others. #419

Merged
merged 1 commit into from
Feb 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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