Compare commits

..
Author SHA1 Message Date
Brad Bumbalough 64b8529472 chore: bump example to expo 48 2023-05-22 16:36:58 -05:00
dependabot[bot] a918aec770 chore(deps): bump minimatch from 3.0.4 to 3.1.2 (#305)
Bumps [minimatch](https://github.com/isaacs/minimatch) from 3.0.4 to 3.1.2.
- [Changelog](https://github.com/isaacs/minimatch/blob/main/changelog.md)
- [Commits](https://github.com/isaacs/minimatch/compare/v3.0.4...v3.1.2)

---
updated-dependencies:
- dependency-name: minimatch
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-09 22:20:53 -06:00
dependabot[bot] 93bc73bf22 chore(deps): bump minimatch from 3.0.4 to 3.1.2 in /example (#304)
Bumps [minimatch](https://github.com/isaacs/minimatch) from 3.0.4 to 3.1.2.
- [Changelog](https://github.com/isaacs/minimatch/blob/main/changelog.md)
- [Commits](https://github.com/isaacs/minimatch/compare/v3.0.4...v3.1.2)

---
updated-dependencies:
- dependency-name: minimatch
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-09 22:19:13 -06:00
dependabot[bot] d2d0843790 chore(deps): bump @xmldom/xmldom from 0.7.5 to 0.7.10 in /example (#303)
Bumps [@xmldom/xmldom](https://github.com/xmldom/xmldom) from 0.7.5 to 0.7.10.
- [Release notes](https://github.com/xmldom/xmldom/releases)
- [Changelog](https://github.com/xmldom/xmldom/blob/master/CHANGELOG.md)
- [Commits](https://github.com/xmldom/xmldom/compare/0.7.5...0.7.10)

---
updated-dependencies:
- dependency-name: "@xmldom/xmldom"
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-09 22:10:47 -06:00
dependabot[bot] 929a1dbc54 chore(deps): bump @sideway/formula from 3.0.0 to 3.0.1 in /example (#302)
Bumps [@sideway/formula](https://github.com/sideway/formula) from 3.0.0 to 3.0.1.
- [Commits](https://github.com/sideway/formula/compare/v3.0.0...v3.0.1)

---
updated-dependencies:
- dependency-name: "@sideway/formula"
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-09 22:10:33 -06:00
dependabot[bot] 0468951ed4 chore(deps): bump ua-parser-js from 0.7.28 to 0.7.33 (#294)
Bumps [ua-parser-js](https://github.com/faisalman/ua-parser-js) from 0.7.28 to 0.7.33.
- [Release notes](https://github.com/faisalman/ua-parser-js/releases)
- [Changelog](https://github.com/faisalman/ua-parser-js/blob/master/changelog.md)
- [Commits](https://github.com/faisalman/ua-parser-js/compare/0.7.28...0.7.33)

---
updated-dependencies:
- dependency-name: ua-parser-js
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-09 22:05:33 -06:00
dependabot[bot] c73938f4de chore(deps): bump ua-parser-js from 0.7.28 to 0.7.33 in /example (#293)
Bumps [ua-parser-js](https://github.com/faisalman/ua-parser-js) from 0.7.28 to 0.7.33.
- [Release notes](https://github.com/faisalman/ua-parser-js/releases)
- [Changelog](https://github.com/faisalman/ua-parser-js/blob/master/changelog.md)
- [Commits](https://github.com/faisalman/ua-parser-js/compare/0.7.28...0.7.33)

---
updated-dependencies:
- dependency-name: ua-parser-js
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-09 22:05:22 -06:00
dependabot[bot] aec473fb02 chore(deps): bump json5 from 1.0.1 to 1.0.2 (#290)
Bumps [json5](https://github.com/json5/json5) from 1.0.1 to 1.0.2.
- [Release notes](https://github.com/json5/json5/releases)
- [Changelog](https://github.com/json5/json5/blob/main/CHANGELOG.md)
- [Commits](https://github.com/json5/json5/compare/v1.0.1...v1.0.2)

---
updated-dependencies:
- dependency-name: json5
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-09 22:04:01 -06:00
dependabot[bot] 21d10edbd0 chore(deps): bump decode-uri-component from 0.2.0 to 0.2.2 in /example (#289)
Bumps [decode-uri-component](https://github.com/SamVerschueren/decode-uri-component) from 0.2.0 to 0.2.2.
- [Release notes](https://github.com/SamVerschueren/decode-uri-component/releases)
- [Commits](https://github.com/SamVerschueren/decode-uri-component/compare/v0.2.0...v0.2.2)

---
updated-dependencies:
- dependency-name: decode-uri-component
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-09 22:03:38 -06:00
dependabot[bot] ecb6b23caa chore(deps): bump decode-uri-component from 0.2.0 to 0.2.2 (#288)
Bumps [decode-uri-component](https://github.com/SamVerschueren/decode-uri-component) from 0.2.0 to 0.2.2.
- [Release notes](https://github.com/SamVerschueren/decode-uri-component/releases)
- [Commits](https://github.com/SamVerschueren/decode-uri-component/compare/v0.2.0...v0.2.2)

---
updated-dependencies:
- dependency-name: decode-uri-component
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-09 22:03:22 -06:00
dependabot[bot] 2f9346bcd7 chore(deps): bump shell-quote from 1.6.1 to 1.7.4 in /example (#284)
Bumps [shell-quote](https://github.com/ljharb/shell-quote) from 1.6.1 to 1.7.4.
- [Release notes](https://github.com/ljharb/shell-quote/releases)
- [Changelog](https://github.com/ljharb/shell-quote/blob/main/CHANGELOG.md)
- [Commits](https://github.com/ljharb/shell-quote/compare/1.6.1...v1.7.4)

---
updated-dependencies:
- dependency-name: shell-quote
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-09 22:03:04 -06:00
BradByte b35a403a21 fix: use release-please instead of semantic release (#300)
* fix: use release-please instead of semantic release

* chore: update ci steps
2023-05-09 22:01:20 -06:00
Eleftherios Myteletsis 3b698da831 chore: Update README.md (#291) 2023-01-18 08:36:30 -06:00
semantic-release-bot c583287d00 chore(release): 4.0.1 [skip ci]
## [4.0.1](https://github.com/expo/react-native-action-sheet/compare/v4.0.0...v4.0.1) (2022-11-04)

### Bug Fixes

* expose ref on ActionSheetProvider for statically invoking ([#283](https://github.com/expo/react-native-action-sheet/issues/283)) ([b2f5f43](https://github.com/expo/react-native-action-sheet/commit/b2f5f433ff2070c77fdd62b273d2d80e636efd3a))
2022-11-04 20:14:25 +00:00
BradByte b2f5f433ff fix: expose ref on ActionSheetProvider for statically invoking (#283)
This fixes an unknown breaking change from 4.0.0 where attempting to put a ref directly on `ActionSheetProvider` would error. For simplicity, the ref on that component will now return an object containing `showActionSheetWithOptions()`, but for backwards compatibility `getContext()` is also available.
2022-11-04 15:13:18 -05:00
semantic-release-bot fc9cefa2c1 chore(release): 4.0.0 [skip ci]
# [4.0.0](https://github.com/expo/react-native-action-sheet/compare/v3.14.0...v4.0.0) (2022-10-26)

### Features

* iOS use custom action sheet ([#281](https://github.com/expo/react-native-action-sheet/issues/281)) ([372dc80](https://github.com/expo/react-native-action-sheet/commit/372dc8065006a4da510ef5f31c27225d14a71ff3))

### BREAKING CHANGES

* This implementation is backwards compatible, but just to be safe I'm marking this as breaking so that it bumps the major version.
2022-10-26 17:39:06 +00:00
BradByte 372dc80650 feat: iOS use custom action sheet (#281)
BREAKING CHANGE: This implementation is backwards compatible, but just to be safe I'm marking this as breaking so that it bumps the major version.
2022-10-26 12:38:17 -05:00
BradByte 86fabab32b docs: add link to expo snack (#280) 2022-10-05 10:10:07 -05:00
BradByte b75a00a233 docs: update the docs, add better example, iOS props (#279) 2022-10-04 10:53:01 -05:00
semantic-release-bot 1df8d22613 chore(release): 3.14.0 [skip ci]
# [3.14.0](https://github.com/expo/react-native-action-sheet/compare/v3.13.1...v3.14.0) (2022-10-03)

### Features

* support cancelButtonTintColor ([#278](https://github.com/expo/react-native-action-sheet/issues/278)) ([2dcd54c](https://github.com/expo/react-native-action-sheet/commit/2dcd54c56f35a64c66f8d9a7d09a9475801cf037))
2022-10-03 19:40:24 +00:00
BradByte 2dcd54c56f feat: support cancelButtonTintColor (#278)
* feat: bump expo to sdk 46
* feat: add support for cancelButtonTintColor
2022-10-03 14:39:47 -05:00
16 changed files with 4647 additions and 4758 deletions

No files matched your search

+18 -10
View File
@@ -2,21 +2,29 @@ name: CI
on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v2
- name: 🗂️ Checkout
uses: actions/checkout@v3
- name: ⚙️ Setup Node
uses: actions/setup-node@v3
with:
node-version: '14'
cache: 'yarn'
- run: yarn install
- run: npm run type-check
- run: npm run lint-check
- name: 🧱 Build
run: yarn
- name: 🚧 Type Check
run: npm run type-check
- name: 🛟 Lint Check
run: npm run lint-check
+30 -14
View File
@@ -2,22 +2,38 @@ name: Release
on:
push:
branches: [ master ]
jobs:
release:
runs-on: ubuntu-latest
branches: [master]
jobs:
release-please:
runs-on: ubuntu-latest
outputs:
release-created: ${{ steps.release.outputs.release_created }}
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v2
- uses: google-github-actions/release-please-action@v3
id: release
with:
release-type: node
package-name: '@expo/react-native-action-sheet'
deploy:
needs: [release-please]
if: needs.release-please.outputs.release-created == 'true'
runs-on: ubuntu-latest
steps:
- name: 🗂️ Checkout
uses: actions/checkout@v3
- name: ⚙️ Setup Node
uses: actions/setup-node@v3
with:
node-version: '14'
cache: 'yarn'
- run: yarn install
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release
- name: 🧱 Build
run: yarn
- name: 🚀 Deploy
uses: JS-DevTools/npm-publish@v2
with:
token: ${{ secrets.NPM_TOKEN }}
+26
View File
@@ -1,5 +1,31 @@
# Changelog
## [4.0.1](https://github.com/expo/react-native-action-sheet/compare/v4.0.0...v4.0.1) (2022-11-04)
### Bug Fixes
* expose ref on ActionSheetProvider for statically invoking ([#283](https://github.com/expo/react-native-action-sheet/issues/283)) ([b2f5f43](https://github.com/expo/react-native-action-sheet/commit/b2f5f433ff2070c77fdd62b273d2d80e636efd3a))
# [4.0.0](https://github.com/expo/react-native-action-sheet/compare/v3.14.0...v4.0.0) (2022-10-26)
### Features
* iOS use custom action sheet ([#281](https://github.com/expo/react-native-action-sheet/issues/281)) ([372dc80](https://github.com/expo/react-native-action-sheet/commit/372dc8065006a4da510ef5f31c27225d14a71ff3))
### BREAKING CHANGES
* This implementation is backwards compatible, but just to be safe I'm marking this as breaking so that it bumps the major version.
# [3.14.0](https://github.com/expo/react-native-action-sheet/compare/v3.13.1...v3.14.0) (2022-10-03)
### Features
* support cancelButtonTintColor ([#278](https://github.com/expo/react-native-action-sheet/issues/278)) ([2dcd54c](https://github.com/expo/react-native-action-sheet/commit/2dcd54c56f35a64c66f8d9a7d09a9475801cf037))
## [3.13.1](https://github.com/expo/react-native-action-sheet/compare/v3.13.0...v3.13.1) (2022-10-03)
+107 -120
View File
@@ -1,92 +1,101 @@
# react-native-action-sheet
# @expo/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.
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 |
| -------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------- |
| <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"/> |
## [Check out the example snack here!](https://snack.expo.dev/@expo-action-sheet/example)
## Installation
```
$ npm install @expo/react-native-action-sheet -S
npm install @expo/react-native-action-sheet
```
or
```
$ yarn add @expo/react-native-action-sheet
yarn add @expo/react-native-action-sheet
```
## A basic ActionSheet Setup
### 1. Wrap your top-level component with `<ActionSheetProvider />`
```es6
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.
```jsx
import { ActionSheetProvider } from '@expo/react-native-action-sheet';
class AppContainer extends React.Component {
render() {
return (
<ActionSheetProvider>
<ConnectedApp />
</ActionSheetProvider>
);
}
export default function AppContainer() {
return (
<ActionSheetProvider>
<App />
</ActionSheetProvider>
);
}
```
### 2. Connect your component which uses showActionSheetWithOptions.
### 2. Call the `showActionSheetWithOptions` method with a hook or a higher order component.
```es6
import { connectActionSheet } from '@expo/react-native-action-sheet';
```tsx
// Using the provided hook
import { useActionSheet } from '@expo/react-native-action-sheet';
class App extends React.Component {
/* ... */
}
export default Menu() {
const { showActionSheetWithOptions } = useActionSheet();
const ConnectedApp = connectActionSheet(App);
const onPress = () => {
const options = ['Delete', 'Save', 'Cancel'];
const destructiveButtonIndex = 0;
const cancelButtonIndex = 2;
export default ConnectedApp;
```
`App` component can access the actionSheet method as `this.props.showActionSheetWithOptions`
```es6
_onOpenActionSheet = () => {
// Same interface as https://facebook.github.io/react-native/docs/actionsheetios.html
const options = ['Delete', 'Save', 'Cancel'];
const destructiveButtonIndex = 0;
const cancelButtonIndex = 2;
this.props.showActionSheetWithOptions(
{
showActionSheetWithOptions({
options,
cancelButtonIndex,
destructiveButtonIndex,
},
(buttonIndex) => {
// Do something here depending on the button index selected
}
);
destructiveButtonIndex
}, (selectedIndex: number) => {
switch (selectedIndex) {
case 1:
// Save
break;
case destructiveButtonIndex:
// Delete
break;
case cancelButtonIndex:
// Canceled
}});
}
return (
<Button title="Menu" onPress={onPress}/>
)
};
```
You can use a hook instead of the higher order component if you are on React 16.8 or newer.
Alternatively, any component can use the higher order component to access the context and pass the `showActionSheetWithOptions` as a prop.
```es6
import { useActionSheet } from '@expo/react-native-action-sheet';
```tsx
// Using a Higher Order Component to wrap your component
import { connectActionSheet } from '@expo/react-native-action-sheet';
export default function App() {
const { showActionSheetWithOptions } = useActionSheet();
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.
@@ -95,97 +104,75 @@ 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://reactnative.dev/docs/0.64/actionsheetios#showactionsheetwithoptions) component exist for both iOS and Android in this library. Note: `disabledButtonIndices` is only available for iOS in Expo 43+ or RN 0.64.0+.
| 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 | Required | Default |
| ------------------ | ------ | -------- | ------- |
| anchor | number | No | |
| userInterfaceStyle | string | No | |
| Name | Type | Description |
| -------------------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `anchor` | number | 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` | string | The interface style used for the action sheet, can be set to `light` or `dark`, otherwise the default system style will be used. |
#### `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
### 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 | 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.
#### `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.
| 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](https://github.com/expo/react-native-action-sheet/issues/164)). |
| `destructiveColor` | string | Modify color for text of destructive option. Defaults to `#d32f2f`. |
## ActionSheetProvider Props
The following props can be set directly on the `ActionSheetProvider`
#### `useNativeDriver` (optional)
| 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](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.
```jsx
// 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.
```tsx
function onButtonPress(selectedIndex: number) {
// handle it!
}
```
## Try it out
Try it in Expo: https://expo.io/@community/react-native-action-sheet-example
Try it in Expo Snack: https://snack.expo.dev/@expo-action-sheet/example.
## Example
+54 -10
View File
@@ -3,7 +3,9 @@ import {
connectActionSheet,
ActionSheetProps,
} from '@expo/react-native-action-sheet';
import { Entypo } from '@expo/vector-icons';
import * as React from 'react';
import { useState } from 'react';
import {
Modal,
StyleSheet,
@@ -13,11 +15,15 @@ import {
SafeAreaView,
TouchableOpacity,
Share,
Platform,
} from 'react-native';
import ShowActionSheetButton from './ShowActionSheetButton';
type Props = ActionSheetProps;
type Props = ActionSheetProps & {
useCustomActionSheet: boolean;
setUseCustomActionSheet: (next: boolean) => void;
};
interface State {
selectedIndex?: number | null;
@@ -77,6 +83,35 @@ class App extends React.Component<Props, State> {
style={{
alignItems: 'center',
}}>
<View
style={{
alignItems: 'center',
display: Platform.OS === 'ios' ? 'flex' : 'none',
}}>
{this._renderSectionHeader('Use Custom Action Sheet')}
<Text style={{ marginBottom: 10 }}>
On iOS the default action sheet will be the native UI. However, you can optionally
enable the custom JS action sheet by setting the useCustomActionSheet prop on the
provider.
</Text>
<Entypo.Button
backgroundColor={this.props.useCustomActionSheet ? '#3e3e3e' : 'white'}
name={this.props.useCustomActionSheet ? 'check' : 'circle'}
color={this.props.useCustomActionSheet ? '#fff' : '#3e3e3e'}
style={{
borderColor: '#3e3e3e',
borderWidth: 2,
}}
onPress={() => this.props.setUseCustomActionSheet(!this.props.useCustomActionSheet)}>
<Text
style={{
fontSize: 15,
color: this.props.useCustomActionSheet ? '#fff' : '#3e3e3e',
}}>
Use Custom Action Sheet
</Text>
</Entypo.Button>
</View>
{this._renderSectionHeader('Universal Options')}
<ShowActionSheetButton
title="Options Only"
@@ -96,6 +131,12 @@ class App extends React.Component<Props, State> {
onSelection={this._updateSelectionText}
showActionSheetWithOptions={showActionSheetWithOptions}
/>
<ShowActionSheetButton
title="Cancel Button Tint Color"
withCancelButtonTintColor
onSelection={this._updateSelectionText}
showActionSheetWithOptions={showActionSheetWithOptions}
/>
<ShowActionSheetButton
title="iPad Anchor"
withAnchor
@@ -211,16 +252,19 @@ class App extends React.Component<Props, State> {
}
}
const ConnectedApp = connectActionSheet<object>(App);
const ConnectedApp = connectActionSheet<any>(App);
export default class AppContainer extends React.Component {
render() {
return (
<ActionSheetProvider>
<ConnectedApp />
</ActionSheetProvider>
);
}
export default function WrappedApp() {
const [useCustomActionSheet, setUseCustomActionSheet] = useState(false);
return (
<ActionSheetProvider useCustomActionSheet={useCustomActionSheet}>
<ConnectedApp
useCustomActionSheet={useCustomActionSheet}
setUseCustomActionSheet={setUseCustomActionSheet}
/>
</ActionSheetProvider>
);
}
const styles = StyleSheet.create({
+4
View File
@@ -19,6 +19,7 @@ interface Props {
withIcons?: boolean;
withSeparators?: boolean;
withCustomStyles?: boolean;
withCancelButtonTintColor?: boolean;
withAnchor?: boolean;
useModal?: boolean;
}
@@ -32,6 +33,7 @@ export default class ShowActionSheetButton extends React.PureComponent<Props> {
withSeparators: false,
withCustomStyles: false,
withAnchor: false,
withCancelButtonTintColor: false,
onSelection: null,
useModal: false,
};
@@ -46,6 +48,7 @@ export default class ShowActionSheetButton extends React.PureComponent<Props> {
withIcons,
withSeparators,
withCustomStyles,
withCancelButtonTintColor,
onSelection,
showActionSheetWithOptions,
useModal,
@@ -98,6 +101,7 @@ export default class ShowActionSheetButton extends React.PureComponent<Props> {
{
options,
cancelButtonIndex,
cancelButtonTintColor: withCancelButtonTintColor ? '#D93F0B' : undefined,
destructiveButtonIndex,
disabledButtonIndices,
title,
+10 -10
View File
@@ -13,18 +13,18 @@
},
"dependencies": {
"@expo/react-native-action-sheet": "../src",
"@expo/vector-icons": "^12.0.0",
"expo": "^43.0.0-beta.3",
"@expo/vector-icons": "^13.0.0",
"expo": "^48.0.0",
"hoist-non-react-statics": "^3.3.0",
"react": "17.0.1",
"react-dom": "17.0.1",
"react-native": "0.64.2",
"react-native-web": "0.17.1"
"react": "18.2.0",
"react-dom": "18.2.0",
"react-native": "0.71.3",
"react-native-web": "~0.18.11"
},
"devDependencies": {
"@types/react": "~17.0.21",
"@types/react-native": "~0.64.12",
"babel-preset-expo": "8.5.1",
"typescript": "~4.3.5"
"@types/react": "~18.2.0",
"@types/react-native": "~0.71.3",
"babel-preset-expo": "^9.3.0",
"typescript": "^4.9.4"
}
}
+3924 -1760
View File
File diff suppressed because it is too large. Load diff
+1 -2
View File
@@ -1,6 +1,6 @@
{
"name": "@expo/react-native-action-sheet",
"version": "3.13.1",
"version": "4.0.1",
"description": "A cross-platform ActionSheet for React Native",
"react-native": "lib/module/index.js",
"types": "lib/typescript/index.d.ts",
@@ -45,7 +45,6 @@
"prettier": "^2.3.2",
"react": "^16.8.6",
"react-native": "https://github.com/expo/react-native/archive/sdk-33.0.0.tar.gz",
"semantic-release": "^19.0.3",
"typescript": "^3.5.3"
},
"peerDependencies": {
+8 -1
View File
@@ -119,6 +119,8 @@ export default class ActionGroup extends React.Component<Props> {
const {
options,
icons,
cancelButtonIndex,
cancelButtonTintColor,
destructiveButtonIndex,
disabledButtonIndices,
destructiveColor = DESTRUCTIVE_COLOR,
@@ -141,7 +143,12 @@ export default class ActionGroup extends React.Component<Props> {
? tintColor
: (textStyle || {}).color || BLACK_87PC_TRANSPARENT;
const disabled = isIndexDisabled(i, disabledButtonIndices);
const color = isIndexDestructive(i, destructiveButtonIndex) ? destructiveColor : defaultColor;
const isCancelButton = i === cancelButtonIndex;
const color = isIndexDestructive(i, destructiveButtonIndex)
? destructiveColor
: isCancelButton
? cancelButtonTintColor || defaultColor
: defaultColor;
const iconSource = icons != null ? icons[i] : null;
optionViews.push(
+333
View File
@@ -0,0 +1,333 @@
import * as React from 'react';
import {
Animated,
BackHandler,
Easing,
Modal,
Platform,
StyleSheet,
TouchableWithoutFeedback,
View,
ViewProps,
} from 'react-native';
import { ActionSheetOptions } from '../types';
import ActionGroup from './ActionGroup';
interface State {
isVisible: boolean;
isAnimating: boolean;
options: ActionSheetOptions | null;
onSelect: ((i: number) => void) | null;
overlayOpacity: any;
sheetOpacity: any;
}
export interface Props {
readonly children: React.ReactNode;
readonly useNativeDriver?: boolean;
readonly pointerEvents?: ViewProps['pointerEvents'];
}
const OPACITY_ANIMATION_IN_TIME = 225;
const OPACITY_ANIMATION_OUT_TIME = 195;
const EASING_OUT = Easing.bezier(0.25, 0.46, 0.45, 0.94);
const EASING_IN = Easing.out(EASING_OUT);
const ESCAPE_KEY = 'Escape';
// Has same API as https://facebook.github.io/react-native/docs/actionsheetios.html
export default class CustomActionSheet extends React.Component<Props, State> {
_actionSheetHeight = 360;
state: State = {
isVisible: false,
isAnimating: false,
options: null,
onSelect: null,
overlayOpacity: new Animated.Value(0),
sheetOpacity: new Animated.Value(0),
};
_deferAfterAnimation?: () => void = undefined;
componentDidMount() {
if (Platform.OS === 'web') {
document.addEventListener('keydown', this._handleWebKeyDown);
}
}
componentWillUnmount() {
if (Platform.OS === 'web') {
document.removeEventListener('keydown', this._handleWebKeyDown);
}
}
_handleWebKeyDown = (event: KeyboardEvent): void => {
if (event.key === ESCAPE_KEY && this.state.isVisible) {
event.preventDefault();
this._selectCancelButton();
}
};
_setActionSheetHeight = ({ nativeEvent }: any) =>
(this._actionSheetHeight = nativeEvent.layout.height);
render() {
const { isVisible, overlayOpacity, options } = this.state;
const useModal = options ? options.autoFocus || options.useModal === true : false;
const overlay = isVisible ? (
<Animated.View
style={[
styles.overlay,
{
opacity: overlayOpacity,
},
]}
/>
) : null;
// While the sheet is visible, hide the rest of the app's content from screen readers.
const appContent = (
<View
style={styles.flexContainer}
importantForAccessibility={isVisible ? 'no-hide-descendants' : 'auto'}>
{React.Children.only(this.props.children)}
</View>
);
return (
<View pointerEvents={this.props.pointerEvents} style={styles.flexContainer}>
{appContent}
{isVisible && !useModal && (
<>
{overlay}
{this._renderSheet()}
</>
)}
{isVisible && useModal && (
<Modal animationType="none" transparent onRequestClose={this._selectCancelButton}>
{overlay}
{this._renderSheet()}
</Modal>
)}
</View>
);
}
_renderSheet() {
const { options, isAnimating, sheetOpacity } = this.state;
if (!options) {
return null;
}
const {
options: optionsArray,
icons,
tintIcons,
destructiveButtonIndex,
disabledButtonIndices,
destructiveColor,
textStyle,
tintColor,
title,
titleTextStyle,
message,
messageTextStyle,
autoFocus,
showSeparators,
containerStyle,
separatorStyle,
cancelButtonIndex,
cancelButtonTintColor,
} = options;
return (
<TouchableWithoutFeedback importantForAccessibility="yes" onPress={this._selectCancelButton}>
<Animated.View
needsOffscreenAlphaCompositing={isAnimating}
style={[
styles.sheetContainer,
{
opacity: sheetOpacity,
transform: [
{
translateY: sheetOpacity.interpolate({
inputRange: [0, 1],
outputRange: [this._actionSheetHeight, 0],
}),
},
],
},
]}>
<View style={styles.sheet} onLayout={this._setActionSheetHeight}>
<ActionGroup
options={optionsArray}
icons={icons}
tintIcons={tintIcons === undefined ? true : tintIcons}
cancelButtonIndex={cancelButtonIndex}
cancelButtonTintColor={cancelButtonTintColor}
destructiveButtonIndex={destructiveButtonIndex}
destructiveColor={destructiveColor}
disabledButtonIndices={disabledButtonIndices}
onSelect={this._onSelect}
startIndex={0}
length={optionsArray.length}
textStyle={textStyle || {}}
tintColor={tintColor}
title={title || undefined}
titleTextStyle={titleTextStyle}
message={message || undefined}
messageTextStyle={messageTextStyle}
autoFocus={autoFocus}
showSeparators={showSeparators}
containerStyle={containerStyle}
separatorStyle={separatorStyle}
/>
</View>
</Animated.View>
</TouchableWithoutFeedback>
);
}
showActionSheetWithOptions = (options: ActionSheetOptions, onSelect: (i: number) => void) => {
const { isVisible, overlayOpacity, sheetOpacity } = this.state;
const { useNativeDriver = true } = this.props;
if (isVisible) {
this._deferAfterAnimation = this.showActionSheetWithOptions.bind(this, options, onSelect);
return;
}
this.setState({
options,
onSelect,
isVisible: true,
isAnimating: true,
});
overlayOpacity.setValue(0);
sheetOpacity.setValue(0);
Animated.parallel([
Animated.timing(overlayOpacity, {
toValue: 0.32,
easing: EASING_OUT,
duration: OPACITY_ANIMATION_IN_TIME,
useNativeDriver,
}),
Animated.timing(sheetOpacity, {
toValue: 1,
easing: EASING_OUT,
duration: OPACITY_ANIMATION_IN_TIME,
useNativeDriver,
}),
]).start((result) => {
if (result.finished) {
this.setState({
isAnimating: false,
});
this._deferAfterAnimation = undefined;
}
});
// @ts-ignore: Argument of type '"actionSheetHardwareBackPress"' is not assignable to parameter of type '"hardwareBackPress"'
BackHandler.addEventListener('actionSheetHardwareBackPress', this._selectCancelButton);
};
_selectCancelButton = () => {
const { options } = this.state;
if (!options) {
return false;
}
if (typeof options.cancelButtonIndex === 'undefined') {
return false;
} else if (typeof options.cancelButtonIndex === 'number') {
return this._onSelect(options.cancelButtonIndex);
} else {
return this._animateOut();
}
};
_onSelect = (index: number): boolean => {
const { isAnimating, onSelect } = this.state;
if (isAnimating) {
return false;
}
if (onSelect) {
this._deferAfterAnimation = onSelect.bind(this, index);
}
return this._animateOut();
};
_animateOut = (): boolean => {
const { isAnimating, overlayOpacity, sheetOpacity } = this.state;
const { useNativeDriver = true } = this.props;
if (isAnimating) {
return false;
}
// @ts-ignore: Argument of type '"actionSheetHardwareBackPress"' is not assignable to parameter of type '"hardwareBackPress"'
BackHandler.removeEventListener('actionSheetHardwareBackPress', this._selectCancelButton);
this.setState({
isAnimating: true,
});
Animated.parallel([
Animated.timing(overlayOpacity, {
toValue: 0,
easing: EASING_IN,
duration: OPACITY_ANIMATION_OUT_TIME,
useNativeDriver,
}),
Animated.timing(sheetOpacity, {
toValue: 0,
easing: EASING_IN,
duration: OPACITY_ANIMATION_OUT_TIME,
useNativeDriver,
}),
]).start((result) => {
if (result.finished) {
this.setState({
isVisible: false,
isAnimating: false,
});
if (this._deferAfterAnimation) {
this._deferAfterAnimation();
}
}
});
return true;
};
}
const styles = StyleSheet.create({
flexContainer: {
flex: 1,
},
overlay: {
position: 'absolute',
top: 0,
right: 0,
bottom: 0,
left: 0,
backgroundColor: 'black',
},
sheetContainer: {
position: 'absolute',
left: 0,
right: 0,
bottom: 0,
top: 0,
backgroundColor: 'transparent',
alignItems: 'flex-end',
justifyContent: 'center',
flexDirection: 'row',
},
sheet: {
flex: 1,
backgroundColor: 'transparent',
},
});
+9 -2
View File
@@ -21,13 +21,20 @@ export default class ActionSheet extends React.Component<Props> {
showActionSheetWithOptions(dataOptions: ActionSheetIOSOptions, onSelect: onSelect) {
// ...dataOptions include other keys which use in android and web, thats why `Android-Only options` Crash on IOS
const { cancelButtonIndex, destructiveButtonIndex, options, tintColor, disabledButtonIndices } =
dataOptions;
const {
cancelButtonIndex,
destructiveButtonIndex,
options,
tintColor,
cancelButtonTintColor,
disabledButtonIndices,
} = dataOptions;
const iosOptions: ActionSheetIOSOptions = {
cancelButtonIndex,
destructiveButtonIndex,
options,
tintColor,
cancelButtonTintColor,
disabledButtonIndices,
// A null title or message on iOS causes a crash
title: dataOptions.title || undefined,
+2 -330
View File
@@ -1,330 +1,2 @@
import * as React from 'react';
import {
Animated,
BackHandler,
Easing,
Modal,
Platform,
StyleSheet,
TouchableWithoutFeedback,
View,
ViewProps,
} from 'react-native';
import { ActionSheetOptions } from '../types';
import ActionGroup from './ActionGroup';
interface State {
isVisible: boolean;
isAnimating: boolean;
options: ActionSheetOptions | null;
onSelect: ((i: number) => void) | null;
overlayOpacity: any;
sheetOpacity: any;
}
interface Props {
readonly useNativeDriver: boolean | undefined;
readonly pointerEvents?: ViewProps['pointerEvents'];
}
const OPACITY_ANIMATION_IN_TIME = 225;
const OPACITY_ANIMATION_OUT_TIME = 195;
const EASING_OUT = Easing.bezier(0.25, 0.46, 0.45, 0.94);
const EASING_IN = Easing.out(EASING_OUT);
const ESCAPE_KEY = 'Escape';
// Has same API as https://facebook.github.io/react-native/docs/actionsheetios.html
export default class ActionSheet extends React.Component<Props, State> {
static defaultProps = {
useNativeDriver: true,
};
_actionSheetHeight = 360;
state: State = {
isVisible: false,
isAnimating: false,
options: null,
onSelect: null,
overlayOpacity: new Animated.Value(0),
sheetOpacity: new Animated.Value(0),
};
_deferAfterAnimation?: () => void = undefined;
componentDidMount() {
if (Platform.OS === 'web') {
document.addEventListener('keydown', this._handleWebKeyDown);
}
}
componentWillUnmount() {
if (Platform.OS === 'web') {
document.removeEventListener('keydown', this._handleWebKeyDown);
}
}
_handleWebKeyDown = (event: KeyboardEvent): void => {
if (event.key === ESCAPE_KEY && this.state.isVisible) {
event.preventDefault();
this._selectCancelButton();
}
};
_setActionSheetHeight = ({ nativeEvent }: any) =>
(this._actionSheetHeight = nativeEvent.layout.height);
render() {
const { isVisible, overlayOpacity, options } = this.state;
const useModal = options ? options.autoFocus || options.useModal === true : false;
const overlay = isVisible ? (
<Animated.View
style={[
styles.overlay,
{
opacity: overlayOpacity,
},
]}
/>
) : null;
// While the sheet is visible, hide the rest of the app's content from screen readers.
const appContent = (
<View
style={styles.flexContainer}
importantForAccessibility={isVisible ? 'no-hide-descendants' : 'auto'}>
{React.Children.only(this.props.children)}
</View>
);
return (
<View pointerEvents={this.props.pointerEvents} style={styles.flexContainer}>
{appContent}
{isVisible && !useModal && (
<>
{overlay}
{this._renderSheet()}
</>
)}
{isVisible && useModal && (
<Modal animationType="none" transparent onRequestClose={this._selectCancelButton}>
{overlay}
{this._renderSheet()}
</Modal>
)}
</View>
);
}
_renderSheet() {
const { options, isAnimating, sheetOpacity } = this.state;
if (!options) {
return null;
}
const {
options: optionsArray,
icons,
tintIcons,
destructiveButtonIndex,
disabledButtonIndices,
destructiveColor,
textStyle,
tintColor,
title,
titleTextStyle,
message,
messageTextStyle,
autoFocus,
showSeparators,
containerStyle,
separatorStyle,
} = options;
return (
<TouchableWithoutFeedback importantForAccessibility="yes" onPress={this._selectCancelButton}>
<Animated.View
needsOffscreenAlphaCompositing={isAnimating}
style={[
styles.sheetContainer,
{
opacity: sheetOpacity,
transform: [
{
translateY: sheetOpacity.interpolate({
inputRange: [0, 1],
outputRange: [this._actionSheetHeight, 0],
}),
},
],
},
]}>
<View style={styles.sheet} onLayout={this._setActionSheetHeight}>
<ActionGroup
options={optionsArray}
icons={icons}
tintIcons={tintIcons === undefined ? true : tintIcons}
destructiveButtonIndex={destructiveButtonIndex}
destructiveColor={destructiveColor}
disabledButtonIndices={disabledButtonIndices}
onSelect={this._onSelect}
startIndex={0}
length={optionsArray.length}
textStyle={textStyle || {}}
tintColor={tintColor}
title={title || undefined}
titleTextStyle={titleTextStyle}
message={message || undefined}
messageTextStyle={messageTextStyle}
autoFocus={autoFocus}
showSeparators={showSeparators}
containerStyle={containerStyle}
separatorStyle={separatorStyle}
/>
</View>
</Animated.View>
</TouchableWithoutFeedback>
);
}
showActionSheetWithOptions = (options: ActionSheetOptions, onSelect: (i: number) => void) => {
const { isVisible, overlayOpacity, sheetOpacity } = this.state;
if (isVisible) {
this._deferAfterAnimation = this.showActionSheetWithOptions.bind(this, options, onSelect);
return;
}
this.setState({
options,
onSelect,
isVisible: true,
isAnimating: true,
});
overlayOpacity.setValue(0);
sheetOpacity.setValue(0);
Animated.parallel([
Animated.timing(overlayOpacity, {
toValue: 0.32,
easing: EASING_OUT,
duration: OPACITY_ANIMATION_IN_TIME,
useNativeDriver: this.props.useNativeDriver,
}),
Animated.timing(sheetOpacity, {
toValue: 1,
easing: EASING_OUT,
duration: OPACITY_ANIMATION_IN_TIME,
useNativeDriver: this.props.useNativeDriver,
}),
]).start((result) => {
if (result.finished) {
this.setState({
isAnimating: false,
});
this._deferAfterAnimation = undefined;
}
});
// @ts-ignore: Argument of type '"actionSheetHardwareBackPress"' is not assignable to parameter of type '"hardwareBackPress"'
BackHandler.addEventListener('actionSheetHardwareBackPress', this._selectCancelButton);
};
_selectCancelButton = () => {
const { options } = this.state;
if (!options) {
return false;
}
if (typeof options.cancelButtonIndex === 'undefined') {
return false;
} else if (typeof options.cancelButtonIndex === 'number') {
return this._onSelect(options.cancelButtonIndex);
} else {
return this._animateOut();
}
};
_onSelect = (index: number): boolean => {
const { isAnimating, onSelect } = this.state;
if (isAnimating) {
return false;
}
if (onSelect) {
this._deferAfterAnimation = onSelect.bind(this, index);
}
return this._animateOut();
};
_animateOut = (): boolean => {
const { isAnimating, overlayOpacity, sheetOpacity } = this.state;
if (isAnimating) {
return false;
}
// @ts-ignore: Argument of type '"actionSheetHardwareBackPress"' is not assignable to parameter of type '"hardwareBackPress"'
BackHandler.removeEventListener('actionSheetHardwareBackPress', this._selectCancelButton);
this.setState({
isAnimating: true,
});
Animated.parallel([
Animated.timing(overlayOpacity, {
toValue: 0,
easing: EASING_IN,
duration: OPACITY_ANIMATION_OUT_TIME,
useNativeDriver: this.props.useNativeDriver,
}),
Animated.timing(sheetOpacity, {
toValue: 0,
easing: EASING_IN,
duration: OPACITY_ANIMATION_OUT_TIME,
useNativeDriver: this.props.useNativeDriver,
}),
]).start((result) => {
if (result.finished) {
this.setState({
isVisible: false,
isAnimating: false,
});
if (this._deferAfterAnimation) {
this._deferAfterAnimation();
}
}
});
return true;
};
}
const styles = StyleSheet.create({
flexContainer: {
flex: 1,
},
overlay: {
position: 'absolute',
top: 0,
right: 0,
bottom: 0,
left: 0,
backgroundColor: 'black',
},
sheetContainer: {
position: 'absolute',
left: 0,
right: 0,
bottom: 0,
top: 0,
backgroundColor: 'transparent',
alignItems: 'flex-end',
justifyContent: 'center',
flexDirection: 'row',
},
sheet: {
flex: 1,
backgroundColor: 'transparent',
},
});
import CustomActionSheet from './CustomActionSheet';
export default CustomActionSheet;
+39 -26
View File
@@ -1,41 +1,54 @@
import * as React from 'react';
import ActionSheet from './ActionSheet';
// NativeActionSheet will always be custom when on Android/web
import NativeActionSheet from './ActionSheet';
import CustomActionSheet from './ActionSheet/CustomActionSheet';
import { Provider } from './context';
import { ActionSheetOptions, ActionSheetProps } from './types';
import { ActionSheetOptions, ActionSheetProviderRef } from './types';
interface Props {
children: React.ReactNode;
useNativeDriver?: boolean;
useCustomActionSheet?: boolean;
}
export default class ActionSheetProvider extends React.Component<Props> {
_actionSheetRef: React.RefObject<ActionSheet>;
_context: ActionSheetProps;
export default React.forwardRef<ActionSheetProviderRef, Props>(function ActionSheetProvider(
{ children, useNativeDriver, useCustomActionSheet = false },
ref
) {
const actionSheetRef = React.useRef<NativeActionSheet>(null);
constructor(props: Props) {
super(props);
this._actionSheetRef = React.createRef();
this._context = {
const context = React.useMemo(
() => ({
showActionSheetWithOptions: (options: ActionSheetOptions, callback: (i: number) => void) => {
if (this._actionSheetRef.current != null) {
this._actionSheetRef.current.showActionSheetWithOptions(options, callback);
if (actionSheetRef.current) {
actionSheetRef.current.showActionSheetWithOptions(options, callback);
}
},
};
}
}),
[actionSheetRef]
);
getContext(): ActionSheetProps {
return this._context;
}
React.useImperativeHandle(
ref,
() => ({
// backwards compatible with 13.x before context was being passed right on the ref
getContext: () => context,
showActionSheetWithOptions: context.showActionSheetWithOptions,
}),
[context]
);
render() {
return (
<Provider value={this._context}>
<ActionSheet ref={this._actionSheetRef} useNativeDriver={this.props.useNativeDriver}>
{React.Children.only(this.props.children)}
</ActionSheet>
</Provider>
);
}
}
const ActionSheet = React.useMemo(
() => (useCustomActionSheet ? CustomActionSheet : NativeActionSheet),
[useCustomActionSheet]
);
return (
<Provider value={context}>
<ActionSheet ref={actionSheetRef} useNativeDriver={useNativeDriver}>
{React.Children.only(children)}
</ActionSheet>
</Provider>
);
});
+8
View File
@@ -8,6 +8,13 @@ export interface ActionSheetProps {
) => void;
}
export interface ActionSheetProviderRef extends ActionSheetProps {
/**
* @deprecated Simply call `showActionSheetWithOptions()` directly from the ref now
*/
getContext: () => ActionSheetProps;
}
// for iOS
export interface ActionSheetIOSOptions {
options: string[];
@@ -15,6 +22,7 @@ export interface ActionSheetIOSOptions {
message?: string;
tintColor?: string;
cancelButtonIndex?: number;
cancelButtonTintColor?: string;
destructiveButtonIndex?: number | number[];
anchor?: number;
userInterfaceStyle?: 'light' | 'dark';
+74 -2473
View File
File diff suppressed because it is too large. Load diff