Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-native-fast-image

DylanVann969.6k(MIT AND Apache-2.0)8.6.3TypeScript support: included

🚩 FastImage, performant React Native image component.

cache, cached, fastimage, image, priority

readme

🚩 FastImage

Performant React Native image component.

Version Downloads Build Status Code Coverage

Watch on GitHub Star on GitHub Tweet

<kbd> </kbd> <kbd> </kbd>
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

  • <input checked="" disabled="" type="checkbox"> Aggressively cache images.
  • <input checked="" disabled="" type="checkbox"> Add authorization headers.
  • <input checked="" disabled="" type="checkbox"> Prioritize images.
  • <input checked="" disabled="" type="checkbox"> Preload images.
  • <input checked="" disabled="" type="checkbox"> GIF support.
  • <input checked="" disabled="" type="checkbox"> 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.

changelog

8.6.3 (2022-10-31)

Bug Fixes

8.6.2 (2022-10-31)

Bug Fixes

  • Add tintColor to Flow FastImageProps type (#871) (37abecd)

8.6.1 (2022-09-05)

Bug Fixes

8.6.0 (2022-08-29)

Features

  • support defaultSource on iOS and Android (#921) (ec7c453)

8.5.12 (2022-08-28)

chore

  • Update React peerDependency to "^17 || ^18" (6255fc4)

BREAKING CHANGES

  • This package will no longer support React 16.

8.5.11 (2021-09-27)

Bug Fixes

  • null exception in FastImageViewManager.java (#423) (a7a8643)

8.5.10 (2021-09-27)

8.5.9 (2021-09-27)

Bug Fixes

8.5.8 (2021-09-17)

8.5.7 (2021-09-17)

8.5.6 (2021-09-16)

Bug Fixes

  • make corresponding flow file for .cjs file (77326e8), closes #784

8.5.5 (2021-09-15)

Bug Fixes

8.5.4 (2021-09-15)

Bug Fixes

8.5.3 (2021-09-15)

Bug Fixes

8.5.2 (2021-09-15)

Bug Fixes

  • android: replace jcenter with mavenCentral (69c9422)

8.5.1 (2021-09-15)

Bug Fixes

  • improve/update build.gradle (1f04c55)

8.5.0 (2021-09-15)

Features

  • ios: cancel image load when unmounted (#787) (f1588be)

8.4.1 (2021-09-15)

8.4.0 (2021-09-15)

Bug Fixes

Features

  • add clear image cache from memory and disk (#425) (818ed0c)

8.3.7 (2021-07-24)

8.3.6 (2021-07-08)

8.3.5 (2021-07-06)

Bug Fixes

8.3.4 (2020-11-17)

8.3.3 (2020-11-01)

Bug Fixes

8.3.2 (2020-07-17)

Bug Fixes

  • android: remove explicit use of UI thread (#698) (5d2894e)

8.3.1 (2020-07-17)

Bug Fixes

  • android: make center ResizeMode work correctly (d648ef8)

8.3.0 (2020-07-17)

Features

  • ios: allow for for per-image-request-headers (#691) (4a7cd64)

8.2.2 (2020-07-17)

Bug Fixes

8.2.1 (2020-07-17)

Bug Fixes

  • remove cache property if using fallback (ba0f238)

8.2.0 (2020-07-17)

Features

  • export ResizeMode and Priority types (#678) (e33664f)

8.1.10 (2020-07-17)

Bug Fixes

  • update SDWebImage and SDWebImageWebPCoder (#689) (9646456)

8.1.9 (2020-07-17)

Bug Fixes

8.1.8 (2020-07-17)

Bug Fixes

8.1.7 (2020-07-17)

8.1.6 (2020-07-17)

Changed

  • Use dv-scripts to simplify tooling (build, lint, test, release).

8.1.5 (2020-03-14)

Bug Fixes

8.1.4 (2020-03-12)

Bug Fixes

8.1.3 (2020-03-12)

Bug Fixes

  • Replace 'Component' with 'ComponentType' (#647) (6abb273)

8.1.2 (2020-03-09)

Bug Fixes

8.1.1 (2020-03-09)

Bug Fixes

  • Add git tag to CocoaPods source property (#601) (2d706ad)

8.1.0 (2020-03-09)

Features

8.0.0 (2019-10-20)

Features

BREAKING CHANGES

  • This changes how network requests are handled on iOS. Make sure they still work for you.

7.0.2 (2019-07-05)

Bug Fixes

  • Fix peer dependency and remove prop-types. (44a4c8b)

7.0.1 (2019-07-05)

Bug Fixes

  • Fix IllegalArgumentException crash (Android). (#511) (b6c4677)

7.0.0 (2019-07-05)

Features

  • Upgrade to React Native 0.60.0 / CocoaPods / Android X. (#513) (5489f9e)

BREAKING CHANGES

6.1.1 (2019-07-03)

Bug Fixes

  • Loading images by reverting "bug: Use device scale when loading images.". (0326c3e), closes #509

6.1.0 (2019-06-30)

Features

6.0.5 (2019-06-28)

Bug Fixes

6.0.4 (2019-06-28)

Bug Fixes

6.0.3 (2019-06-03)

Bug Fixes

  • Add tintColor type definition. (4adf42f)

6.0.2 (2019-06-03)

Bug Fixes

  • Upgrade vendored SDWebImage to v5.0.5. (5016172), closes #489

6.0.1 (2019-05-25)

Bug Fixes

6.0.0 (2019-05-08)

Features

BREAKING CHANGES

  • Upgrade SDWebImage, may affect some projects and CocoaPods users.

Fix the bug of cacheOnly behavior

5.4.2 (2019-05-03)

Bug Fixes

  • Fix dependency versions not specified in podfile. (89f3379), closes #456

5.4.1 (2019-05-03)

Bug Fixes

  • Fix wildcard peer dependencies. (7149420), closes #440

5.4.0 (2019-05-03)

Features

5.3.0 (2019-04-23)

Bug Fixes

Features

Reverts

  • Remove functionality for notifying other images on load. (#452) (292223d)

5.2.1 (2019-04-21)

Performance Improvements

5.2.0 (2019-02-25)

Features

  • Use forwardRef to allow access to ref.measure and others. (#419) (2b4fba3), closes #69

5.1.4 (2019-02-25)

Bug Fixes

5.1.3 (2019-02-22)

Bug Fixes

5.1.2 (2018-12-30)

Fixed

5.1.1 (2018-11-13)

Fixed

  • URIs using the file scheme on Android. (1ea804593b8e3a9bb585ebec36d5484945d31c14 - @tsrkalexandr)
  • .idea/ being published to npm. (a01f8d596faddb71f5007bb32e2cd5e91a64634c - @retyui)
  • Manual installation docs for Android. (4cdee52a5eb7a9dee69ff770da7b0cf32f571cb4 - @fschindler)
    • Referencing deprecated compile instead of implementation.
    • Using hardcoded appcompat version instead of using rootProject.ext.

5.1.0 (2018-11-06)

@patrickkempff has done a lot to improve the stability and usefulness of this library in this release 🙏🏻.

Changed

  • A Resources.NotFoundException will now be thrown if a local image cannot be resolved. (7859d5b6d919c6c769bed4901d12b6941b4473bb - @patrickkempff)

Fixed

  • Not rendering local images in production builds. (47e36edc24a1990eeb735527ae4ebe6d2dbe61b5 - @patrickkempff)
  • Crash where activity was already destroyed before React Native could cleanup view manager. (8f702ed1d9ae69dfea172ebc5da3af7764a73808 - @patrickkempff)
  • Incorrect Flow types. (ba447531ace686d52178d943e9d5337d2fc74da7 - @retyui)

5.0.11 (2018-10-15)

Added

  • Support for showing local images. (fddee2c583c0978d0e7e91cdf4d6c87629afe015)
  • An example of auto-sizing. (400232767b1b0c5ce1d7fd5f87d9278bb70b0cb9)
  • fallback prop. (30a2ff7909df07d5188c4dbeae719d46562ef778)
  • cacheControl prop. (cf9a595ee929c1397063b97f44441f0556317f36, 9f422c4a74888ddc062dae20a212949256fc9daa)
  • Flow type definitions. (11c7e9e86508be289c57cacda00d687134458e2b - @retyui)

Changed

  • Upgraded to Glide 4. (f31a44fc07caa7d4635ae83936b8925891a1ab15)
  • Updated license info. (3bd08ef952967a736fb7baca29dd798daafb4376)
  • Decrease package size by ignoring more files. (a6f7b109aac070b487a6bdb54da7a2276f860e94)
  • Specify types file in package.json. (e5838165b6f6e56af534cb6f59dca81cd87dfcdf)

Fixed

  • Memory leaks on Android. (6e0e6f8f2b9c97dc4e31f5b3562944c1c0560870 - @patrickkempff)
  • Make sure headers only accepts key value pairs. (d142379e6f04ac8aa9e6c0e85d5c36949d027b78 - @BenWildeman)
  • Fix enum names in readme. (d2c33a85ce6cb67c8d1b0c6fcaa9bb591e69908a - @richeterre)
  • Make linking command in docs more specific. (22541243d96f6d4f50bf082c1f91a911ed91aba1 - @lfkwtz)
  • Changes to support getting Android compile and support library versions from ext in build.gradle.
  • Removed unnecessary import. (0f78b13d13ed4d239c6b2c3672f9c8f02aec096c - @retyui)
  • Added breaks in FastImageViewConverter.java. (efd02a307dc9aacad731325d39c325f772371d00 - @Yria)
  • Switches to new Gradle synax, using implementation instead of compile. (5d973a8cec50efdd3c20d05b97dbe59f71677944 - @yeomann)
  • Allow overwriting imageContainer styles. (b8c82c7d5ea7c4abe0b74f8976eb31e5999fc710 - @n1ru4l)
  • Add cache enum type to TypeScript definitions. (0c7e323ef0c818ff0e95f62211ad86058d9f3bb8 - @EQuimper)
  • TypeScript types for fallback. (c265c7a79a70067a3d1459e4878916fd5a13c2e6 - @retyui)
  • Handle null view.glideUrl. (75a6ce766c7fc2c1dd98a4e8d8c52c3aeeb3d506 - @ratson)
  • Incorrect cache property name in readme. (0ef723101846792e20ae9ba6420d5271ba6e928a - @vieiralucas)

4.0.14 (2018-05-09)

Changed

  • Add resizeMode examples.

4.0.13 (2018-05-09)

Fixed

  • Fix initial resizeMode. This fixes a bug where the stretch resizeMode could not be used. (6e5d0d7b89d71b5c05678d1ede7f6c27f809c9e9 - @bluekurk)

4.0.12 (2018-05-06)

Fixed

  • Revert some changes to default settings for building for Android. (a4e6ef3002319679d6faa95ca1314b2df36c433e)
  • Probably the correct way to deal with this going forward is to match the defaults to the values currently in React Native.
  • React Native may also choose to update the template to provide these properties on ext, in which case this issue would go away.

4.0.12 (2018-05-06)

Changed

  • Handle asset library URIs. (466f43f4aef74765ddc6e7740d4455748047acbf)
  • Improve TypeScript types. (75e3fd7cd832ce5e571b0ce1374a47a4b4c632c4)

4.0.10 (2018-05-05)

Changed

  • Handle assets from smart albums. (243b33db768b8afe4c58999db005600bda4a07dd)

4.0.9 (2018-05-05)

Fixed

  • Fix some issues with the examples.
  • Use OkHttpClientProvider to allow extending preconfigured clients. (eac670b2dcd26414c6c98426a9cda35ba35c5b67 - @btegenbosch)

4.0.8 (2018-05-05)

Added

  • Handle content and file urls.

4.0.7 (2018-05-05)

Added

  • Add instructions for manually linking. (71a52d9ba7973b881fef99c6688dbc4e2c2f8500 - @Meandmybadself)
  • Add note about proguard. (f31e8d6a3e752269b84fbf3d6017c1480c58c0f0)

Changed

  • Updated examples.
  • Use SDK version and variables from the root project. (c9b3aaef9ce9d1fdc701aa3bc7eaa99d3e3f57df - @rayronvictor)

Fixed

  • Fix bugs when using with createAnimatedComponent. (cf83d0f7f384afd262014f3a96feff32356611a2 - @kphungry)

4.0.6 (2018-04-24)

Fixed

  • Fix failing iOS builds. (#189)
  • Use conditional imports to support linking and CocoaPods. (084a41497d5688c7939f94be7d48d2f2ad74fb74)
  • Fix other FLAnimatedImage header search path. (ac00fdaa6309f03afc3bf052584a99c18726d21e)

4.0.4 (2018-04-21)

Changed

  • Set deprecated ALWAYS_SEARCH_USER_PATHS to NO. (e7ba4a7f789d883f4dbbe526612e70a2501d7be5)
  • Remove FLAnimatedImage from FastImage project since it's already included in SDWebImage. Installation remains the same as before when using CocoaPods. (a2d9fe2c71693721fec56e9cfe258a373a651b71)

Fixed

  • Fix FLAnimatedImage header search path. (883dc0664dfd6ca26a1b8bece161abd3b9184cf1)

4.0.3 (2018-04-21)

Fixed

4.0.2 (2018-04-19)

Added

  • Added borderRadius to style prop in TypeScript definitions.

Fixed

  • Fix onLoad not being called with dimensions on iOS. (@ligen52)

Removed

  • Remove borderRadius prop that was left in accidentally, including removing it from the TypeScript definitions. borderRadius should now be applied using style.

4.0.0 (2018-03-18)

Added

  • Support for CocoaPods. (@patrickkempff )
  • Width and height information to onLoad event. (@jeremyclee)

Fixed

  • An issue with onLoadEnd not being called. (@kdong007)
  • HEADER_SEARCH_PATHS. (@OceanHorn)
  • Use DecodeFormat.PREFER_ARGB_8888 to fix image quality issues. (@TilWs)

3.0.1 (2018-03-10)

Fixed

  • Adds support for using borderRadius from style.

Removed

  • Support for borderRadius property.
radius

2.2.6 (2018-03-07)

Fixed

2.2.4 (2018-02-13)

Changed

  • Update TypeScript definitions to include borderRadius.

2.2.3 (2018-01-31)

Added

2.1.4 (2018-01-31)

Fixed

2.1.3 (2018-01-30)

Added

Changed

  • Improved examples.

screen shot 2018-01-30 at 20 43 02

Fixed

2.0.1 (2017-11-30)

Removed

  • Locking of node version with engines.

2.0.0 (2017-11-30)

Changed

  • Updated example and docs.

Fixed

Removed

  • Removing backwards compatible View.propTypes.

1.0.0 (2017-08-08)

Added

  • Adds progress support.

Removed

  • Support for react-native < 0.47.0 because of a change to how native modules work.

0.0.11 (2017-06-20)

Added

  • Add support for preloading. ( 4e69ddd09908139feda66b283713d2b0efa04522 ) - @fjcaetano
  • Improve docs formatting.

0.0.10 (2017-05-04)

Added

  • Add gif support to iOS. 🎞

0.0.9 (2017-05-03)

Fixed

  • Re-release of previous version.

0.0.8 (2017-05-03)

Fixed

  • Fixed submodule installation.
  • This issue also caused the last version released to be packaged incorrectly (did not include SDWebImage).

0.0.7 (2017-04-28)

Fixed

  • Fix library header search paths. These being set incorrectly was causing archiving to fail.

0.0.6 (2017-04-20)

Fixed

  • Fix setNativeProps for plain Image component (no source).

0.0.5 (2017-04-19)

Fixed

  • Forward setNativeProps. Makes this component work with TouchableOpacity.

0.0.4 (2017-04-18)

Fixed

  • Fix onLoad and onError props on iOS.

0.0.3 (2017-04-18)

Changed

  • Remove useless image loading cancellation code.
  • Improve example.
  • Improve code formatting.

0.0.2 (2017-04-17)

Added

  • Initial release (for real).

0.0.1 (2017-04-17)

Added

  • Initial release.