Code Monkey home page Code Monkey logo

react-native-fast-image's Introduction

๐Ÿšฉ FastImage

Performant React Native image component.

Version Downloads Build Status Code Coverage

Watch on GitHub Star on GitHub Tweet


FastImage example app.

React Native's Image component handles image caching like browsers for the most part. If the server is returning proper cache control headers for images you'll generally get the sort of built in caching behavior you'd have in a browser. Even so many people have noticed:

  • Flickering.
  • Cache misses.
  • Low performance loading from cache.
  • Low performance in general.

FastImage is an Image replacement that solves these issues. FastImage is a wrapper around SDWebImage (iOS) and Glide (Android).

Features

  • Aggressively cache images.
  • Add authorization headers.
  • Prioritize images.
  • Preload images.
  • GIF support.
  • Border radius.

Usage

Note: You must be using React Native 0.60.0 or higher to use the most recent version of react-native-fast-image.

yarn add react-native-fast-image
cd ios && pod install
import FastImage from 'react-native-fast-image'

const YourImage = () => (
    <FastImage
        style={{ width: 200, height: 200 }}
        source={{
            uri: 'https://unsplash.it/400/400?image=1',
            headers: { Authorization: 'someAuthToken' },
            priority: FastImage.priority.normal,
        }}
        resizeMode={FastImage.resizeMode.contain}
    />
)

Are you using Glide already using an AppGlideModule?

Are you using Proguard?

If you use Proguard you will need to add these lines to android/app/proguard-rules.pro:

-keep public class com.dylanvann.fastimage.* {*;}
-keep public class com.dylanvann.fastimage.** {*;}
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.module.AppGlideModule
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
  **[] $VALUES;
  public *;
}

Properties

source?: object

Source for the remote image to load.


source.uri?: string

Remote url to load the image from. e.g. 'https://facebook.github.io/react/img/logo_og.png'.


source.headers?: object

Headers to load the image with. e.g. { Authorization: 'someAuthToken' }.


source.priority?: enum

  • FastImage.priority.low - Low Priority.
  • FastImage.priority.normal (Default) - Normal Priority.
  • FastImage.priority.high - High Priority.

source.cache?: enum

  • FastImage.cacheControl.immutable - (Default) - Only updates if url changes.
  • FastImage.cacheControl.web - Use headers and follow normal caching procedures.
  • FastImage.cacheControl.cacheOnly - Only show images from cache, do not make any network requests.

defaultSource?: number

  • An asset loaded with require(...).
  • Note that like the built-in Image implementation, on Android defaultSource does not work in debug mode. This is due to the fact that assets are sent from the dev server, but RN's functions only know how to load it from res.

resizeMode?: enum

  • FastImage.resizeMode.contain - Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or less than the corresponding dimension of the view (minus padding).
  • FastImage.resizeMode.cover (Default) - Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view (minus padding).
  • FastImage.resizeMode.stretch - Scale width and height independently, This may change the aspect ratio of the src.
  • FastImage.resizeMode.center - Do not scale the image, keep centered.

onLoadStart?: () => void

Called when the image starts to load.


onProgress?: (event) => void

Called when the image is loading.

e.g. onProgress={e => console.log(e.nativeEvent.loaded / e.nativeEvent.total)}


onLoad?: (event) => void

Called on a successful image fetch. Called with the width and height of the loaded image.

e.g. onLoad={e => console.log(e.nativeEvent.width, e.nativeEvent.height)}


onError?: () => void

Called on an image fetching error.


onLoadEnd?: () => void

Called when the image finishes loading, whether it was successful or an error.


style

A React Native style. Supports using borderRadius.


fallback: boolean

If true will fallback to using Image. In this case the image will still be styled and laid out the same way as FastImage.


tintColor?: number | string

If supplied, changes the color of all the non-transparent pixels to the given color.

Static Methods

FastImage.preload: (source[]) => void

Preload images to display later. e.g.

FastImage.preload([
    {
        uri: 'https://facebook.github.io/react/img/logo_og.png',
        headers: { Authorization: 'someAuthToken' },
    },
    {
        uri: 'https://facebook.github.io/react/img/logo_og.png',
        headers: { Authorization: 'someAuthToken' },
    },
])

