Code Monkey home page Code Monkey logo

Comments (6)

xerdnu avatar xerdnu commented on June 2, 2024 1

Hi @sepperousseau ,

First of all, thank you for your detailed ideas and glad to hear your thoughts.

I will start look into this after the weekend.

The reason i removed the width% feature is because i believe the onLayout event will have a tiny impact on performance and that i did not have the need for it cause i only use pre-calculated width/height. But i will add that for you.

Handling loaded images:

  1. (Fast) You can use async promise for knowing when the image was loaded or error occured.
  2. (Not as fast) the Event that can be found in the documentation.

I will also look into adding a method that checks if the image is in cache. I am preloading all images to disk when my app is loading so i did not have the need for that function but it will be added 😄

Thanks again for your ideas and best regards! 🚀

from react-native-blasted-image.

dFelinger avatar dFelinger commented on June 2, 2024 1

It would be great if you add onLoad prop like in standard react native Image component.

from react-native-blasted-image.

sepperousseau avatar sepperousseau commented on June 2, 2024

Hi @xerdnu

I currently updated all my images with fixed sizing :D might be better for performance. So the sizing is not that important anymore.

For the async promise you mean calling the loadImage myself?

Also I noticed the package name for android is still default package="com.reactlibrary"
Maybe you can rename it :)

from react-native-blasted-image.

xerdnu avatar xerdnu commented on June 2, 2024

@sepperousseau

That sounds good!

When using onLayout there will be a tiny delay due to the state update in combination with the onLayout event so i found that passing the fixed size down to the image module works best in terms of performance to avoid flickering and unnecessary delay. Maybe someone else has some better idea on how to handle this without using onLayout and states.

Also Glide is not built with the functionality to check if a image is cached or not out of the box. Implementing this check will make it cache the image and manually remove it and this will just be draining resources in my opinion. I would recommend preloading the image at some point. Please note that if the image is already found in cache Glide will not download it again so there is no downside there.

Also regarding your question about the loaded image callback i will post some code below.

Using preload

const processItem = async (image) => {
    try {
        await BlastedImage.preload({
	    uri: image,
	    skipMemoryCache: true // if you want to only store it to disk and not allocate memory
        });
        console.log("Image done loading here");
    } catch (error) {
        console.error("Error preloading image:", error);
    }
};

processItem("https://example.image.url.png");

Without preload you can listen to the event

import { NativeEventEmitter, NativeModules } from 'react-native';

const BlastedImageEvents = new NativeEventEmitter(NativeModules.BlastedImage);

useEffect(() => {
  const subscription = BlastedImageEvents.addListener('BlastedEventLoaded', (data) => {
    console.log(data.message); // Image was loaded from network/disk/memory and also shown
  });

  return () => {
    subscription.remove();
  };
}, []);

I will push a new package name in the next patch. Thanks for the feedback and let me know if the code above works for you or if you want something else 😃 🚀

from react-native-blasted-image.

xerdnu avatar xerdnu commented on June 2, 2024

@dFelinger

Added in 0.0.12 with #3.

Credits go to @sepperousseau

from react-native-blasted-image.

Karrthik-Arya avatar Karrthik-Arya commented on June 2, 2024

Will support for width% feature be added anytime soon?

from react-native-blasted-image.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.