perf: Use React.memo for FastImage. (#449)
This commit is contained in:
parent
89c0e2e9ac
commit
5c2b4afa41
24
src/index.js
24
src/index.js
|
@ -1,4 +1,4 @@
|
|||
import React, { forwardRef } from 'react'
|
||||
import React, { forwardRef, memo } from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import {
|
||||
View,
|
||||
|
@ -11,9 +11,7 @@ import {
|
|||
|
||||
const FastImageViewNativeModule = NativeModules.FastImageView
|
||||
|
||||
const FastImage = forwardRef(
|
||||
(
|
||||
{
|
||||
function FastImageBase({
|
||||
source,
|
||||
onLoadStart,
|
||||
onProgress,
|
||||
|
@ -23,15 +21,14 @@ const FastImage = forwardRef(
|
|||
style,
|
||||
children,
|
||||
fallback,
|
||||
forwardedRef,
|
||||
...props
|
||||
},
|
||||
ref,
|
||||
) => {
|
||||
}) {
|
||||
const resolvedSource = Image.resolveAssetSource(source)
|
||||
|
||||
if (fallback) {
|
||||
return (
|
||||
<View style={[styles.imageContainer, style]} ref={ref}>
|
||||
<View style={[styles.imageContainer, style]} ref={forwardedRef}>
|
||||
<Image
|
||||
{...props}
|
||||
style={StyleSheet.absoluteFill}
|
||||
|
@ -48,7 +45,7 @@ const FastImage = forwardRef(
|
|||
}
|
||||
|
||||
return (
|
||||
<View style={[styles.imageContainer, style]} ref={ref}>
|
||||
<View style={[styles.imageContainer, style]} ref={forwardedRef}>
|
||||
<FastImageView
|
||||
{...props}
|
||||
style={StyleSheet.absoluteFill}
|
||||
|
@ -62,8 +59,13 @@ const FastImage = forwardRef(
|
|||
{children}
|
||||
</View>
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
const FastImageMemo = memo(FastImageBase)
|
||||
|
||||
const FastImage = forwardRef((props, ref) => (
|
||||
<FastImageMemo forwardedRef={ref} {...props} />
|
||||
))
|
||||
|
||||
FastImage.displayName = 'FastImage'
|
||||
|
||||
|
|
Loading…
Reference in New Issue