FastImage.clearMemoryCache: () => Promise<void>

Clear all images from memory cache.

FastImage.clearDiskCache: () => Promise<void>

Clear all images from disk cache.

Troubleshooting

If you have any problems using this library try the steps in troubleshooting and see if they fix it.

Development

Follow these instructions to get the example app running.

Supported React Native Versions

This project only aims to support the latest version of React Native.
This simplifies the development and the testing of the project.

If you require new features or bug fixes for older versions you can fork this project.

Credits

The idea for this modules came from vovkasm's react-native-web-image package. It also uses Glide and SDWebImage, but didn't have some features I needed (priority, headers).

Thanks to @mobinni for helping with the conceptualization

Licenses

  • FastImage - MIT ยฉ DylanVann
  • SDWebImage - MIT
  • Glide - BSD, part MIT and Apache 2.0. See the LICENSE file for details.

react-native-fast-image's People

Contributors

ahce avatar almouro avatar amauryliet avatar angeltrinidad avatar benwildeman avatar brunolemos avatar chitezh avatar connoremma avatar danhodos avatar dreampiggy avatar dylanvann avatar equimper avatar exphat avatar fedeorlandau avatar felipepaiva1992 avatar fjcaetano avatar friederbluemle avatar fschindler avatar iroachie avatar jeremyclee avatar jpdriver avatar meandmybadself avatar naturalclar avatar patrickkempff avatar ratson avatar semantic-release-bot avatar taschik avatar tianling536 avatar vieiralucas avatar yeomann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-fast-image's Issues

Consider switching to a different iOS image loading library.

Although it's very performant and used in tons of applications the API for SDWebImage is sort of weird.

e.g. The API for prefetching:

Assign list of URLs to let SDWebImagePrefetcher to queue the prefetching, currently one image is downloaded at a time, and skips images for failed downloads and proceed to the next image in the list. Any previously-running prefetch operations are canceled.

completionBlock
block to be called when prefetching is completed first param is the number of completed (successful or not) requests, second parameter is the number of skipped requests

Weird things:

  • One at a time.
  • Cancels any previous prefetch operation.
  • Tells you the number of successful and unsuccessful requests, not which images were successful or unsuccessful.

e.g. The API for headers:

headersFilter
Set filter to pick headers for downloading image HTTP request.
This block will be invoked for each downloading image request, returned NSDictionary will be used as headers in corresponding HTTP request.

Weird things:

  • Headers are not a property of each request (they should be).
  • Why is a singleton property being used to dynamically determine the headers for each request?
  • What if I had two requests to the same url that should have different headers?
    (The api of headersFilter does not allow that)

Maybe there's another native library we could use that's more straightforward than this.

Image not showing up on Android device?

When I run on my Android device the image is not showing up my code is pretty straight forward

<Image
                            onLoadEnd={() => {}}
                            style={{width: 300, height: 300}}
                            source={{
                                uri: photoUri,
                                priority: FastImage.priority.normal,
                            }}
                            indicator={ProgressCircle}
                            resizeMode={FastImage.resizeMode.contain}/>
                        }

And the uri is file:///storage/emulated/0/Pictures:IMG_20170827_171631.jpg

How preload works?

Hi,
first of all thank you for your work.

Just a question, how preload works?

I've a collection of images, I have to prefetch all of them before render the component but I don't have callbacks, and I don't have Idea why in examples, image have token key inside headers and in preload there is authentication key, why I have to use them? and finally why you never used preloaded images?

I hope you can help to clarify me, thank you.

Control cache time?

Is it possible to define / control how long images are cached by this library?
How long are images cached at all when using this library?

I'm asking this because I want to use this library for user-specific data that might get deleted. If so, the images (that are not related to any up-to-date content and so never shown again) should not stay forever, obviously.

Maybe this is a dumb question but hopefully someone will answer it anyway.

Thank you.

Image not rendering

After installing and linking, I'm seeing this when trying to display image(s):

image

React native version: 0.42.3

To start with just tried rendering a canned image, like this:

