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

Feature/preload callbacks #437

Closed
wants to merge 22 commits into from
Closed

Feature/preload callbacks #437

wants to merge 22 commits into from

Conversation

Mickagd
Copy link

@Mickagd Mickagd commented Mar 26, 2019

We also need this PR to be merged

doomsower and others added 3 commits August 29, 2018 09:02
# Conflicts:
#	android/src/main/java/com/dylanvann/fastimage/FastImagePreloaderModule.java
#	src/index.d.ts
#	src/index.js
Copy link
Contributor

@guhungry guhungry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename FastImagePreloaderModule back to FastImageViewModule and extract method into new class instead from preload()

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.views.imagehelper.ImageSource;

class FastImageViewModule extends ReactContextBaseJavaModule {
class FastImagePreloaderModule extends ReactContextBaseJavaModule {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why rename class just like that. I have #425 which edit FastImageViewModule.java

@codecov
Copy link

codecov bot commented Mar 28, 2019

Codecov Report

Merging #437 (c86abda) into main (a7a8643) will decrease coverage by 45.01%.
The diff coverage is 17.39%.

❗ Current head c86abda differs from pull request most recent head 0ee6e1f. Consider uploading reports for the commit 0ee6e1f to get more accurate results
Impacted file tree graph

@@             Coverage Diff             @@
##             main     #437       +/-   ##
===========================================
- Coverage   96.29%   51.28%   -45.02%     
===========================================
  Files           1        2        +1     
  Lines          27       39       +12     
  Branches        2        0        -2     
===========================================
- Hits           26       20        -6     
- Misses          1       19       +18     
Impacted Files Coverage Δ
src/preloaderManager.js 15.78% <15.78%> (ø)
src/index.js 85.00% <25.00%> (ø)
src/index.tsx

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4d8c749...0ee6e1f. Read the comment docs.

@RWOverdijk
Copy link

Hey all! Is this going somewhere?

@augustbjornberg
Copy link

Is this PR still being worked on? Would be such a nice feature to have.

@Ilphrin
Copy link

Ilphrin commented May 28, 2019

There are some conflicts, I think you should resolve them @Mickagd before @DylanVann can take a look at this PR ^^

@SamiChab
Copy link

Please consider implementing this! It would be so useful!

@RWOverdijk
Copy link

Really happy to see this still moving forward! I can't wait to remove my component hack 😄

@LuisRodriguezLD
Copy link

Hello. Any update on this?

@RWOverdijk
Copy link

@LuisRodriguezLD As far as I can see there are conflicts.

@RWOverdijk
Copy link

I've reimplemented this. Confirmed to work on iOS. Android I'll check later. I'll make a PR when I'm done.

On a sidenote, my solution uses a lot less code so I'm hoping that makes it easier to get it merged.

@Elindorath
Copy link

Hi @RWOverdijk. Thanks for your work! Could you publish your reimplementation on your fork that we can help to test it and speed up this to get it merged?

We really need this to be compatible with RN v0.60+.

@RWOverdijk
Copy link

RWOverdijk commented Oct 15, 2019

@Elindorath Sure thing. I have to finish android first though. The module is compatible with 0.60+ for me, so I'm not sure what you mean

Sync with the original repo
@joan-saum
Copy link

Hi @RWOverdijk , how is it going with Android ? :) Need any help ?

@sebqq
Copy link

sebqq commented Nov 5, 2019

Promise should also return which pictures from array couldn't be fetched, not only how many couldn't be fetched.

@RWOverdijk
Copy link

@joan-saum It's going all right. The biggest problem right now is time and priorities. I can push the iOS stuff at some point this or next week though, maybe someone else can then PR the android stuff to my branch and we can get this thing going!

Sorry for my lack of time... It bothers me as well.

@sebqq
Copy link

sebqq commented Nov 11, 2019

Please, consider to also add id to every image, so we can check from react-native side which images failed to load.

@RWOverdijk
Copy link

@sebinq I will not be doing that but you could add that after if you want.

@sebqq
Copy link

sebqq commented Nov 11, 2019

@RWOverdijk thanks for info,, I will try.

@RWOverdijk
Copy link

The problem is that my project isn't selling well enough to prioritize this feature (My sales strategy was well calculated but man, am I bad at math.).

@Mickagd
Copy link
Author

Mickagd commented Aug 20, 2021

We have updated our PR with your last changes.
There is a lot of people that need these changes.
Could you please merge this request @DylanVann ?
Thanks a lot !

@nguyenphucbao68
Copy link

Please merge this PR. I really need it 👍

@Flictuum
Copy link

Hi guys just a last call if it's possible to merge this PR, we invested time here to bring last changes to the PR and I think this will help a lot of people.
So I hope my words will find you @DylanVann
Thanks a lot for your work and maybe we could help to maintain this package for other needs !

@@ -14,7 +13,7 @@ import {
ViewProps,
} from 'react-native'

const FastImageViewNativeModule = NativeModules.FastImageView

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should remain because it is needed to use "clearMemoryCache" and "clearDiskCache". It also generate a typescript error.

@putuoka
Copy link

putuoka commented May 20, 2022

how to implement this into my project? because i don't have src folder in my node_modules fast image

@nicomontanari
Copy link

Hi @putuoka, did you download the stable version of the package or did you download it from this pull request?

If you have downloaded the stable version in your node_modules folder you should see the compiled package in the dist folder, if not you should see the entire project as the below image:

Schermata 2022-05-20 alle 10 41 25

@putuoka
Copy link

putuoka commented May 20, 2022

Hi @putuoka, did you download the stable version of the package or did you download it from this pull request?

If you have downloaded the stable version in your node_modules folder you should see the compiled package in the dist folder, if not you should see the entire project as the below image:

Schermata 2022-05-20 alle 10 41 25

Hi @nicomontanari , thanks for the reply. i have downloaded stable version using yarn add react-native-fast-image
what i mean is, in this pull request there is 12 files change one of them is PreloaderManager.tsx which i can't find in my node_modules react-native-fast-image

image

sorry because i'm new with rn i might missing something here. sorry for my english. please enlighten me because i need to use preload promise/callback to know when it done downloading resources and then i can use it as cache with fast images & redux persist

@nicomontanari
Copy link

@putuoka you need to install this package with yarn add DylanVann/react-native-fast-image#pull/437/head or npm install DylanVann/react-native-fast-image#pull/437/head if you use npm

@putuoka
Copy link

putuoka commented May 23, 2022

@putuoka you need to install this package with yarn add DylanVann/react-native-fast-image#pull/437/head or npm install DylanVann/react-native-fast-image#pull/437/head if you use npm

Hi @nicomontanari i got this error:


error: Error: While trying to resolve module `react-native-fast-image` from file `D:\gcp-app\src\MainApp.js`, the package 
`D:\gcp-app\node_modules\react-native-fast-image\package.json` was successfully found. However, this package itself 
specifies a `main` module field that could not be resolved (`D:\gcp-app\node_modules\react-native-fast-image\dist\index.cjs.js`. 
Indeed, none of these files exist:

edit: run yarn upgrade --latest into node_modules fast image after that run yarn build i solve that error by doing this but still can't use new preload.

solved!! it's working!! here what i do:

  1. clone original repo not from this pull request
  2. run yarn install no need upgrade to latest. after that changes necessary files according to this pull request.
  3. run yarn build copy "dist" folder to your destination node_modules which has original install of this package

note: it can't preload 151 images. sometimes just 32, sometimes 113
image

@putuoka
Copy link

putuoka commented May 25, 2022

Btw This pull make FastImage.clearDiskCache() broken

TypeError: Cannot read property 'clearDiskCache' of null

code:

FastImage.clearDiskCache().then(() => {
      //preloadComplete(isComplete);
      console.log('clear');
    });

@patissier-boulanger
Copy link

really need this!

@knro
Copy link

knro commented Oct 23, 2022

Any plans yet to merge this? Any forks that have this merged with upstream?

@AlessandroAries
Copy link

Any plans yet to merge this? Any forks that have this merged with upstream?

I added the changes to my fork with the updated stream: #986

@skizzo
Copy link

skizzo commented Jun 20, 2023

This would be so nice to have!

@ymc-thzi
Copy link

ymc-thzi commented Jul 7, 2023

Had the same need, couldn't patch the PR due to conflicts. I am using another patch to get the cache folder path
With that I wrote a tiny function to get the state and even a progress of the cached images. Maybe this helps someone as a workaround...

  async function checkCacheFolder(cacheFolderPath, expectedImageCount) {
    try {
      const files = await RNFS.readDir(cacheFolderPath);
      const imageCount = files.filter(
        file => file.isFile() && file.name.endsWith('.jpg'),
      ).length;

      if (imageCount === expectedImageCount) {
        console.log('Images cache complete');
        return;
      }

      let progress = (imageCount / expectedImageCount) * 100;
      console.log(progress.toFixed(0));

      setTimeout(() => {
       checkCacheFolder(
          cacheFolderPath,
          expectedImageCount,
        );
      }, 1000);
    } catch (error) {
      //Sentry will log that
    }
  },

@Sparted Sparted closed this by deleting the head repository Jul 17, 2023
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.