Skip to content

duguyihou/react-native-turbo-image

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

You can find more examples in example folder

TurboImage

Performant image component for React Native. Powered by Nuke and Coil

Features

  • Support New Architecture. see the example
  • Support authorization headers
  • Support thumbhash, blurhash and memoryCacheKey for placeholder
  • Memory cache, aggressive LRU disk cache and HTTP disk cache
  • Prefetch, dispose, cleanMemoryCache and cleanDiskCache
  • Written in TypeScript, Swift and Kotlin
  • Support special formats (SVG, Gif, APNG)

Installation

npm install react-native-turbo-image

cd ios && pod install

Usage

import TurboImage from 'react-native-turbo-image';

<TurboImage
  source={{ uri: "https://github.com/duguyihou/react-native-turbo-image/assets/9347790/7955aa00-0b53-44d1-88bd-9b5e320db21e" }}
  style={{ width: 300, height: 300 }}
/>;

Properties

Name Type Description Default
source Source (Required) an object containing a uri string -
style ImageStyle Styles to be applied to the image. -
placeholder Placeholder show placeholder while loading -
cachePolicy CachePolicy Determines how to cache the image urlCache
resizeMode String Resize the image with one of the options: contain cover stretch center contain
indicator object style: medium(default) or largecolor: number / ColorValue -
fadeDuration number The transition duration of the image. Note: To avoid flicking, it will be set to 0 when a placeholder is provided 300(iOS) / 100(Android)
resize number Scales an image to the given width preserving aspect ratio -
blur number The blur radius of the blur filter added to the image -
monochrome number / ColorValue The color applied to the image. note: For iOS and Android Q+, it works with any color. For Android Q-, it only supports grayscale -
tint number / ColorValue The color is applied to every non-transparent pixel, causing the image’s shape to adopt that color. This effect is not applied to placeholders -
showPlaceholderOnFailure boolean Show the placeholder image in the case of a failure false
rounded boolean Round the image into a circle false
enableLiveTextInteraction boolean Enables Live Text interaction with the image (iOS 16+ only) false
allowHardware boolean Setting this to false this will reduce performance on API 26 and above. Only disable this if necessary. Coil's docs (Android only) false
format string Specify the format for special image, e.g. svg, gif and apng. In general, TurboImage will determine the decoder automatically. -
onStart Function The function to call when the image is fetching. -
onSuccess Function The function to call when the image is successfully loaded -
onFailure Function The function to call when the request failed -
onCompletion Function The function to call when the request is completed -

Methods

prefetch

await TurboImage.prefetch([Source]);

dispose

await TurboImage.dispose([Source]);

clearMemoryCache

await TurboImage.clearMemoryCache();

clearDiskCache

await TurboImage.clearDiskCache();

Types

Source

Name Type Description
uri string the url of the image
headers Record<string, string> An object representing the HTTP headers to send along with the request for a remote image
cacheKey string The cache key used to query and store this specific image. If not provided, the uri is used also as the cache key

Placeholder

Name Type Description
thumbhash string A string used to generate the image placeholder. For more information, see thumbhash
blurhash string A string used to generate the image placeholder. For more information, see woltapp/blurhash.
memoryCacheKey string Using the key of previous request as placeholder. For more information, see Memory Cache Key
thumbhash blurhash memoryCacheKey

CachePolicy

Name Type Description
urlCache string Allows the server to manage caching precisely through cache-control HTTP headers. You can determine which images to cache and caching duration
dataCache string Ignores HTTP cache control

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

TurboImage is released under the MIT license. Some of the dependencies are licensed differently, with the Apache-2.0 license, for example.