<FastImage
   style={styles.image}
   source={{ 
      uri: 'https://facebook.github.io/react/img/logo_og.png', 														
      priority: FastImage.priority.normal
   }} 
   resizeMode={FastImage.resizeMode.contain}
/>

Any ideas why we are not seeing the images render ?

Warning: Native component for "FastImageView" does not exist

Thank you for the great work! I cannot wait to see it work on my end (^ ^)/

Here is my basic information:
MacOS Sierra
Expo 20.0.0
React Native 0.47.2

I installed the package following the instruction:

  1. yarn add react-native-fast-image
  2. react-native link

But when I use it, the terminal gives me this warning Warning: Native component for "FastImageView" does not exist, and NO image was shown, only red boxes. But if I change to React Native's Image component, things work as expected.

screen shot 2017-08-26 at 01 21 58

I wonder if it is because I am using expo? But I tried eject expo, and link again, but the warning persists, and no image was showing up. :(

Add blurRadius support.

React Native now supports blurRadius prop for Image for both Android and iOS, but this library does not seem to. It would be super useful to have this ๐Ÿ‘

Getting a wired behavior bug with activity indicator

When I load my app and if go to my photo tabs which loads images from my redux store activity indicator is showing but does not go away attached gif showing the issue
fast-image-issue

I don't think it's getting the correct events

FastImage :Breaks in android

when i am using some thing like

<FastImage
            source={{
              uri: item.blurredImageUrl,
            }}
            resizeMode={FastImage.resizeMode.cover}
            style={Style.modalHeaderBgImage}
          >
            <View>
              <FastImage
                source={{
                  uri: iconUrl,
                  priority: FastImage.priority.high,
                }}
                style={Style.modalHeaderImage}
                resizeMode={FastImage.resizeMode.stretch}
              />
            </View>
            <View style={Style.modalHeaderRight}>
              
              <Text>
                ENDS IN 
              </Text>
            </View>
          </FastImage>

when i use this libary on Android, it show an error:
"android.widget.imageview cannot be cast to android.view.viewgroup".

Please resolve this issue . Works fine in IOS . Need it urgently

Add non-aggressive caching.

It would be great if we could get the possibility to turn on http caching control (SDWebImageRefreshCached in SDWebImage) to utilise functionality like etags

BorderRadius Android

On iOS it works as expected, but on Android, borderRadius does not get applied, the image stays squared.

Here is the code I use:

<FastImage 
   source={{uri: 'https://example.com'} 
   style={styles.picture} 
   borderRadius={75} 
   resizeMode="cover"
/>

and styles.picture has the following:

    width: 150,
    height: 150,
    borderRadius: 75,
    borderWidth: 0.5,
    borderColor: 'grey',
    backgroundColor: 'transparent',

So I tried to double set it through props and through style object.

No luck :/
Running:
RN v0.46.2
Android 5.0.1
RNFI v0.0.11

Android build failed.( ios ok) compileReleaseJavaWithJavac FAILED

hi, first installed package
on ios it builds success . but Android it fails:

`:react-native-fast-image:prepareComFacebookFrescoImagepipeline101Library
:react-native-fast-image:prepareComFacebookFrescoImagepipelineBase101Library
:react-native-fast-image:prepareComFacebookFrescoImagepipelineOkhttp3101Library
:react-native-fast-image:prepareComFacebookReactReactNative0451Library
:react-native-fast-image:prepareComFacebookSoloaderSoloader010Library
:react-native-fast-image:prepareOrgWebkitAndroidJscR174650Library
:react-native-fast-image:prepareReleaseDependencies
:react-native-fast-image:compileReleaseAidl
:react-native-fast-image:compileReleaseNdk UP-TO-DATE
:react-native-fast-image:compileLint
:react-native-fast-image:copyReleaseLint UP-TO-DATE
:react-native-fast-image:compileReleaseRenderscript
:react-native-fast-image:generateReleaseBuildConfig
:react-native-fast-image:generateReleaseResValues
:react-native-fast-image:generateReleaseResources
:react-native-fast-image:mergeReleaseResources
:react-native-fast-image:processReleaseManifest
/..../node_modules/react-native-fast-image/android/src/main/AndroidManifest.xml:11:9-15:15 Warning:
meta-data#com.bumptech.glide.integration.okhttp.OkHttpGlideModule was tagged at AndroidManifest.xml:11 to remove other declarations but no other declaration present
:react-native-fast-image:processReleaseResources
:react-native-fast-image:generateReleaseSources
:react-native-fast-image:incrementalReleaseJavaCompilationSafeguard
:react-native-fast-image:compileReleaseJavaWithJavac
:react-native-fast-image:compileReleaseJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
/..../node_modules/react-native-fast-image/android/src/main/java/com/dylanvann/fastimage/FastImageViewPackage.java:14: error: FastImageViewPackage is not abstract and does not override abstract method createJSModules() in ReactPackage
public class FastImageViewPackage implements ReactPackage {
^
Note: /..../node_modules/react-native-fast-image/android/src/main/java/com/dylanvann/fastimage/FastImageViewManager.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
:react-native-fast-image:compileReleaseJavaWithJavac FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':react-native-fast-image:compileReleaseJavaWithJavac'.

Compilation failed; see the compiler error output for details.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 8.256 secs`

FastImage with Blob

Hi!
I'm trying to use react-native-fast-image but it doesn't seems to work with Blob. I give it a blob URL as the uri and all i get is a white rectangle with red border. the onError isn't fired.
Could it be because a blob url is made to download the image and your module is ti load online image?

Image is not being rendered

I did the following:

yarn add react-native-fast-image
react-native link

Then I replaced one of my images from this:

                    <Image
                      style={styles.image}
                      source={{uri: imageUri}}
                    />

to this:

                    <FastImage
                      style={styles.image}
                      source={{
                        uri: imageUri,
                        priority: FastImage.priority.normal,
                      }}
                      resizeMode={FastImage.resizeMode.contain}
                      onLoad={() => console.tron.log('loaded')}
                      onError={() => console.tron.log('error')}
                    />

I see the empty space where the image should be displayed, but no image. Am I missing something?

Can't Load android local file in content format

I can't show a image by 'content://media/external/images/media/32854'.
So I view the code. Then found you use GlideUrl.
So I try to use urlString instead. It works.
So I add some logic to load local image and network image.
FastImageViewManager

private static RequestListener<String, GlideDrawable> LISTENER_STRING = new RequestListener<String, GlideDrawable>() {
        @Override
        public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
            OkHttpProgressGlideModule.forget(model);
            if (!(target instanceof ImageViewTarget)) {
                return false;
            }
            ImageViewWithUrl view = (ImageViewWithUrl) ((ImageViewTarget) target).getView();
            ThemedReactContext context = (ThemedReactContext) view.getContext();
            RCTEventEmitter eventEmitter = context.getJSModule(RCTEventEmitter.class);
            int viewId = view.getId();
            eventEmitter.receiveEvent(viewId, REACT_ON_ERROR_EVENT, new WritableNativeMap());
            eventEmitter.receiveEvent(viewId, REACT_ON_LOAD_END_EVENT, new WritableNativeMap());
            return false;
        }

        @Override
        public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
            if (!(target instanceof ImageViewTarget)) {
                return false;
            }
            ImageViewWithUrl view = (ImageViewWithUrl) ((ImageViewTarget) target).getView();
            ThemedReactContext context = (ThemedReactContext) view.getContext();
            RCTEventEmitter eventEmitter = context.getJSModule(RCTEventEmitter.class);
            int viewId = view.getId();
            eventEmitter.receiveEvent(viewId, REACT_ON_LOAD_EVENT, new WritableNativeMap());
            eventEmitter.receiveEvent(viewId, REACT_ON_LOAD_END_EVENT, new WritableNativeMap());
            return false;
        }
    };

