Framer icon indicating copy to clipboard operation
Framer copied to clipboard

Events.ImageLoaded and Events.ImageLoadError don't fire for Layer

Open kitajchuk opened this issue 10 years ago • 1 comments

The snippet here fails to receive the "load" event and fire the handler:

# Create the card layer for the feed
postLayer = new Layer
    superLayer: @feedLayer
    x: 0
    y: offset
    width: screenWidth
    height: height
    backgroundColor: "black"

# Bind for image loaded event: This DOES NOT fire
postLayer.on(Events.ImageLoaded, @onImageLoaded)

# Apply card image if available
if post.get("mainImage")
    postLayer.image = post.get("mainImage").url()

In debugging, it doesn't work because it fails to pass a test for _ref and/or _ref1 which are checking against the contexts events object, this.events, to see if it has a "load" and/or "error" property. There seems to be no need for this check. The following shims the "load" reference on the layer's events object and results in the onImageLoaded handler firing successfully:

# Create the card layer for the feed
postLayer = new Layer
    superLayer: @feedLayer
    x: 0
    y: offset
    width: screenWidth
    height: height
    backgroundColor: "black"

# Bind for image loaded event: This DOES fire now
postLayer.on(Events.ImageLoaded, @onImageLoaded)

# Shim the events object because its not working...
postLayer.events =
    load: true

# Apply card image if available
if post.get("mainImage")
    postLayer.image = post.get("mainImage").url()

kitajchuk avatar Mar 24 '15 01:03 kitajchuk

This appears to be broken again - Copied directly from reference:


layerA = new Layer
    image: "images/logo.png"

layerA.on Events.ImageLoaded, ->
    print "The image loaded"

layerA.on Events.ImageLoadError, ->
    print "The image couldn't be loaded"

Neither appears to fire the handler.

g-a-v-i-n avatar Sep 20 '16 20:09 g-a-v-i-n