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

How I can set placeholder image #265

Closed
wdayanand opened this issue Aug 23, 2018 · 14 comments
Closed

How I can set placeholder image #265

wdayanand opened this issue Aug 23, 2018 · 14 comments

Comments

@wdayanand
Copy link

No description provided.

@wdayanand wdayanand changed the title How i can set placeholder image How I can set placeholder image Aug 23, 2018
@Fsarmento
Copy link

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} />
  )
}

@rendomnet
Copy link

rendomnet commented Aug 28, 2018

@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.

@Fsarmento
Copy link

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

@dlferro
Copy link

dlferro commented Sep 11, 2018

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.

@nica0012
Copy link

Really waiting on this!

@devpascoe
Copy link

Oh for sure, would love this.

@EgidioCaprino
Copy link

This PR adds placeholder prop #409

@byteab
Copy link

byteab commented Jun 29, 2020

wrap it in a helper component

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

@muhammad786
Copy link

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>

@chramos
Copy link

chramos commented Aug 4, 2021

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

@AJV2018
Copy link

AJV2018 commented Jan 21, 2022

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

@fukemy
Copy link

fukemy commented Apr 14, 2022

                    <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

@DylanVann
Copy link
Owner

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

@yoann84
Copy link

yoann84 commented Nov 23, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests