Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 48 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
# react-native-action-sheet

[![npm](https://img.shields.io/npm/v/@expo/react-native-action-sheet.svg?style=flat-square)](https://www.npmjs.com/package/@expo/react-native-action-sheet)
[![License: MIT](https://img.shields.io/github/license/nd-02110114/goofi-mobile.svg)](https://opensource.org/licenses/MIT)
[![Discord](https://img.shields.io/badge/discord-expo-green?style=flat-square&logo=discord)](https://discord.gg/4gtbPAdpaE)

ActionSheet is a cross-platform React Native component that uses the native UIActionSheet on iOS and a JS implementation on Android. Almost a drop in replacement for [ActionSheetIOS](https://facebook.github.io/react-native/docs/actionsheetios.html) except it cannot be called statically.


| iOS | Android | Web |
|---------------------------|---------------------------|---------------------------|
| iOS | Android | Web |
| -------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------- |
| <img src="https://raw.githubusercontent.com/expo/react-native-action-sheet/master/gif/ios.gif" width="200" height="400"/> | <img src="https://raw.githubusercontent.com/expo/react-native-action-sheet/master/gif/android.gif" width="200" height="400"/> | <img src="https://raw.githubusercontent.com/expo/react-native-action-sheet/master/gif/web.gif" width="400" height="400"/> |


## Installation

```
$ npm install @expo/react-native-action-sheet -S
```

or

```
$ yarn add @expo/react-native-action-sheet
```
Expand All @@ -26,8 +27,7 @@ $ yarn add @expo/react-native-action-sheet
### 1. Wrap your top-level component with `<ActionSheetProvider />`

```es6

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

class AppContainer extends React.Component {
render() {
Expand All @@ -41,16 +41,17 @@ class AppContainer extends React.Component {
```

### 2. Connect your component which uses showActionSheetWithOptions.

```es6
import { connectActionSheet } from '@expo/react-native-action-sheet'
import { connectActionSheet } from '@expo/react-native-action-sheet';

class App extends React.Component {
/* ... */
}

const ConnectedApp = connectActionSheet(App)
const ConnectedApp = connectActionSheet(App);

export default ConnectedApp
export default ConnectedApp;
```

`App` component can access the actionSheet method as `this.props.showActionSheetWithOptions`
Expand All @@ -68,19 +69,19 @@ _onOpenActionSheet = () => {
cancelButtonIndex,
destructiveButtonIndex,
},
buttonIndex => {
(buttonIndex) => {
// Do something here depending on the button index selected
},
}
);
};
```

You can use a hook instead of the higher order component if you are on React 16.8 or newer.

```es6
import { useActionSheet } from '@expo/react-native-action-sheet'
import { useActionSheet } from '@expo/react-native-action-sheet';

export default function App () {
export default function App() {
const { showActionSheetWithOptions } = useActionSheet();
/* ... */
}
Expand All @@ -94,82 +95,93 @@ This library can also be used in the browser with Expo for web.

### Universal Props

The same options available on React Native's [ActionSheetIOS](https://facebook.github.io/react-native/docs/actionsheetios.html#showactionsheetwithoptions) component exist for both iOS and Android in this library.
The same options available on React Native's [ActionSheetIOS](https://reactnative.dev/docs/0.64/actionsheetios#showactionsheetwithoptions) component exist for both iOS and Android in this library. Note: `disabledButtonIndicies` is only available for iOS in Expo 43+ or RN 0.64.0+.

### iOS Only Props

| Name | Type | Required | Default |
| -------------------| -------| -------- | ------- |
| ------------------ | ------ | -------- | ------- |
| anchor | number | No | |
| userInterfaceStyle | string | No | |

#### `anchor` (optional)

iPad only option that allows for docking the action sheet to a node. See [ShowActionSheetButton.tsx](/example/ShowActionSheetButton.tsx) for an example on how to implement this.

#### `userInterfaceStyle` (optional)

The interface style used for the action sheet, can be set to `light` or `dark`, otherwise the default system style will be used.

### Android/Web-Only 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 | Required | Default |
| -----------------| ----------------------------------| -------- | ------- |
| icons | array of required images or icons | No | |
| tintIcons | boolean | No | true |
| textStyle | TextStyle | No | |
| titleTextStyle | TextStyle | No | |
| messageTextStyle | TextStyle | No | |
| autoFocus | boolean | No | false |
| showSeparators | boolean | No | false |
| containerStyle | ViewStyle | No | |
| separatorStyle | ViewStyle | No | |
| useModal | boolean | No | false (true if autoFocus is true) |
| destructiveColor | string | No | #d32f2f |
| Name | Type | Required | Default |
| ---------------- | --------------------------------- | -------- | --------------------------------- |
| icons | array of required images or icons | No | |
| tintIcons | boolean | No | true |
| textStyle | TextStyle | No | |
| titleTextStyle | TextStyle | No | |
| messageTextStyle | TextStyle | No | |
| autoFocus | boolean | No | false |
| showSeparators | boolean | No | false |
| containerStyle | ViewStyle | No | |
| separatorStyle | ViewStyle | No | |
| useModal | boolean | No | false (true if autoFocus is true) |
| destructiveColor | string | No | #d32f2f |

#### `icons` (optional)

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` (optional)
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.

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` (optional)

Apply any text style props to the options. If the `tintColor` option is provided, it takes precedence over a color text style prop.

#### `titleTextStyle` (optional)

Apply any text style props to the title if present.

#### `messageTextStyle` (optional)

Apply any text style props to the message if present.

#### `autoFocus`: (optional)

If true, 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`: (optional)

Show separators between items. On iOS, separators always show so this prop has no effect.

#### `containerStyle`: (optional)

Apply any view style props to the container rather than use the default look (e.g. dark mode).

#### `separatorStyle`: (optional)

Modify the look of the separators rather than use the default look.

#### `useModal`: (optional)

Wrap the ActionSheet with a Modal, in order to show in front of other Modals that were already opened ([issue reference](https://github.com/expo/react-native-action-sheet/issues/164)).

#### `destructiveColor`: (optional)

Modify color for text of destructive option.

## ActionSheetProvider Props

The following props can be set directly on the `ActionSheetProvider`

#### `useNativeDriver` (optional)
Windows only option that provides the option to disable the [native animation](https://reactnative.dev/docs/animated#using-the-native-driver) 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](https://microsoft.github.io/react-native-windows/docs/win10-compat) so if your project is targeting that, you don't need to set this prop.

Windows only option that provides the option to disable the [native animation](https://reactnative.dev/docs/animated#using-the-native-driver) 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](https://microsoft.github.io/react-native-windows/docs/win10-compat) so if your project is targeting that, you don't need to set this prop.

## Try it out

Expand All @@ -180,6 +192,7 @@ Try it in Expo: https://expo.io/@community/react-native-action-sheet-example
See the [example app](https://github.com/expo/react-native-action-sheet/tree/master/example).

### Usage

```
$ cd example
$ yarn
Expand All @@ -195,19 +208,23 @@ $ yarn web
## Development

### Setup

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

### Build

We use [bob](https://github.com/react-native-community/bob).

```
$ yarn build
```

### Lint & Format

```
// tsc
$ yarn type-check
Expand Down
14 changes: 9 additions & 5 deletions example/ShowActionSheetButton.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { ActionSheetOptions } from '@expo/react-native-action-sheet';
import { MaterialIcons, Entypo } from '@expo/vector-icons';
import * as React from 'react';
import { Text, View, TextStyle, ViewStyle, findNodeHandle, Button } from 'react-native';
import { Text, View, TextStyle, ViewStyle, findNodeHandle } from 'react-native';

const icon = (name: string) => <MaterialIcons key={name} name={name} size={24} />;
const icon = (name: React.ComponentProps<typeof MaterialIcons>['name']) => (
<MaterialIcons key={name} name={name} size={24} />
);

interface Props {
title: string;
Expand Down Expand Up @@ -34,7 +36,7 @@ export default class ShowActionSheetButton extends React.PureComponent<Props> {
useModal: false,
};

_anchorRef = React.createRef<Button>();
_anchorRef = React.createRef<any>();

_showActionSheet = () => {
const {
Expand All @@ -50,7 +52,7 @@ export default class ShowActionSheetButton extends React.PureComponent<Props> {
} = this.props;

// Same interface as https://facebook.github.io/react-native/docs/actionsheetios.html
const options = ['Delete', 'Save', 'Share', 'Cancel'];
const options = ['Delete', 'Disabled', 'Save', 'Share', 'Cancel'];
const icons = withIcons
? [icon('delete'), icon('save'), icon('share'), icon('cancel')]
: undefined;
Expand All @@ -59,7 +61,8 @@ export default class ShowActionSheetButton extends React.PureComponent<Props> {
? 'This library tries to mimic the native share sheets as close as possible.'
: undefined;
const destructiveButtonIndex = 0;
const cancelButtonIndex = 3;
const disabledButtonIndices = [1];
const cancelButtonIndex = 4;
const textStyle: TextStyle | undefined = withCustomStyles
? {
fontSize: 20,
Expand Down Expand Up @@ -96,6 +99,7 @@ export default class ShowActionSheetButton extends React.PureComponent<Props> {
options,
cancelButtonIndex,
destructiveButtonIndex,
disabledButtonIndices,
title,
message,
icons,
Expand Down
20 changes: 10 additions & 10 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
},
"dependencies": {
"@expo/react-native-action-sheet": "../src",
"@expo/vector-icons": "^10.0.0",
"expo": "^39.0.0",
"@expo/vector-icons": "^12.0.0",
"expo": "^43.0.0-beta.3",
"hoist-non-react-statics": "^3.3.0",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-39.0.3.tar.gz",
"react-native-web": "~0.13.7"
"react": "17.0.1",
"react-dom": "17.0.1",
"react-native": "0.64.2",
"react-native-web": "0.17.1"
},
"devDependencies": {
"@types/react": "~16.9.35",
"@types/react-native": "~0.63.2",
"babel-preset-expo": "^8.3.0",
"typescript": "~3.9.2"
"@types/react": "~17.0.21",
"@types/react-native": "~0.64.12",
"babel-preset-expo": "8.5.1",
"typescript": "~4.3.5"
}
}
13 changes: 10 additions & 3 deletions example/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@
"compilerOptions": {
"esModuleInterop": true,
"jsx": "react-native",
"lib": ["esnext"],
"lib": [
"esnext"
],
"moduleResolution": "node",
"noEmit": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"target": "esnext",
"typeRoots": ["./node_modules/@types"],
"typeRoots": [
"./node_modules/@types"
]
},
"include": ["./**.tsx"],
"include": [
"./**.tsx"
],
"extends": "expo/tsconfig.base"
}
Loading