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

fix: on error empty null source [#1028] #10

Merged
merged 6 commits into from
Jun 11, 2024

Conversation

mistryswapnil-dream11
Copy link

@mistryswapnil-dream11 mistryswapnil-dream11 commented Jun 10, 2024

The PR fixes the following DylanVann#1028.

Previously it was observed that onError was not getting invoked when an empty or null source uri was passed to FastImage as a prop.
The PR fixes point mentioned above.

Scenarios Tested:

  1. When source uri is valid and not reachable, onError should be invoked:
    import React from 'react'
    import {View} from 'react-native'
    import FastImage from 'react-native-fast-image'

    export const ImageLoadErrorExample = () => {

    const onImageLoadError = () => {
        console.log("Error called when url is not reachable.")
    }

    return <View>
        <FastImage source={{
            uri: 'https://fastly.picsum.photos/id/31'
        }}
        onError={onImageLoadError}
        />
    </View>
}
  1. When source uri is empty (""), onError should be invoked:
    import React from 'react'
    import {View} from 'react-native'
    import FastImage from 'react-native-fast-image'

    export const ImageLoadErrorExample = () => {

    const onImageLoadError = () => {
        console.log("Error called when url is empty.")
    }

    return <View>
        <FastImage source={{
            uri: ''
        }}
        onError={onImageLoadError}
        />
    </View>
}
  1. When source uri is null, onError should be invoked:
import React from 'react'
   import {View} from 'react-native'
   import FastImage from 'react-native-fast-image'

   export const ImageLoadErrorExample = () => {

   const onImageLoadError = () => {
       console.log("Error called when url is null.")
   }

   return <View>
       <FastImage source={{
           uri: null
       }}
       onError={onImageLoadError}
       />
   </View>
}
  1. When source uri is a fallback source, is valid URL, but not reachable:
import React from 'react'
import {View} from 'react-native'
import FastImage from 'react-native-fast-image'

export const ImageLoadErrorExample = () => {

const onImageLoadError = () => {
    console.log("Error called when fallback url is not reachable.")
}

return <View>
    <FastImage source={{
        uri: 'https://fastly.picsum.photos/id/31'
    }}
    onError={onImageLoadError}
    fallback={true}
    />
</View>
}

@mistryswapnil-dream11 mistryswapnil-dream11 merged commit bec3d61 into main Jun 11, 2024
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

Successfully merging this pull request may close these issues.

2 participants