.
.
.

        if (glideUrl.toStringUrl().startsWith("http://") || glideUrl.toStringUrl().startsWith("https://")) {
            Glide
                    .with(view.getContext())
                    .load(glideUrl)
                    .priority(priority)
                    .placeholder(TRANSPARENT_DRAWABLE)
                    .listener(LISTENER)
                    .into(view);
        } else {
            Glide
                    .with(view.getContext())
                    .load(glideUrl.toStringUrl())
                    .priority(priority)
                    .placeholder(TRANSPARENT_DRAWABLE)
                    .listener(LISTENER_STRING)
                    .into(view);
        }

FastImageViewModule

    @ReactMethod
    public void preload(final ReadableArray sources) {
        Activity activity = getCurrentActivity();
        final Context context = activity.getApplicationContext();
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < sources.size(); i++) {
                    final ReadableMap source = sources.getMap(i);
                    final GlideUrl glideUrl = FastImageViewConverter.glideUrl(source);
                    final Priority priority = FastImageViewConverter.priority(source);
                    if (glideUrl.toStringUrl().startsWith("http://") || glideUrl.toStringUrl().startsWith("https://")) {
                        Glide
                                .with(context)
                                .load(glideUrl)
                                .priority(priority)
                                .placeholder(TRANSPARENT_DRAWABLE)
                                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                                .preload();
                    } else {
                        Glide
                                .with(context)
                                .load(glideUrl.toStringUrl())
                                .priority(priority)
                                .placeholder(TRANSPARENT_DRAWABLE)
                                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                                .preload();
                    }
                }
            }
        });
    }

