@alessiocancian/react-native-actionsheet

中文文档
3.2.0发布于 2022/11/18MITTypeScriptCommonJS近 30 天下载 7155

Cross platform ActionSheet. This component implements a custom ActionSheet and provides the same way to drawing it on the defferent platforms(iOS and Android). Actually, In order to keep the best effect, it still uses the ActionSheetIOS on iOS.

原始使用文档
文档目录7 节
  1. Install
  2. Usage
  3. Functional components
  4. Class components
  5. Use ActionSheetCustom directly
  6. How to redesign style ?
  7. Props

react-native-actionsheet

npm
Cross platform ActionSheet. This component implements a custom ActionSheet and provides the same way to drawing it on the defferent platforms(iOS and Android). Actually, In order to keep the best effect, it still uses the ActionSheetIOS on iOS.

Starting from v3.0.0 a custom ActionSheet with a native-like UI is available and used as default option for iOS:

A similar UI is available for Android too by passing theme="ios":

Install

npm i -S @alessiocancian/react-native-actionsheet

Usage

Functional components

import { useRef } from 'react'
import ActionSheet from '@alessiocancian/react-native-actionsheet'

const Demo = () => {
  const actionSheetRef = useRef()

  const showActionSheet = () => {
    actionSheetRef.current.show()
  }
  
  render() {
    return (
      <View>
        <Text onPress={showActionSheet}>Open ActionSheet</Text>
        <ActionSheet
          ref={actionSheetRef}
          title={'Which one do you like ?'}
          options={['Apple', 'Banana', 'cancel']}
          cancelButtonIndex={2}
          destructiveButtonIndex={1}
          onPress={(index) => { /* do something */ }}
        />
      </View>
    )
  }
}

Class components

import ActionSheet from '@alessiocancian/react-native-actionsheet'

class Demo extends React.Component {
  showActionSheet = () => {
    this.ActionSheet.show()
  }
  render() {
    return (
      <View>
        <Text onPress={this.showActionSheet}>Open ActionSheet</Text>
        <ActionSheet
          ref={o => this.ActionSheet = o}
          title={'Which one do you like ?'}
          options={['Apple', 'Banana', 'cancel']}
          cancelButtonIndex={2}
          destructiveButtonIndex={1}
          onPress={(index) => { /* do something */ }}
        />
      </View>
    )
  }
}

Use ActionSheetCustom directly

so you can customize option and title

import { ActionSheetCustom as ActionSheet } from '@alessiocancian/react-native-actionsheet'

const options = [
  'Cancel', 
  'Apple', 
  <Text style={{color: 'yellow'}}>Banana</Text>,
  'Watermelon', 
  <Text style={{color: 'red'}}>Durian</Text>
]

class Demo extends React.Component {
  showActionSheet = () => {
    this.ActionSheet.show()
  }
  render() {
    return (
      <View>
        <Text onPress={this.showActionSheet}>Open ActionSheet</Text>
        <ActionSheet
          ref={o => this.ActionSheet = o}
          title={<Text style={{color: '#000', fontSize: 18}}>Which one do you like?</Text>}
          options={options}
          cancelButtonIndex={0}
          destructiveButtonIndex={4}
          onPress={(index) => { /* do something */ }}
        />
      </View>
    )
  }
}

How to redesign style ?

The style of ActionSheet is defined in lib/styles.js. We can pass the styles prop to cover default style. See Example .

// example

const styles = {
  titleBox: {
    background: 'pink'
  },
  titleText: {
    fontSize: 16,
    color: '#000'
  }
}

<ActionSheet
  ...
  styles={styles}
/>

Props

https://github.com/alessiocancian/react-native-actionsheet/blob/master/lib/options.js

Prop name Type Description Default
title string or ReactNode ActionSheetCustom needed to use ReactNode for iOS
message string or ReactNode ActionSheetCustom needed to use ReactNode for iOS
options (string | ReactChild)[] ActionSheetCustom needed to use ReactChild options for iOS
tintColor string
cancelButtonIndex number
destructiveButtonIndex number
onPress function
userInterfaceStyle "light" | "dark" RN version >=0.63 System theme
theme "flat" | "ios" flat for Android and native or native-like for iOS
styles only for ActionSheetCustom {}
statusBarTranslucent boolean only for Android false

版本与发布记录

@alessiocancian/react-native-actionsheet 共发布 20 个版本,首次发布于 2021/02/21;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.2.0latest2022/11/183 年前
3.1.42022/11/183 年前
3.1.32022/11/054 年前
3.1.22022/02/244 年前
3.1.12021/09/145 年前
3.1.02021/09/025 年前

关于 @alessiocancian/react-native-actionsheet 的常见问题

@alessiocancian/react-native-actionsheet 是什么?

Cross platform ActionSheet. This component implements a custom ActionSheet and provides the same way to drawing it on the defferent platforms(iOS and Android). Actually, In order to keep the best effect, it still uses the ActionSheetIOS on iOS.

如何安装 @alessiocancian/react-native-actionsheet?

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

@alessiocancian/react-native-actionsheet 支持 TypeScript 吗?

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

@alessiocancian/react-native-actionsheet 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@alessiocancian/react-native-actionsheet 可以商用吗?

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

@alessiocancian/react-native-actionsheet 的下载量有多少?

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

@alessiocancian/react-native-actionsheet 还在维护吗?

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