react-native-fast-image icon indicating copy to clipboard operation
react-native-fast-image copied to clipboard

How I can set placeholder image

Open wdayanand opened this issue 6 years ago • 12 comments

wdayanand avatar Aug 23 '18 06:08 wdayanand

I have been setting placeholders like this and it works:

import { placeholder } from '../assets/images'

(...)
render() {
  const imgSource = this.props.imgUri ? { uri: this.props.imgUri } : placeholder

  return (
    <FastImage source={imgSource} style={styles.imageStyle} />
  )
}

Fsarmento avatar Aug 27 '18 14:08 Fsarmento

@Fsarmento your placeholder is not correct. Placeholder must be visible unless source is not dowloaded. Or if source was not downloaded at all(because of some error or not reachable)

In original <Image component there is prop defaultImage which is working on iOS and doing what I have described above.

rendomnet avatar Aug 28 '18 06:08 rendomnet

Oh, I see. There is an older issue for that - #5. In the last comment there is a workaround using 2 overlapped Images.

Fsarmento avatar Aug 28 '18 09:08 Fsarmento

Anyone coming across this. I had done a similar wrapper to manage placeholder images as the previous comment mentions, however you'll start to hit performance issues when you're dealing with a large number of images and having to update state. I found leveraging the ImageBackground component a suitable alternative if you're dealing with non transparent images. Definitely look forward to a native solution via the library itself.

dlferro avatar Sep 11 '18 02:09 dlferro

Really waiting on this!

nica0012 avatar Sep 11 '18 15:09 nica0012

Oh for sure, would love this.

devpascoe avatar Nov 22 '18 03:11 devpascoe

This PR adds placeholder prop https://github.com/DylanVann/react-native-fast-image/pull/409

EgidioCaprino avatar Feb 19 '19 09:02 EgidioCaprino

wrap it in a helper component

({actualSource, placeHolder}) => {
    const [source, setSource] = useState(placeHolder)
    <FastImage  source={source}. onLoadEnd={ () => setSource({uri: actualSource}) }/>
}

byteab avatar Jun 29 '20 07:06 byteab

Seems still no support for a placeholder, following is my workaround for placeholder

<View> { loading && <MImage containerStyle={imageStyle} uri={placeholderUri} /> } <FastImage style={loading?{width:0, height:0}:imageStyle} source={uri} onLoad={()=>{ setTimeout(()=>{ setLoading(false) },100) }} resizeMode={FastImage.resizeMode.contain} /> </View>

muhammad786 avatar Jul 13 '20 09:07 muhammad786

Seems still no support for a placeholder, following is my workaround for placeholder

<View> { loading && <MImage containerStyle={imageStyle} uri={placeholderUri} /> } <FastImage style={loading?{width:0, height:0}:imageStyle} source={uri} onLoad={()=>{ setTimeout(()=>{ setLoading(false) },100) }} resizeMode={FastImage.resizeMode.contain} /> </View>

I did something like that but I noticed that I lost the cache feature... I mean, every time I "rerender" my component I see the placeholder and after some milliseconds I see the real image

chramos avatar Aug 04 '21 11:08 chramos

                    <ImageBackground
                        style={styles.dp}
                        source={require('../../assets/item-img-placeholder.png')} >
                        <FastImage
                            style={styles.dp]}
                            source={{
                                uri: state.image,
                            }}
                        />
                    </ImageBackground>

AJV2018 avatar Jan 21 '22 06:01 AJV2018

                    <ImageBackground
                        style={styles.dp}
                        source={require('../../assets/item-img-placeholder.png')} >
                        <FastImage
                            style={styles.dp]}
                            source={{
                                uri: state.image,
                            }}
                        />
                    </ImageBackground>

wrap inside imagebackground took more performance

fukemy avatar Apr 14 '22 08:04 fukemy

This library now supports defaultSource, if that doesn't meet your needs you could try something else from this thread, like the layering solution.

DylanVann avatar Aug 29 '22 04:08 DylanVann

It's super laggy with default source with Flashlist (didn't try with flatlist)

yoann84 avatar Nov 23 '22 13:11 yoann84