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

setOnFastImageError #1035

Open
NguyenHoangMinhkkkk opened this issue Mar 22, 2024 · 1 comment
Open

setOnFastImageError #1035

NguyenHoangMinhkkkk opened this issue Mar 22, 2024 · 1 comment
Labels

Comments

@NguyenHoangMinhkkkk
Copy link

NguyenHoangMinhkkkk commented Mar 22, 2024

My project using these version:
"react-native": "0.68.7"
"react-native-fast-image": "^8.6.3"

Code:

import DefaultImage from "@images/DefaultImage.png"
...
const [isErrorImage, setErrorImage] = React.useState(false);
...
<>
  {isErrorImage ? <Text>{"Image Error"}</Text> : null}
  <FastImage
    resizeMode="cover"
    style={{
      width: 200, height: 200,   borderRadius: 8, backgroundColor: "gray"
    }}
    onError={() => {
      InteractionManager.runAfterInteractions(() => {
        setErrorImage(true);
      });
    }}
    defaultSource={DefaultImage}
    source={{ uri: 'https://something...' }}
  />
</>

Everytime Image load failed, => Crash and get this error 👇
Screenshot 2024-03-22 at 14 49 40

After some searching on issues, this issue give me a idea.

And i tried this code 👇, the Crash gone away and project working fine.

- (void) setOnFastImageError: (RCTDirectEventBlock)onFastImageError {
    _onFastImageError = onFastImageError;

    if (self.hasErrored && _onFastImageError) {   // insead of if (self.hasErrored) {
        _onFastImageError(@{});
    }
}

And, finally, what should i do with this issue ? is the fix code above the right way to do (Should i use patch-package?) or i have to do something else ??

@deepanshushuklad11
Copy link

@NguyenHoangMinhkkkk you can try @d11/react-native-fast-image

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

No branches or pull requests

2 participants