Thanks. Greate lib.

Strange behaviour using stretch resizemode.

I am super amazed by the speed of your library. There is no flickering, the images are loaded immediately. Super awesome!!!

The problem that I have is with the resize mode of stretch. When I set:
resizeMode={FastImage.resizeMode.stretch} it's working only the first time and every other refresh of the app, or preloding my list of items the images are looking like with:
resizeMode={FastImage.resizeMode.contain}
I have this problem only with the 'stretch' property.

Support local file uri

On ios, local file uri is /xxx/ooo/document/a.jpg.
And on Android, the uri is file://xxx/ooo/document/a.jpg.

Could I add something to support it ?

Placeholder image.

Hi, thanks for this very useful lib!
It would be great if we could set a placeholder image (to show it while the image is loading).

RN 0.47.1 Build Error

iOS:

    ^
In module 'FLAnimatedImage' imported from app/node_modules/react-native-fast-image/ios/Vendor/SDWebImage/SDWebImage/FLAnimatedImage/FLAnimatedImageView+WebCache.h:14:
app/ios/build/Build/Products/Debug-iphonesimulator/FLAnimatedImage.framework/Headers/FLAnimatedImage.h:64:5: note: previous definition is here
    FLLogLevelError,
    ^
In file included from app/node_modules/react-native-fast-image/ios/Vendor/SDWebImage/SDWebImage/FLAnimatedImage/FLAnimatedImageView+WebCache.m:16:
app/node_modules/react-native-fast-image/ios/Vendor/SDWebImage/Vendors/FLAnimatedImage/FLAnimatedImage/FLAnimatedImage.h:65:5: error: redefinition of enumerator 'FLLogLevelWarn'
    FLLogLevelWarn,
    ^
In module 'FLAnimatedImage' imported from app/node_modules/react-native-fast-image/ios/Vendor/SDWebImage/SDWebImage/FLAnimatedImage/FLAnimatedImageView+WebCache.h:14:
app/ios/build/Build/Products/Debug-iphonesimulator/FLAnimatedImage.framework/Headers/FLAnimatedImage.h:65:5: note: previous definition is here
    FLLogLevelWarn,
    ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.

Android:

15:27	EmptyThrowable: Invalid file: file:///app/node_modules/react-native-fast-image/android/src/main/AndroidManifest.xml

Why is that? updated to RNFI 1.0.0 :/

Cannot set per request headers. Headers are global.

The way SDWebImage works headers set on FastImage are global.

See here.

So the latest requested image will e.g. overwrite the token header for any other queued images.

This is really sloppy and will probably lead to bugs in some people's code down the line. This may tie into #13 .

Error in android

when i use this libary on Android, it show an error:
"android.widget.imageview cannot be cast to android.view.viewgroup".
but on ios is work fine.

react-native: 0.44.2
react: 16.0.0-alpha.6
react-native-fast-image: 0.0.10

