@candlefinance/faster-image

中文文档
1.7.2发布于 2024/11/06MITTypeScriptESM + CJS零依赖近 30 天下载 7241

test

原始使用文档
文档目录7 节
  1. Features
  2. To be added
  3. Installation
  4. Usage
  5. Props
  6. Contributing
  7. License


https://github.com/candlefinance/faster-image/assets/12258850/ede91008-4dca-417c-a2ca-4d2177066316

A performant way to render images in React Native with a focus on speed and memory usage. Powered by Nuke, the smallest and most performant image loading library for iOS and macOS and Coil on Android.

The framework is lean and compiles in under 2 seconds¹. Nuke has an automated test suite 2x the size of the codebase itself, ensuring excellent reliability. Every feature is carefully designed and optimized for performance.

Coil performs a number of optimizations including memory and disk caching, downsampling the image in memory, automatically pausing/cancelling requests, and more.

Features

  • Supports visionOS
  • Fast image loading
  • Memory and disk caching
  • Placeholder support:
  • Animated transition
  • Failure image
  • Typescript support
  • Written in Swift/Kotlin

To be added

  • GIF support

Installation

yarn add @candlefinance/faster-image

Usage

import { FasterImageView, clearCache, prefetch } from '@candlefinance/faster-image';

<FasterImageView
  style={styles.image}
  onSuccess={(event) => {
    console.log(event.nativeEvent);
  }}
  onError={(event) => console.warn(event.nativeEvent.error)}
  source={{
    transitionDuration: 0.3,
    borderRadius: 50,
    cachePolicy: 'discWithCacheControl',
    showActivityIndicator: true,
    url: 'https://picsum.photos/200/200?random=1',
  }}
/>;

// Clear memory and disk cache
await clearCache();

// Prefetch
await prefetch(['https://picsum.photos/200/200?random=0'])

Props

PropTypeDefaultDescription
urlstringThe URL of the image
styleobjectThe style of the image
resizeModestringcontainThe resize mode of the image
thumbhashstringThe thumbhash of the image as a base64 encoded string to show while loading (Android not tested)
blurhashstringThe blurhash of the image to show while loading (iOS only)
showActivityIndicatorbooleanfalse (iOS only)Whether to show the UIActivityIndicatorView indicator when the image is loading
activityColorColorValueundefined (iOS only)Activity indicator color. Changed default activity indicator color. Only hex supported
base64PlaceholderstringThe base64 encoded placeholder image to show while the image is loading
cachePolicystringmemoryThe cache policy of the image
transitionDurationnumber0.75 (iOS) Android (100)The transition duration of the image
borderRadiusnumber0border radius of image
borderTopLeftRadiusnumber0top left border radius of image
borderTopRightRadiusnumber0top right border radius of image
borderBottomLeftRadiusnumber0bottom left border radius of image
borderBottomRightRadiusnumber0bottom right border radius of image
failureImagestringIf the image fails to download this will be set (blurhash, thumbhash, base64)
progressiveLoadingEnabledbooleanfalseProgressively load images (iOS only)
onErrorfunctionThe function to call when an error occurs. The error is passed as the first argument of the function
onSuccessfunctionThe function to call when the image is successfully loaded
grayscalenumber0Filter or transformation that converts the image into shades of gray (0-1).
colorMatrixnumber[][]Color matrix that is applied to image
ignoreQueryParamsForCacheKeybooleanfalseIgnore URL query parameters in cache keys
allowHardwarebooleantrueAllow hardware rendering (Android only)
headersRecord<string, string>undefinedPass in headers
accessibilityLabelstringundefinedaccessibility label
accessiblebooleanundefinedis accessible

Contributing

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

License

MIT

版本与发布记录

@candlefinance/faster-image 共发布 29 个版本,首次发布于 2023/03/27;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.7.2latest2024/11/062 年前
1.7.12024/11/032 年前
1.7.02024/11/032 年前
1.6.22024/06/282 年前
1.6.12024/06/022 年前
1.6.02024/05/262 年前

关于 @candlefinance/faster-image 的常见问题

@candlefinance/faster-image 是什么?

test

如何安装 @candlefinance/faster-image?

在项目目录运行 npm install @candlefinance/faster-image,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(*)、react-native(*)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@candlefinance/faster-image 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@candlefinance/faster-image 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@candlefinance/faster-image 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@candlefinance/faster-image 可以商用吗?

@candlefinance/faster-image 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@candlefinance/faster-image 的下载量有多少?

根据 npm 官方下载统计,@candlefinance/faster-image 在 2026/10/09 – 2026/11/07 这 30 天内被下载 7,241 次,日均约 241 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@candlefinance/faster-image 还在维护吗?

最新版本 1.7.2 发布于 2024/11/06(2 年前);至今共发布 29 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/03/27。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。