React-native-fast-image: Crash on Android if source is an invalid URL

Created on 17 Feb 2019  ·  14Comments  ·  Source: DylanVann/react-native-fast-image

If I pass as source an object like this { uri: 'INVALID_URL' } I get the following error on Android:

Error while updating property 'source' of a view managed by: FastImageView

null

Must not be null or empty

At the moment I am normalising the source using this (ugly) code to avoid the crash:

const normalisedSource = source && typeof source.uri === 'string' && !source.uri.split('https://')[1] ? null : source;

but I think it would be better if the library prevents it.

Most helpful comment

not all image start https, http ??
const normalisedSource = source && typeof source.uri === 'string' && !source.uri.split('http')[1] ? null : source;

All 14 comments

not all image start https, http ??
const normalisedSource = source && typeof source.uri === 'string' && !source.uri.split('http')[1] ? null : source;

image

this is log.

2019-03-28 19:29:08.185 14848-14848/E/fastimage: http://img.abc.com/o_1d6v24em310p7pib14b94gsjbha.jpg
2019-03-28 19:29:08.185 14848-14848/ E/fastimage: false
2019-03-28 19:29:08.195 14848-14848/ E/fastimage: true
2019-03-28 19:29:08.196 14848-14848/E/unknown:ViewManager: Error while updating prop source
    java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Method.invoke(Native Method)


 Caused by: java.lang.ClassCastException: Value for uri cannot be cast from ReadableNativeMap to String

@OrangeFlavoredColdCoffee Your answer works perfectly. Thank you very much! you saved me so much time ^^

so I need adjust every source ? It's so Unfriendly!!!

const normalisedSource = source && typeof source.uri === 'string' && !source.uri.split('http')[1] ? null : source;

You saved my day!

not all image start https, http ??
const normalisedSource = source && typeof source.uri === 'string' && !source.uri.split('http')[1] ? null : source;

not all images start with https or http. what about local images

how i could use this function or variable ?

not all image start https, http ??
const normalisedSource = source && typeof source.uri === 'string' && !source.uri.split('http')[1] ? null : source;

not all images start with https or http. what about local images

i don't know where

You don’t have to use it necessarily, but it prevents malformed url to
crash on Android devices. If you want to use it, just wrap your fast image
with your own custom component wrapper and apply the function to fast image
data source prop

On Sat, 11 Apr 2020 at 16:15, alexdieudonne notifications@github.com
wrote:

not all image start https, http ??
const normalisedSource = source && typeof source.uri === 'string' &&
!source.uri.split('http')[1] ? null : source;

not all images start with https or http. what about local images

i don't know where


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/DylanVann/react-native-fast-image/issues/407#issuecomment-612443733,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ABMMH5NHLBTK4X37HBYPB73RMCCSVANCNFSM4GX5PRSQ
.

render() {
return (

)
}

function getUriImage(uri) {
return uri !== null && uri !== undefined && uri.includes("/") && uri.includes(".") ? uri : ""
}

not all image start https, http ??

where do i have do make this change?

render() {
return (

)
}

function getUriImage(uri) {
return uri !== null && uri !== undefined && uri.includes("/") && uri.includes(".") ? uri : ""
}

Thanks you, my problem is solved using this

Handler local image

class ProgressiveImage extends React.Component {

getUriImage(uri) {
    return uri !== null && uri !== undefined && uri.includes("/") && uri.includes(".") ? uri : ""
}

render() {
    let source = this.props.source;
    return (
        <View style={styles.container}>
            {this.props.source && this.props.source.uri ? <FastImage {...this.props} source={{
                uri: this.getUriImage(this.props.source.uri),
                cache: FastImage.cacheControl.immutable,
            }} /> : <Image {...this.props} />}
        </View>
    )
}

}

I think the library itself should take of this issue, on ios it works perfectly.

Was this page helpful?
0 / 5 - 0 ratings