question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onLoad, onError, onLoadStart and onLoadEnd do not fire for Image.

See original GitHub issue

Environment

Environment:
  OS: macOS High Sierra 10.13.3
  Node: 8.9.4
  Yarn: 1.5.1
  npm: 5.5.1
  Watchman: 4.9.0
  Xcode: Xcode 9.2 Build version 9C40b
  Android Studio: 3.0 AI-171.4443003

Packages: (wanted => installed)
  react: 16.2.0 => 16.2.0
  react-native: 0.54.0 => 0.54.0

Steps to Reproduce

<Image
  sourse={{uri: this.props.uri}}
  onLoad={this.onLoad}
  onError={this.onError}
/>

Expected Behavior

Should work as described in documentation documentation

Actual Behavior

onLoad, onError, onLoadStart and onLoadEnd do not fire for Image, on both IOS and Android platforms

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:12

github_iconTop GitHub Comments

4reactions
iMericacommented, Jun 6, 2018

Issue persists using latest and greatest as of today

1reaction
luisbragancacommented, Aug 28, 2018

It does work, it just depends on the implementation.

For example, this code below works, it fires the console.log (this code is not useful or anything, I just created it so I could test if the events were properly being fired):

constructor(props) {
    super(props);
    this.state = { loaded: false };
}

_finishLoading = function () {
    console.log("Finished loading");
    this.setState({ loaded: true });
}

render = function () {
    return <Image onLoadEnd={this._finishLoading.bind(this)} {...this.props} />;
}

However, this code below does not work at all (it’s a non-working LazyImage implementation):

constructor(props) {
    super(props);
    this.state = { loaded: false };
}

_finishLoading = function () {
    console.log("Finished loading");
    this.setState({ loaded: true });
}

render = function () {
    var image = <Image onLoadEnd={this._finishLoading.bind(this)} {...this.props} />;
    return this.state.loaded ? image : <Image {...this.props} source={Loader} />;
}

I’m assuming it’s not firing the event because the Image has not been mounted so it will never initiate the loading. Is there any way to force its mount or to fake mount an element? I just want it to start loading so it can change the this.state.loading to true

Read more comments on GitHub >

github_iconTop Results From Across the Web

onLoadEnd is not fired in react-native Image - Stack Overflow
returns the Image component, onLoadStart is triggered and this.state.loading is set to true . When the second render happens, this.state.loading ...
Read more >
Resource loading: onload and onerror
So when we add <img> to the page, the user does not see the picture immediately. The browser needs to load it first....
Read more >
Chapter 2. Making CORS requests - CORS in Action
Fires if the client aborts the request by calling the abort method. If onabort fires, the onload and onerror event handlers will not...
Read more >
ASP.NET Core Blazor event handling - Microsoft Learn
Learn about Blazor's event handling features, including event argument types, event callbacks, and managing default browser events.
Read more >
Cross-Site Scripting (XSS) Cheat Sheet | Web Security Academy
Event handlers that do not require user interaction ... <audio src/onerror=alert(1)> ... <image src=validimage.png onloadstart=alert(1)>.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found