@georstat/react-native-image-gallery

中文文档
1.1.0发布于 2022/04/03MITTypeScriptESM + CJS零依赖近 30 天下载 2498

React Native Image Gallery with Thumbnails

原始使用文档
文档目录9 节
  1. Features
  2. If you're looking for Image caching visit @georstat/react-n…
  3. Default Gallery Preview:
  4. Custom Gallery Preview:
  5. Installation
  6. Usage
  7. Props
  8. Todo:
  9. Authors:

React Native Image Gallery with Thumbnails

npm version npm License: MIT GitHub package.json version Platform - Android and iOS

Features

  • Image gallery with thumbnails
  • Made with PanResponder, no external dependencies
  • Written in Typescript

If you're looking for Image caching visit @georstat/react-native-image-cache

@georstat:react-native-image-gallery default_demo

@georstat:react-native-image-gallery default_demo

Installation

yarn:

yarn add @georstat/react-native-image-gallery

npm:

npm i @georstat/react-native-image-gallery

Usage

import { ImageGallery } from '@georstat/react-native-image-gallery';

const images = [
  {
    id: 1,
    url: 'https://...',
    // any other extra info you want
  },
  ...
]

const MyGallery = () => {
    const [isOpen, setIsOpen] = useState(false);
    const openGallery = () => setIsOpen(true);
    const closeGallery = () => setIsOpen(false);

    return (
        <View>
            <Button onPress={openGallery} title="Open Gallery" />
            <ImageGallery close={closeGallery} isOpen={isOpen} images={images} />
        </View>
    )
}

For more info check example

This example uses georstat/react-native-image-cache for image caching

import { ImageGallery } from '@georstat/react-native-image-gallery';
import { CacheManager, CachedImage } from '@georstat/react-native-image-cache';
import { Dirs } from 'react-native-file-access';
import {
  ImageGallery,
  ImageObject,
} from '@georstat/react-native-image-gallery';

CacheManager.config = {
  baseDir: `${Dirs.CacheDir}/images_cache/`,
  blurRadius: 15,
  sourceAnimationDuration: 1000,
  thumbnailAnimationDuration: 1000,
};

const MyGallery = () => {
  const [isOpen, setIsOpen] = useState(false);
  const openGallery = () => setIsOpen(true);
  const closeGallery = () => setIsOpen(false);

  const renderHeaderComponent = (image: ImageObject, currentIndex: number) => {
    return <Header currentIndex={currentIndex} />;
  };

  const renderFooterComponent = (image: ImageObject, currentIndex: number) => {
    return <Footer total={images.length} currentIndex={currentIndex} />;
  };

  const renderCustomImage = (image: ImageObject) => {
    return (
      <View style={styles.customImageContainer}>
        <CachedImage
          resizeMode="cover"
          source={image.url}
          style={styles.customImage}
          thumbnailSource="https://via.placeholder.com/350x150"
        />
      </View>
    );
  };
  return (
    <View>
      <Button onPress={openGallery} title="Open Gallery" />
      <ImageGallery
        close={closeCustomGallery}
        hideThumbs
        images={images}
        isOpen={isCustomGalleryOpen}
        renderCustomImage={renderCustomImage}
        renderFooterComponent={renderFooterComponent}
        renderHeaderComponent={renderHeaderComponent}
      />
    </View>
  );
};

Props

CachedImage accepts the following props:

PropertiesPropTypeDescription
isOpenBoolean(Required) when to show the gallery.
imagesArray(Required) array of objects. Every image must have a url (required), a thumbUrl (optional) and id (optional) and any other info you need
resizeModestringReact Native Image component resizeMode defaults to contain, used on images
closeFunc(Required) function to close the gallery image
disableSwipeBooleanDisables the swipe gesture.
initialIndexNumberInitial index of image to snap when opening the gallery
thumbSizeNumberHeight and width of the thumb, defaults to 48
thumbColorstringOutline color of selected thumb, defaults to #d9b44a
thumbResizeModestringReact Native Image component resizeMode defaults to cover, used on thumbnails
hideThumbsBooleanSet to true to hide the thumbs defaults to false
renderCustomThumbFuncFunction to render a custom thumb. Accepts image, index and if the thumb is selected, eg. (image:Image, index:number, isSelected:boolean) => ...
renderCustomImageFuncFunction to render a custom Image. Accepts image, index and if the thumb is selected, eg. (image:Image, index:number, isSelected:boolean) => ...
renderHeaderComponentFuncFunction to render a custom header at the top of the screen. Accepts image and current index, eg. (image:Image, currentIndex:number) => ...
renderFooterComponentFuncFunction to render a custom header at the top of the screen. Accepts image and current index eg. (image:Image, currentIndex:number) => ...

Todo:

  • Add zoom factor

  • Add prop to keep zoom and double tap to zoom out

Authors:

版本与发布记录

@georstat/react-native-image-gallery 共发布 3 个版本,首次发布于 2021/11/22;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.1.0latest2022/04/034 年前
1.0.22021/11/224 年前
1.0.12021/11/224 年前

关于 @georstat/react-native-image-gallery 的常见问题

@georstat/react-native-image-gallery 是什么?

React Native Image Gallery with Thumbnails

如何安装 @georstat/react-native-image-gallery?

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

@georstat/react-native-image-gallery 支持 TypeScript 吗?

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

@georstat/react-native-image-gallery 支持 ESM 还是 CommonJS?

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

@georstat/react-native-image-gallery 可以商用吗?

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

@georstat/react-native-image-gallery 的下载量有多少?

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

@georstat/react-native-image-gallery 还在维护吗?

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