react-native-image-cache-wrapper icon indicating copy to clipboard operation
react-native-image-cache-wrapper copied to clipboard

Setting default image before url

Open Dellybro opened this issue 6 years ago • 0 comments

When i set a default image before obtaining the signedURL from AWS to get my image, the CachedImage component never render the URL and just keeps my default Image.

This works on a regular Image view but not the cachedImage

` function S3ImageLoader(props) { const { media, style } = props;

let [photoUrl, setPhotoUrl] = useState(DefaultUser)
let [loading, setLoading] = useState(true)


useEffect(() => {
    getPhotoUrl()
}, [])

async function getPhotoUrl() {
    if(!media.key || !media.bucket) {
        return setPhotoUrl(DefaultUser)
    }

    var url = S3.getSignedUrl('getObject', {Bucket: media.bucket, Key: media.key});
    setPhotoUrl({uri: url});

    // URL is logged as expected.
    console.log(url);
}

return (
    <Lightbox style={[styles.lightbox, style]}>
        <React.Fragment>
            {
                loading ? 
                <Spinner style={styles.loading} color={Red700}/> : null
            }
            <CachedImage 
                resizeMode="cover"
                indicatorProps={ImageIndicator}
                onLoadStart={() => setLoading(true)}
                onLoadEnd={() => setLoading(false)}
                onError={() => setPhotoUrl(DefaultUser)}
                style={styles.photo} 
                source={photoUrl}/>
        </React.Fragment>
    </Lightbox>
)

} `

Dellybro avatar Sep 25 '19 21:09 Dellybro