• Stars
    star
    1,301
  • Rank 34,689 (Top 0.8 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 8 years ago
  • Updated 18 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A cross-platform ActionSheet for React Native

@expo/react-native-action-sheet

npm License: MIT Discord

React Native Action Sheet is a cross-platform React Native component that uses the native UIActionSheet on iOS and a pure JS implementation on Android.

iOS Android Web

Check out the example snack here!

Installation

npm install @expo/react-native-action-sheet

or

yarn add @expo/react-native-action-sheet

A basic ActionSheet Setup

1. Wrap your top-level component with <ActionSheetProvider />

ReactNativeActionSheet uses React context to allow your components to invoke the menu. This means your app needs to be wrapped with the ActionSheetProvider component first.

import { ActionSheetProvider } from '@expo/react-native-action-sheet';

export default function AppContainer() {
  return (
    <ActionSheetProvider>
      <App />
    </ActionSheetProvider>
  );
}

2. Call the showActionSheetWithOptions method with a hook or a higher order component.

// Using the provided hook
import { useActionSheet } from '@expo/react-native-action-sheet';

export default Menu() {
  const { showActionSheetWithOptions } = useActionSheet();

  const onPress = () => {
    const options = ['Delete', 'Save', 'Cancel'];
    const destructiveButtonIndex = 0;
    const cancelButtonIndex = 2;

    showActionSheetWithOptions({
      options,
      cancelButtonIndex,
      destructiveButtonIndex
    }, (selectedIndex: number) => {
      switch (selectedIndex) {
        case 1:
          // Save
          break;

        case destructiveButtonIndex:
          // Delete
          break;

        case cancelButtonIndex:
          // Canceled
      }});
  }

  return (
    <Button title="Menu" onPress={onPress}/>
  )
};

Alternatively, any component can use the higher order component to access the context and pass the showActionSheetWithOptions as a prop.

// Using a Higher Order Component to wrap your component
import { connectActionSheet } from '@expo/react-native-action-sheet';

function Menu({ showActionSheetWithOptions }) {
  /* ... */
}

export default connectActionSheet(Menu);

Menu component can now access the actionSheet prop as showActionSheetWithOptions.

Options

The goal of this library is to mimic the native iOS and Android ActionSheets as closely as possible.

This library can also be used in the browser with Expo for web.

Universal Props

Name Type Description
options array of strings A list of button titles (required)
cancelButtonIndex number Index of cancel button in options
cancelButtonTintColor string Color used for the change the text color of the cancel button
destructiveButtonIndex number or array of numbers Indices of destructive buttons in options
title string Title to show above the action sheet
message string Message to show below the title
tintColor string Color used for non-destructive button titles
disabledButtonIndices array of numbers Indices of disabled buttons in options

iOS Only Props

Name Type Description
anchor number iPad only option that allows for docking the action sheet to a node. See ShowActionSheetButton.tsx for an example on how to implement this.
userInterfaceStyle string The interface style used for the action sheet, can be set to light or dark, otherwise the default system style will be used.

Custom Action Sheet Only (Android/Web) Props

The below props allow modification of the Android ActionSheet. They have no effect on the look on iOS as the native iOS Action Sheet does not have options for modifying these options.

Name Type Description
icons array of required images or icons Show icons to go along with each option. If image source paths are provided via require, images will be rendered for you. Alternatively, you can provide an array of elements such as vector icons, pre-rendered Images, etc.
tintIcons boolean Icons by default will be tinted to match the text color. When set to false, the icons will be the color of the source image. This is useful if you want to use multicolor icons. If you provide your own nodes/pre-rendered icons rather than required images in the icons array, you will need to tint them appropriately before providing them in the array of icons; tintColor will not be applied to icons unless they are images from a required source.
textStyle TextStyle Apply any text style props to the options. If the tintColor option is provided, it takes precedence over a color text style prop.
titleTextStyle TextStyle Apply any text style props to the title if present.
messageTextStyle TextStyle Apply any text style props to the message if present.
autoFocus boolean If true, this will give the first option screen reader focus automatically when the action sheet becomes visible. On iOS, this is the default behavior of the native action sheet.
showSeparators boolean Show separators between items. On iOS, separators always show so this prop has no effect.
containerStyle ViewStyle Apply any view style props to the container rather than use the default look (e.g. dark mode).
separatorStyle ViewStyle Modify the look of the separators rather than use the default look.
useModal boolean Defaults to false (true if autoFocus is also true) Wraps the ActionSheet with a Modal, in order to show in front of other Modals that were already opened (issue reference).
destructiveColor string Modify color for text of destructive option. Defaults to #d32f2f.

ActionSheetProvider Props

The following props can be set directly on the ActionSheetProvider

Name Type Description
useCustomActionSheet boolean iOS only prop that uses the custom pure JS action sheet (Android/Web version) instead of the native ActionSheetIOS component. Defaults to false.
useNativeDriver boolean Windows only option that provides the option to disable the native animation driver for React Native Windows projects targeting Windows 10 Version-1809 ; Build-10.0.17763.0 and earlier. useNativeDriver is supported in Version-1903 and later so if your project is targeting that, you don't need to set this prop.
// example of using useCustomActionSheet on iOS
export default function AppContainer() {
  return (
    <ActionSheetProvider useCustomActionSheet={true}>
      <App />
    </ActionSheetProvider>
  );
}

Callback

The second parameter of the showActionSheetWithOptions function is a callback for when a button is selected. The callback takes a single argument which will be the zero-based index of the pressed option. You can check the value against your cancelButtonIndex to determine if the action was cancelled or not.

function onButtonPress(selectedIndex: number) {
  // handle it!
}

Try it out

Try it in Expo Snack: https://snack.expo.dev/@expo-action-sheet/example.

Example

See the example app.

Usage

$ cd example
$ yarn

// build simulator
$ yarn ios
$ yarn android

// web
$ yarn web

Development

Setup

$ git clone [email protected]:expo/react-native-action-sheet.git
$ cd react-native-action-sheet
$ yarn

Build

We use bob.

$ yarn build

Lint & Format

// tsc
$ yarn type-check

// ESLint + Prettier
$ yarn lint

More Repositories

1

expo

An open-source framework for making universal native apps with React. Expo runs on Android, iOS, and the web.
TypeScript
28,995
star
2

create-react-native-app

Create React Native apps that run on iOS, Android, and web
TypeScript
13,151
star
3

expo-cli

Tools for creating, running, and deploying universal Expo and React Native apps
TypeScript
2,590
star
4

examples

Example projects that demonstrate how to use Expo APIs and integrate Expo with other popular tools
JavaScript
1,567
star
5

router

[ARCHIVE]: Expo Router has moved to expo/expo -- The File-based router for universal React Native apps
TypeScript
1,358
star
6

xde

The Expo Development Environment
JavaScript
1,168
star
7

ex-navigation

Route-centric navigation for React Native
JavaScript
1,003
star
8

google-fonts

Use any of the 1000+ fonts (and their variants) from fonts.google.com in your Expo app.
JavaScript
739
star
9

expo-github-action

Expo GitHub Action makes it easy to automate EAS builds or updates
TypeScript
714
star
10

expo-server-sdk-node

Server-side library for working with Expo using Node.js
TypeScript
674
star
11

fyi

Little bits of information that you may find useful when interacting with Expo tools and service. Append the markdown filename to https://expo.fyi/ to get a quick link to it.
667
star
12

eas-cli

Fastest way to build, submit, and update iOS and Android apps
TypeScript
648
star
13

vector-icons

JavaScript
638
star
14

expo-three

Utilities for using THREE.js on Expo
TypeScript
619
star
15

react-native-read-more-text

JavaScript
572
star
16

ex-navigator

Route-centric navigation built on top of React Native's Navigator
JavaScript
522
star
17

react-native-infinite-scroll-view

An infinitely scrolling view that notifies you as the scroll offset approaches the bottom
JavaScript
520
star
18

awesome-expo

Useful resources for creating apps with Exponent
468
star
19

exp

JavaScript
465
star
20

react-native-invertible-scroll-view

An invertible ScrollView for React Native
JavaScript
460
star
21

config-plugins

Out-of-tree Expo config plugins for packages that haven't adopted the config plugin system yet.
TypeScript
401
star
22

turtle

Standalone app builder service
TypeScript
386
star
23

vscode-expo

Expo Tools keep you productive with debugging, IntelliSense, and prebuild previews
TypeScript
377
star
24

orbit

Accelerate your development workflow with one-click build launches and simulator management from your macOS menu bar
TypeScript
346
star
25

snack

Expo Snack lets you run Expo in the browser.
TypeScript
340
star
26

react-native-appearance

Access operating system appearance information (currently only light/dark mode) on iOS, Android, and web
Java
337
star
27

expo-pixi

Tools for using pixi.js in Expo
JavaScript
300
star
28

use-unmount-signal

A React Hook to cancel promises when a component is unmounted
TypeScript
289
star
29

web-examples

Examples of using Expo in the browser.
JavaScript
273
star
30

image-upload-example

Demonstration of how to upload images from the ImagePicker, using a node backend to upload to S3
JavaScript
228
star
31

snack-web

TypeScript
214
star
32

expo-phaser

Use Phaser.js on mobile with Expo GL
JavaScript
212
star
33

sentry-expo

TypeScript
197
star
34

custom-expo-updates-server

TypeScript
194
star
35

fluxpybird

some ideas involving games and Redux
JavaScript
179
star
36

stripe-expo

Use the Stripe HTTP API in Expo without the DOM, node, or native deps
JavaScript
160
star
37

react-native-responsive-image

A responsive Image component that chooses the best-resolution image for the current screen
JavaScript
160
star
38

react-native-loading-container

A container component that takes care of loading/catching timeouts/retrying
JavaScript
156
star
39

camerja

JavaScript
156
star
40

playlist-example

JavaScript
151
star
41

match-media

Universal polyfill for match media API using Expo APIs on mobile
TypeScript
131
star
42

dev-plugins

Out-of-tree Expo devtools plugins for packages that haven't adopted the Expo devtools plugin system yet.
TypeScript
119
star
43

react-native-fade-in-image

JavaScript
118
star
44

entity

Entity is a privacy-aware data layer for defining, caching, and authorizing access to application data models.
TypeScript
116
star
45

eslint-config-universe

Moved to https://github.com/expo/expo/tree/master/packages/eslint-config-universe
JavaScript
110
star
46

audio-recording-example

Audio Recording Example
TypeScript
109
star
47

redux-effex

Spin off async functions to perform side effects
JavaScript
108
star
48

auth0-example

This example has moved
JavaScript
108
star
49

expo-2d-context

A pure-js implementation of the W3C's Canvas-2D Context API that can be run on either Expo Graphics or WebGL
HTML
103
star
50

results

An efficient, standards-compliant library for representing results of successful or failed operations
TypeScript
102
star
51

firebase-storage-upload-example

This example has moved
JavaScript
98
star
52

sqlite-example

This example has moved
JavaScript
97
star
53

react-native-scrollable-mixin

A standard interface for your scrollable React Native components, making it easier to compose components.
JavaScript
94
star
54

expo-processing

Utilities for using Processing.js on Expo
JavaScript
93
star
55

videoplayer

Customizable controls for Expo video
JavaScript
83
star
56

snack-sdk

Snack SDK
JavaScript
83
star
57

react-apple-easing

Apple's default Core Animation easing functions for React
JavaScript
83
star
58

turtle-cli-example

Turtle CLI usage example (CircleCI & Travis CI)
Shell
81
star
59

dire-dire-ducks

Flood your room with water and rubber duckies!
JavaScript
77
star
60

status-bar-height

Listen to status bar changes during incoming calls and other multi-tasking events
JavaScript
73
star
61

expo-preview-action

With this preview action, you can test changes made in pull requests via Expo Go or custom development client (created with expo-dev-client) just by scanning QR code.
JavaScript
72
star
62

react-native-image-gallery

JavaScript
71
star
63

pomodoroexp

https://expo.io/@community/pomodoro
JavaScript
70
star
64

expo-three-ar

Utilities for using Expo AR with THREE.js
TypeScript
70
star
65

eas-build

TypeScript
61
star
66

react-native-refreshable-scroll-view

A ScrollView that supports pull-to-refresh. You can customize it with the RefreshIndicator and type of ScrollView (ex: ListView) of your choice.
JavaScript
61
star
67

spawn-async

A Promise-based interface into processes created by child_process.spawn
TypeScript
59
star
68

react-native-for-curious-people

Available through the Exponent iPhone or Android app:
JavaScript
59
star
69

browser-polyfill

Browser polyfill for making React Native compatible with web libs like pixi.js, three.js, phaser.js
JavaScript
52
star
70

xdl

The Expo Development Library
TypeScript
47
star
71

UpdatesAPIDemo

Demo app showing the useUpdates() API
TypeScript
46
star
72

harvard-cs50-app

Harvard's mobile application for CS50.
JavaScript
46
star
73

hello-graphql

JavaScript
44
star
74

expo-graphics

Tools to help simplify working with three, pixi, phaser, ect...
JavaScript
44
star
75

detox-expo-helpers

JavaScript
43
star
76

expo-asset-utils

Utilities for parsing files references, and Expo Assets.
TypeScript
42
star
77

styleguide

Foundational styles for Expo interfaces.
TypeScript
42
star
78

hackathon-examples

40
star
79

with-detox-tests

This template is no longer maintained! See https://github.com/yaron1m/expo-detox-typescript-example instead
JavaScript
39
star
80

react-native-scrollable-decorator

A standard interface for your scrollable React Native components, making it easier to compose components.
JavaScript
38
star
81

react-native-url-handler

Navigate to external URLs, handle in-app URLs, and access system URLs
Objective-C
36
star
82

rnplay

THIS REPOSITORY IS QUITE OLD AND NOT MAINTAINED! React Native Playground has been replaced by https://snack.expo.io. Look at this repository like you might look at tools in a museum, and don't touch it or actually use it
JavaScript
36
star
83

expo-twitter-login-example

This example has moved
JavaScript
34
star
84

react-native-image-picker-android

A camera and gallery image picker native module for Android, giving a subset of the API of https://github.com/marcshilling/react-native-image-picker
Java
34
star
85

react-loading-indicator

A loading indicator written purely in React that uses SVG and no images.
JavaScript
32
star
86

socket-io-example

This example has moved
29
star
87

koa-graphiql

Koa middleware to display GraphiQL, the interactive GraphQL UI
JavaScript
27
star
88

video-background-example

This example has moved
JavaScript
27
star
89

expo-electron-adapter

This package wraps `electron-webpack` and adds support for Expo web and other universal React packages.
TypeScript
27
star
90

eas-tests-example

Demo of running E2E tests on EAS Build
Java
26
star
91

gl-test

Examples and tests for OpenGL rendering in Expo.
JavaScript
26
star
92

three-ar-test

Using Expo's AR functionality with THREE.js
JavaScript
25
star
93

BrightSky

Learn how to use Expo with this simple weather app!
TypeScript
24
star
94

expo-postpublish-slack-notify

JavaScript
24
star
95

breakout

why not?
JavaScript
24
star
96

hyperinstall

Runs "yarn" and "npm install" in several directories with extreme speed when possible
JavaScript
23
star
97

pound-random

Expo Blue - a discussion app for small groups
JavaScript
22
star
98

electron-cookies

Provides document.cookie support for Electron
JavaScript
22
star
99

instapromise

Promisify node style async functions by putting a `.promise` after them (or after the object for methods)
JavaScript
21
star
100

floatyplane

JavaScript
21
star