anyone can help me? :(

'SDWebImage/UIImageView+WebCache.h' file not found

RN 0.46.4

node_modules/react-native-fast-image/ios/FastImage/FFFastImageView.h:3:9: fatal error: 'SDWebImage/UIImageView+WebCache.h' file not found
#import <SDWebImage/UIImageView+WebCache.h>
        ^
1 error generated.

GIF image with same uri do not rendered sometimes.

FastImage just saved my life, the performance is very good.
However, i found that GIF image do not rendered sometimes.

Please noted that the same image were used in both testing.

First Test:

  1. Render the same GIF image with RCTImage, FastImage in the same page.
  2. FastImage component renders placeholder which equals to the image
  3. FastImage component do not renders the GIF image. (Although there is no any warning during the loading, I am sure that it is not caused by the image file size because i was waiting for the loading for 5 minutes and RCTImage just successfully rendered the gif image within 5 seconds)

Second Test:

  1. Render the same GIF image with RCTImage, FastImage in the same page.
  2. FastImage component renders placeholder which equals to the image
  3. FastImage component renders the GIF image

1st: Nice Work 2nd: Question regarding dependencies

node: 8.2.1
react-native-cli: 2.0.1
react-native: 0.43.2

I added updated a fork or react-native-photo-browser to use your FastImage. For some reason, I get the following compilation error:

 FFFastImageView.h:5:9: fatal error: 'FLAnimatedImageView.h' file not found
#import "FLAnimatedImageView.h"
        ^
1 error generated.

Aside from yarn add react-native-fast-image and running react-native link, what else do I need to do? Looks like the paths are incorrect?

The engine "node" is incompatible with this module. Expected version "> 0.4.x < 0.9.0".

Hi i cant install, its my terminal:
yarn add react-native-fast-image
yarn add v0.27.5
[1/4] Resolving packages...
warning There appears to be trouble with your network connection. Retrying...
[2/4] Fetching packages...
error [email protected]: The engine "node" is incompatible with this module. Expected version "> 0.4.x < 0.9.0".
error Found incompatible module
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

resizeMode=FastImage.resizeMode.stretch does not work

There is my code, when I set resizeMode={FastImage.resizeMode.stretch},the images does not show as expected,bu other resizeMode works well, why I got this issue?
<FastImage style={{ width: Global.width, height: Global.width * 0.45, borderWidth: 1, }} source={{ uri: "xxx.jpg" }} resizeMode={FastImage.resizeMode.stretch} />
image

Add borderRadius support.

Hi,
I was just wondering if you plan supporting border radius style on images. At least on android it seems that this rule is ignored.

Error:(20, 5) error: method does not override or implement a method from a supertype

Getting the following issues when trying to build for Android works for iOS

/Users/Almog/Full-Time-Employment/Construction-Cloud/RnD/CCMobileApp/node_modules/react-native-fast-image/android/src/main/java/com/dylanvann/fastimage/FastImageViewPackage.java
Error:(20, 5) error: method does not override or implement a method from a supertype

Error:Execution failed for task ':react-native-fast-image:compileReleaseJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

Any ideas how to fix this?

Unable to compile: Duplicate interface definition for class 'FLAnimatedImageView'

Hi there!

I'm having problems compiling my app after adding react-native-fast-image.

After running react-native link react-native-fast-image, I receive a bunch of duplicate interface definition for class 'FLAnimatedImageView' and property has a previous declaration errors.

Here's a subset of the errors I receive:

In file included from /Users/manuelthomsen/Coding/experiments/expo/woodn/node_modules/react-native-fast-image/ios/Vendor/SDWebImage/SDWebImage/FLAnimatedImage/FLAnimatedImageView+WebCache.m:16:
In file included from /Users/manuelthomsen/Coding/experiments/expo/woodn/node_modules/react-native-fast-image/ios/Vendor/SDWebImage/Vendors/FLAnimatedImage/FLAnimatedImage/FLAnimatedImage.h:13:
/Users/manuelthomsen/Coding/experiments/expo/woodn/node_modules/react-native-fast-image/ios/Vendor/SDWebImage/Vendors/FLAnimatedImage/FLAnimatedImage/FLAnimatedImageView.h:22:1: error: duplicate interface definition for class 'FLAnimatedImageView'
@interface FLAnimatedImageView : UIImageView
^
In module 'FLAnimatedImage' imported from /Users/manuelthomsen/Coding/experiments/expo/test/node_modules/react-native-fast-image/ios/Vendor/SDWebImage/SDWebImage/FLAnimatedImage/FLAnimatedImageView+WebCache.h:14:
/Users/manuelthomsen/Library/Developer/Xcode/DerivedData/test-ftzdxdyafvkexabeahltbammdnfq/Build/Products/Debug-iphonesimulator/FLAnimatedImage.framework/Headers/FLAnimatedImageView.h:22:12: note: previous definition is here
@interface FLAnimatedImageView : UIImageView
           ^
In file included from /Users/manuelthomsen/Coding/experiments/expo/test/node_modules/react-native-fast-image/ios/Vendor/SDWebImage/SDWebImage/FLAnimatedImage/FLAnimatedImageView+WebCache.m:16:
In file included from /Users/manuelthomsen/Coding/experiments/expo/test/node_modules/react-native-fast-image/ios/Vendor/SDWebImage/Vendors/FLAnimatedImage/FLAnimatedImage/FLAnimatedImage.h:13:
/Users/manuelthomsen/Coding/experiments/expo/test/node_modules/react-native-fast-image/ios/Vendor/SDWebImage/Vendors/FLAnimatedImage/FLAnimatedImage/FLAnimatedImageView.h:26:48: error: property has a previous declaration
@property (nonatomic, strong) FLAnimatedImage *animatedImage;

Any ideas on how to solve this?
This is a basic expo app that has just been detached.

Tested on RN v. 46 and 47.

Thank you!

Add option to force reload of certain images.

Is there any way to force a specific uri to be removed from the cache (so that it would be necessarily fetch the next time an image source point to this uri)?
This is because I have a user avatar that always point to the same url for a specific user so I want to be able to clean the cache for this avatar picture each time the user actually change its avatar.

Add support for children.

Currently the component doesn't support children.

This is because FastImage supplies a android.widget.imageview and not a android.view.viewgroup.

For now absolute positioning is a workaround.

ios - Device loses connection when FlatList is passed more than 20 images

I'm building an app where I'm fetching images from a storage bucket in Firebase storage.

When I use FastImage in a FlatList for an array of images less than 20 it works fine. However if I try to render more images (I could have up to roughly 100 images in an array), the connection to my device is lost and I have to restart the project in xCode.

/**
 * @param {Array.<String>} images
 */
<FlatList
    data={props.images.slice(0, 30)}
    keyExtractor={item => item}
    columnWrapperStyle={{
        marginVertical: 2,
    }}
    removeClippedSubviews={false}
    numColumns={3}
    getItemLayout={( data, index ) => (
        {length: 100, offset: 100 * index, index}
    )}
    renderItem={({ item, index }) => (
        <Asset
            item={item}
            index={index}
            imageOnPress={props.imageOnPress}
            isImageSelected={props.isImageSelected ? props.isImageSelected(item) : null}
        />
    )}
/>
        
class Asset extends PureComponent {
     shouldComponentUpdate(nextProps) {
           return this.props.isImageSelected === nextProps.isImageSelected ? false : true;
       }

    render() {
        const priority = setPriorityLevel(this.props.index);

        return (
            <TouchableHighlight
                onPress={() => this.props.imageOnPress(this.props.item)}
                style={styles.imageThumbnail}
            >
                <View style={styles.imageWrapper}>
                    <FastImage
                           style={{
                                flex: 1,
                                marginRight: 2,
                                backgroundColor: colors.gray[1],
                           }}
                           source={{ uri, priority }}
                       />

                    {this.props.isImageSelected && (
                        <Icon
                            name="check"
                            color={colors.greenLime}
                            size={32}
                            style={styles.icon}
                        />
                    )}
                </View>
            </TouchableHighlight>
        )
    }
}

function setPriorityLevel(index) {
    switch(true) {
        case (index >= 0 && index <= 10):
            return FastImage.priority.high;
        case (index >= 11 && index <= 20):
            return FastImage.priority.normal;
        case (index > 20):
            return FastImage.priority.low;
        default:
            return FastImage.priority.low;
    }
};

"react-native": "0.44.0"
"react-native-fast-image": "^0.1.2"

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.