mirror of
https://github.com/expo/react-native-action-sheet.git
synced 2026-11-14 19:11:42 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6244df4549 | ||
|
|
f46a5cfc47 | ||
|
|
9c6f5be31d | ||
|
|
0147d326f9 | ||
|
|
47a1711c3c | ||
|
|
758050480d | ||
|
|
e4f4246880 | ||
|
|
da6105e8a0 | ||
|
|
3822febbf8 | ||
|
|
8999650323 | ||
|
|
6e22c372d3 | ||
|
|
02b2db8947 | ||
|
|
880fe21224 | ||
|
|
df363ead72 | ||
|
|
9ea2d088e6 | ||
|
|
0f534dc1f5 | ||
|
|
55005ba0fb | ||
|
|
bd0c001215 | ||
|
|
c4c3f8b873 | ||
|
|
1fb3411f57 | ||
|
|
2f43b7e956 | ||
|
|
feed1f78b4 | ||
|
|
a561f34cda | ||
|
|
c6cc00fdc5 | ||
|
|
c237838c63 | ||
|
|
d735b696ab | ||
|
|
7736e0e162 | ||
|
|
b54b9f16c2 | ||
|
|
4d8ed00b66 | ||
|
|
22fc2144b3 | ||
|
|
224d992a53 | ||
|
|
688fd47227 | ||
|
|
e2e141bf53 | ||
|
|
be3425a4fd | ||
|
|
7a388210b1 | ||
|
|
d3fe451642 | ||
|
|
682e46136f | ||
|
|
0e5559fb45 | ||
|
|
f9ac44a6cb | ||
|
|
d31681dfea | ||
|
|
8a1659d71d | ||
|
|
fd731f0867 | ||
|
|
4dc8fcf7b2 | ||
|
|
81112b9553 | ||
|
|
f0b38daaac | ||
|
|
bb7c00fb72 | ||
|
|
7c757ac7e5 | ||
|
|
51cd2d1009 | ||
|
|
97505a2041 | ||
|
|
0a5821e1a3 | ||
|
|
c465495515 | ||
|
|
51efe1c0e5 | ||
|
|
b1cbd92a2a | ||
|
|
00a3e8354a | ||
|
|
af226d6aa0 | ||
|
|
f9a8e47b49 | ||
|
|
4af170533f | ||
|
|
735cfa54ba | ||
|
|
1af3809e07 | ||
|
|
d76a61f593 | ||
|
|
3ef49be264 | ||
|
|
18e63e275d | ||
|
|
d48c323e45 | ||
|
|
d0d5182780 | ||
|
|
eb30b1ed14 | ||
|
|
f509356bdd | ||
|
|
86007a32a0 | ||
|
|
76da5f5fe5 | ||
|
|
e1bd0b0415 | ||
|
|
d0cf2b8c8d | ||
|
|
5549e36a92 | ||
|
|
b605fb8a3b | ||
|
|
b95117a8cd | ||
|
|
9ed955dbba | ||
|
|
d85c167b55 | ||
|
|
128a48f2ff | ||
|
|
fe8c66dd0b | ||
|
|
bc3c27d767 | ||
|
|
33c7d9301c | ||
|
|
b20bf029ee | ||
|
|
37156dacf1 | ||
|
|
0d98570861 | ||
|
|
6fe293d4e2 | ||
|
|
ead0ed7dc1 | ||
|
|
27cef1a658 | ||
|
|
bfae6b4ebc | ||
|
|
eecc79ffb0 | ||
|
|
370e6e855f | ||
|
|
6fa494f9de | ||
|
|
fc86afb87e | ||
|
|
40aee02227 | ||
|
|
ac6f9f6ccd | ||
|
|
0131ebbb44 | ||
|
|
0627e77fba | ||
|
|
d114cfb321 | ||
|
|
8016008781 | ||
|
|
39fc431c97 | ||
|
|
76397fa7c4 | ||
|
|
8448370658 | ||
|
|
223d35fb85 | ||
|
|
979da65d59 | ||
|
|
b4f1ae39f9 | ||
|
|
817582e054 | ||
|
|
1a34e86f43 | ||
|
|
e571b97653 | ||
|
|
a4e11daeec | ||
|
|
08a929d477 | ||
|
|
cd966b48ad | ||
|
|
3fc5e9f478 |
No files matched your search
+1
-2
@@ -1,5 +1,4 @@
|
||||
node_modules
|
||||
exmaple/node_modules
|
||||
|
||||
# generated by bob
|
||||
lib/
|
||||
lib/
|
||||
+1
-12
@@ -1,14 +1,3 @@
|
||||
module.exports = {
|
||||
extends: [
|
||||
'@react-native-community',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'prettier/@typescript-eslint',
|
||||
],
|
||||
rules: {
|
||||
// Turn off rules which are useless and annoying for this project
|
||||
'@typescript-eslint/explicit-function-return-type': 'off',
|
||||
'@typescript-eslint/explicit-member-accessibility': 'off',
|
||||
'@typescript-eslint/no-use-before-define': 'off',
|
||||
'react-native/no-inline-styles': 'off',
|
||||
},
|
||||
extends: ['universe/native', 'universe/web'],
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '14'
|
||||
cache: 'yarn'
|
||||
- run: yarn install
|
||||
- run: npm run type-check
|
||||
- run: npm run lint-check
|
||||
@@ -0,0 +1,23 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@v2
|
||||
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
|
||||
+1
-2
@@ -1,5 +1,4 @@
|
||||
node_modules
|
||||
example/node_modules
|
||||
|
||||
# generated by bob
|
||||
lib/
|
||||
lib/
|
||||
+1
-1
@@ -2,6 +2,6 @@
|
||||
"printWidth": 100,
|
||||
"tabWidth": 2,
|
||||
"singleQuote": true,
|
||||
"jsxBracketSameLine": true,
|
||||
"bracketSameLine": true,
|
||||
"trailingComma": "es5"
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"plugins": [
|
||||
"@semantic-release/commit-analyzer",
|
||||
"@semantic-release/release-notes-generator",
|
||||
[
|
||||
"@semantic-release/changelog",
|
||||
{
|
||||
"changelogFile": "CHANGELOG.md",
|
||||
"changelogTitle": "# Changelog"
|
||||
}
|
||||
],
|
||||
"@semantic-release/npm",
|
||||
[
|
||||
"@semantic-release/git",
|
||||
{
|
||||
"assets": [
|
||||
"CHANGELOG.md",
|
||||
"package.json"
|
||||
]
|
||||
}
|
||||
],
|
||||
"@semantic-release/github"
|
||||
]
|
||||
}
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
# Changelog
|
||||
|
||||
## [3.13.1](https://github.com/expo/react-native-action-sheet/compare/v3.13.0...v3.13.1) (2022-10-03)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* add return type to connectActionSheet ([#273](https://github.com/expo/react-native-action-sheet/issues/273)) ([f46a5cf](https://github.com/expo/react-native-action-sheet/commit/f46a5cfc473807478c558a733c8adb1440941017))
|
||||
|
||||
# [3.13.0](https://github.com/expo/react-native-action-sheet/compare/v3.12.0...v3.13.0) (2022-01-10)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* defer calling onSelect until after animation ([#248](https://github.com/expo/react-native-action-sheet/issues/248)) ([1fb3411](https://github.com/expo/react-native-action-sheet/commit/1fb3411f575b4fa1cb762a804fc38cf3e2a5c73b)), closes [#203](https://github.com/expo/react-native-action-sheet/issues/203)
|
||||
* stabilize the identity of the context provider value ([#251](https://github.com/expo/react-native-action-sheet/issues/251)) ([55005ba](https://github.com/expo/react-native-action-sheet/commit/55005ba0fb4bc6aff546390cf324619bf2e0ed2a))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* support closing actionsheet with Esc key on web ([#247](https://github.com/expo/react-native-action-sheet/issues/247)) ([c4c3f8b](https://github.com/expo/react-native-action-sheet/commit/c4c3f8b873d76ff40daf8d2061d9f43346a3577f)), closes [#194](https://github.com/expo/react-native-action-sheet/issues/194)
|
||||
|
||||
# [3.12.0](https://github.com/expo/react-native-action-sheet/compare/v3.11.0...v3.12.0) (2021-10-14)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* use correct callback type allowing for undefined `i` ([#239](https://github.com/expo/react-native-action-sheet/issues/239)) ([b54b9f1](https://github.com/expo/react-native-action-sheet/commit/b54b9f16c251cb2ca5f1bd41ca7cc41b1393c6b3))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* adds support for disabledButtonIndices ([#246](https://github.com/expo/react-native-action-sheet/issues/246)) ([feed1f7](https://github.com/expo/react-native-action-sheet/commit/feed1f78b4c85855d48c1742fe9f8a67c0604609)), closes [#224](https://github.com/expo/react-native-action-sheet/issues/224)
|
||||
|
||||
# [3.11.0](https://github.com/expo/react-native-action-sheet/compare/v3.10.0...v3.11.0) (2021-09-07)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* yarn lock issues ([#238](https://github.com/expo/react-native-action-sheet/issues/238)) ([22fc214](https://github.com/expo/react-native-action-sheet/commit/22fc2144b3ce3b5fc1892eefd86f484dc1af58e9))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* default useModal to true when autoFocus is set ([688fd47](https://github.com/expo/react-native-action-sheet/commit/688fd47227dab6994b59ed85af622cb04ebed220))
|
||||
|
||||
# [3.10.0](https://github.com/expo/react-native-action-sheet/compare/v3.8.0...v3.10.0) (2021-08-09)
|
||||
|
||||
### Features
|
||||
* Allow multiple destructive indices ([#210](https://github.com/expo/react-native-action-sheet/issues/210)) ([81112b9](https://github.com/expo/react-native-action-sheet/commit/81112b9553dc34725e2708b02b64b7a5e5c57509))
|
||||
|
||||
# [3.9.0](https://github.com/expo/react-native-action-sheet/compare/v3.8.0...v3.9.0) (2021-03-12)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* allow callback to be async ([#183](https://github.com/expo/react-native-action-sheet/issues/183)) ([d0d5182](https://github.com/expo/react-native-action-sheet/commit/d0d518278028556a80deec3d9b57c332b82ba28d))
|
||||
* center icons with titles ([#188](https://github.com/expo/react-native-action-sheet/issues/188)) ([d48c323](https://github.com/expo/react-native-action-sheet/commit/d48c323e4563363c8683c427d1803e1ff4cddcb5))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add `userInterfaceStyle` option for iOS ([#206](https://github.com/expo/react-native-action-sheet/issues/206)) ([735cfa5](https://github.com/expo/react-native-action-sheet/commit/735cfa54ba1bfd90139671489aca525fdbd59626))
|
||||
|
||||
# [3.8.0](https://github.com/expo/react-native-action-sheet/compare/v3.7.0...v3.8.0) (2020-05-19)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Add destructiveColor option ([#171](https://github.com/expo/react-native-action-sheet/issues/171)) ([5549e36](https://github.com/expo/react-native-action-sheet/commit/5549e36a92d8afcc0ce2bf6a601e83209b5ce080))
|
||||
* Improvements to Android accessibility ([#168](https://github.com/expo/react-native-action-sheet/issues/168)) ([b605fb8](https://github.com/expo/react-native-action-sheet/commit/b605fb8a3b6421c244f7f18d934bb5ea0753d461))
|
||||
|
||||
# [3.7.0](https://github.com/expo/react-native-action-sheet/compare/v3.6.0...v3.7.0) (2020-05-06)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* adds `useModal` prop wrap action sheet in a modal ([9ed955d](https://github.com/expo/react-native-action-sheet/commit/9ed955dbba7259cbcf5e31ef3d4ed091ae4a3145)), closes [#169](https://github.com/expo/react-native-action-sheet/issues/169)
|
||||
|
||||
# [3.6.0](https://github.com/expo/react-native-action-sheet/compare/v3.5.0...v3.6.0) (2020-03-30)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Android 'Super expression must either be null or a function' ([37156da](https://github.com/expo/react-native-action-sheet/commit/37156dacf114aa5146da153db9ee00c1aea8eaca))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Add accessibility label to Action options ([#158](https://github.com/expo/react-native-action-sheet/issues/158)) ([bc3c27d](https://github.com/expo/react-native-action-sheet/commit/bc3c27d767a5657032b73f70aa1aacfea0481f66))
|
||||
|
||||
# [3.5.0](https://github.com/expo/react-native-action-sheet/compare/v3.4.1...v3.5.0) (2020-02-04)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add anchor option for iPads ([#155](https://github.com/expo/react-native-action-sheet/issues/155)) ([370e6e8](https://github.com/expo/react-native-action-sheet/commit/370e6e855fbacbfc683cc6ab16304f26c159e6b5))
|
||||
|
||||
## [3.4.1](https://github.com/expo/react-native-action-sheet/compare/v3.4.0...v3.4.1) (2019-12-13)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **iOS:** crash when using Android only options ([#144](https://github.com/expo/react-native-action-sheet/issues/144)) ([8016008](https://github.com/expo/react-native-action-sheet/commit/8016008781cbe418dc03f04a324d5e5ef5bcdaa7))
|
||||
|
||||
# [3.4.0](https://github.com/expo/react-native-action-sheet/compare/v3.3.2...v3.4.0) (2019-11-19)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **android:** allow customizing container styles ([#142](https://github.com/expo/react-native-action-sheet/issues/142)) ([39fc431](https://github.com/expo/react-native-action-sheet/commit/39fc431c97cb0ec03ab2a8386bd1b836d9f1cd2f))
|
||||
* Allow pointerEvents prop to pass through to containing view ([#124](https://github.com/expo/react-native-action-sheet/issues/124)) ([76397fa](https://github.com/expo/react-native-action-sheet/commit/76397fa7c4bff7318780ac72600156d753fad3f0))
|
||||
@@ -1,39 +1,57 @@
|
||||
# react-native-action-sheet
|
||||
|
||||
[](https://www.npmjs.com/package/@expo/react-native-action-sheet)
|
||||
[](https://opensource.org/licenses/MIT)
|
||||
[](https://slack.expo.io)
|
||||
[](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
|
||||
```
|
||||
|
||||
## A basic ActionSheet Setup
|
||||
|
||||
### 1. Connect your component which uses showActionSheetWithOptions.
|
||||
### 1. Wrap your top-level component with `<ActionSheetProvider />`
|
||||
|
||||
```es6
|
||||
import { connectActionSheet } from '@expo/react-native-action-sheet'
|
||||
import { ActionSheetProvider } from '@expo/react-native-action-sheet';
|
||||
|
||||
class AppContainer extends React.Component {
|
||||
render() {
|
||||
return (
|
||||
<ActionSheetProvider>
|
||||
<ConnectedApp />
|
||||
</ActionSheetProvider>
|
||||
);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 2. Connect your component which uses showActionSheetWithOptions.
|
||||
|
||||
```es6
|
||||
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`
|
||||
@@ -51,9 +69,9 @@ _onOpenActionSheet = () => {
|
||||
cancelButtonIndex,
|
||||
destructiveButtonIndex,
|
||||
},
|
||||
buttonIndex => {
|
||||
(buttonIndex) => {
|
||||
// Do something here depending on the button index selected
|
||||
},
|
||||
}
|
||||
);
|
||||
};
|
||||
```
|
||||
@@ -61,78 +79,110 @@ _onOpenActionSheet = () => {
|
||||
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();
|
||||
/* ... */
|
||||
}
|
||||
```
|
||||
|
||||
### 2. Wrap your top-level component with `<ActionSheetProvider />`
|
||||
|
||||
```es6
|
||||
|
||||
import { ActionSheetProvider } from '@expo/react-native-action-sheet'
|
||||
|
||||
class AppContainer extends React.Component {
|
||||
render() {
|
||||
return (
|
||||
<ActionSheetProvider>
|
||||
<ConnectedApp />
|
||||
</ActionSheetProvider>
|
||||
);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 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 with on web with Expo.
|
||||
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: `disabledButtonIndices` 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 | |
|
||||
| showSeparators | boolean | No | false |
|
||||
| separatorStyle | ViewStyle | No | |
|
||||
| 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.
|
||||
|
||||
## Try it out
|
||||
|
||||
Try it in Expo: https://expo.io/@community/react-native-action-sheet-example
|
||||
@@ -142,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
|
||||
@@ -157,6 +208,7 @@ $ yarn web
|
||||
## Development
|
||||
|
||||
### Setup
|
||||
|
||||
```
|
||||
$ git clone [email protected]:expo/react-native-action-sheet.git
|
||||
$ cd react-native-action-sheet
|
||||
@@ -164,19 +216,19 @@ $ yarn
|
||||
```
|
||||
|
||||
### Build
|
||||
|
||||
We use [bob](https://github.com/react-native-community/bob).
|
||||
|
||||
```
|
||||
$ yarn build
|
||||
```
|
||||
|
||||
### Lint & Format
|
||||
|
||||
```
|
||||
// tsc
|
||||
$ yarn type-check
|
||||
|
||||
// ESLint
|
||||
// ESLint + Prettier
|
||||
$ yarn lint
|
||||
|
||||
// prettier
|
||||
$ yarn fmt
|
||||
```
|
||||
+105
-10
@@ -1,26 +1,36 @@
|
||||
import * as React from 'react';
|
||||
import { StyleSheet, Text, View, ScrollView, SafeAreaView } from 'react-native';
|
||||
import {
|
||||
ActionSheetProvider,
|
||||
connectActionSheet,
|
||||
ActionSheetOptions,
|
||||
ActionSheetProps,
|
||||
} from '@expo/react-native-action-sheet';
|
||||
import * as React from 'react';
|
||||
import {
|
||||
Modal,
|
||||
StyleSheet,
|
||||
Text,
|
||||
View,
|
||||
ScrollView,
|
||||
SafeAreaView,
|
||||
TouchableOpacity,
|
||||
Share,
|
||||
} from 'react-native';
|
||||
|
||||
import ShowActionSheetButton from './ShowActionSheetButton';
|
||||
|
||||
interface Props {
|
||||
showActionSheetWithOptions: (options: ActionSheetOptions, callback: (i: number) => void) => void;
|
||||
}
|
||||
type Props = ActionSheetProps;
|
||||
|
||||
interface State {
|
||||
selectedIndex: number | null;
|
||||
selectedIndex?: number | null;
|
||||
isModalOpen: boolean;
|
||||
}
|
||||
|
||||
class App extends React.Component<Props, State> {
|
||||
state: State = {
|
||||
selectedIndex: null,
|
||||
isModalOpen: false,
|
||||
};
|
||||
|
||||
_updateSelectionText = (selectedIndex: number) => {
|
||||
_updateSelectionText = (selectedIndex?: number) => {
|
||||
this.setState({
|
||||
selectedIndex,
|
||||
});
|
||||
@@ -29,7 +39,9 @@ class App extends React.Component<Props, State> {
|
||||
_renderSelectionText = () => {
|
||||
const { selectedIndex } = this.state;
|
||||
const text =
|
||||
selectedIndex === null ? 'No Option Selected' : `Option #${selectedIndex + 1} Selected`;
|
||||
selectedIndex === null || selectedIndex === undefined
|
||||
? 'No Option Selected'
|
||||
: `Option #${selectedIndex + 1} Selected`;
|
||||
return <Text style={styles.selectionText}>{text}</Text>;
|
||||
};
|
||||
|
||||
@@ -37,6 +49,27 @@ class App extends React.Component<Props, State> {
|
||||
return <Text style={styles.sectionHeaderText}>{text}</Text>;
|
||||
};
|
||||
|
||||
_toggleModal = () => {
|
||||
this.setState((prevState) => ({ isModalOpen: !prevState.isModalOpen }));
|
||||
};
|
||||
|
||||
async _onShare() {
|
||||
try {
|
||||
const result = await Share.share({
|
||||
message: 'React Native | A framework for building native apps using React',
|
||||
});
|
||||
if (result.action === Share.sharedAction) {
|
||||
if (result.activityType) {
|
||||
// shared with activity type of result.activityType
|
||||
} else {
|
||||
// shared
|
||||
}
|
||||
} else if (result.action === Share.dismissedAction) {
|
||||
// dismissed
|
||||
}
|
||||
} catch (error) {}
|
||||
}
|
||||
|
||||
_renderButtons() {
|
||||
const { showActionSheetWithOptions } = this.props;
|
||||
return (
|
||||
@@ -63,6 +96,44 @@ class App extends React.Component<Props, State> {
|
||||
onSelection={this._updateSelectionText}
|
||||
showActionSheetWithOptions={showActionSheetWithOptions}
|
||||
/>
|
||||
<ShowActionSheetButton
|
||||
title="iPad Anchor"
|
||||
withAnchor
|
||||
withTitle
|
||||
onSelection={this._updateSelectionText}
|
||||
showActionSheetWithOptions={showActionSheetWithOptions}
|
||||
/>
|
||||
<ShowActionSheetButton
|
||||
title="Nested Action Sheets"
|
||||
onSelection={(index) => {
|
||||
if (!index || index < 3) {
|
||||
showActionSheetWithOptions(
|
||||
{
|
||||
title: 'Sub Action Sheet',
|
||||
options: ['One', 'Two', 'Three', 'Done'],
|
||||
cancelButtonIndex: 3,
|
||||
},
|
||||
this._updateSelectionText
|
||||
);
|
||||
}
|
||||
}}
|
||||
showActionSheetWithOptions={showActionSheetWithOptions}
|
||||
/>
|
||||
<ShowActionSheetButton
|
||||
title="Share Menu"
|
||||
showActionSheetWithOptions={() =>
|
||||
showActionSheetWithOptions(
|
||||
{
|
||||
title: 'Share Menu',
|
||||
options: ['Share', 'Cancel'],
|
||||
cancelButtonIndex: 1,
|
||||
},
|
||||
(i) => {
|
||||
i === 0 && this._onShare();
|
||||
}
|
||||
)
|
||||
}
|
||||
/>
|
||||
{this._renderSectionHeader('Android-Only Options')}
|
||||
<ShowActionSheetButton
|
||||
title="Icons"
|
||||
@@ -95,6 +166,26 @@ class App extends React.Component<Props, State> {
|
||||
onSelection={this._updateSelectionText}
|
||||
showActionSheetWithOptions={showActionSheetWithOptions}
|
||||
/>
|
||||
{this._renderSectionHeader('Special Cases')}
|
||||
<TouchableOpacity onPress={this._toggleModal}>
|
||||
<Text style={styles.link}>Open Modal</Text>
|
||||
</TouchableOpacity>
|
||||
{this.state.isModalOpen && (
|
||||
<Modal>
|
||||
<View style={{ flex: 1, padding: 30 }}>
|
||||
<ShowActionSheetButton
|
||||
useModal
|
||||
title="Options Only"
|
||||
onSelection={this._updateSelectionText}
|
||||
showActionSheetWithOptions={showActionSheetWithOptions}
|
||||
/>
|
||||
|
||||
<TouchableOpacity onPress={this._toggleModal}>
|
||||
<Text style={styles.link}>Close Modal</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
</Modal>
|
||||
)}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@@ -120,7 +211,7 @@ class App extends React.Component<Props, State> {
|
||||
}
|
||||
}
|
||||
|
||||
const ConnectedApp = connectActionSheet<{}>(App);
|
||||
const ConnectedApp = connectActionSheet<object>(App);
|
||||
|
||||
export default class AppContainer extends React.Component {
|
||||
render() {
|
||||
@@ -162,4 +253,8 @@ const styles = StyleSheet.create({
|
||||
fontSize: 16,
|
||||
marginTop: 20,
|
||||
},
|
||||
link: {
|
||||
fontSize: 15,
|
||||
textDecorationLine: 'underline',
|
||||
},
|
||||
});
|
||||
@@ -1,22 +1,26 @@
|
||||
import * as React from 'react';
|
||||
import { Text, View, TextStyle } from 'react-native';
|
||||
import { MaterialIcons, Entypo } from '@expo/vector-icons';
|
||||
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 } 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;
|
||||
showActionSheetWithOptions: (
|
||||
optons: ActionSheetOptions,
|
||||
callback: (buttonIndex: number) => void
|
||||
options: ActionSheetOptions,
|
||||
callback: (buttonIndex?: number) => void
|
||||
) => void;
|
||||
onSelection: (index: number) => void;
|
||||
onSelection: (index?: number) => void;
|
||||
withTitle?: boolean;
|
||||
withMessage?: boolean;
|
||||
withIcons?: boolean;
|
||||
withSeparators?: boolean;
|
||||
withCustomStyles?: boolean;
|
||||
withAnchor?: boolean;
|
||||
useModal?: boolean;
|
||||
}
|
||||
|
||||
// A custom button that shows examples of different share sheet configurations
|
||||
@@ -27,11 +31,16 @@ export default class ShowActionSheetButton extends React.PureComponent<Props> {
|
||||
withIcons: false,
|
||||
withSeparators: false,
|
||||
withCustomStyles: false,
|
||||
withAnchor: false,
|
||||
onSelection: null,
|
||||
useModal: false,
|
||||
};
|
||||
|
||||
_anchorRef = React.createRef<any>();
|
||||
|
||||
_showActionSheet = () => {
|
||||
const {
|
||||
withAnchor,
|
||||
withTitle,
|
||||
withMessage,
|
||||
withIcons,
|
||||
@@ -39,10 +48,11 @@ export default class ShowActionSheetButton extends React.PureComponent<Props> {
|
||||
withCustomStyles,
|
||||
onSelection,
|
||||
showActionSheetWithOptions,
|
||||
useModal,
|
||||
} = 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', 'Cancel'];
|
||||
const icons = withIcons
|
||||
? [icon('delete'), icon('save'), icon('share'), icon('cancel')]
|
||||
: undefined;
|
||||
@@ -51,6 +61,7 @@ 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 disabledButtonIndices = [1];
|
||||
const cancelButtonIndex = 3;
|
||||
const textStyle: TextStyle | undefined = withCustomStyles
|
||||
? {
|
||||
@@ -74,14 +85,26 @@ export default class ShowActionSheetButton extends React.PureComponent<Props> {
|
||||
textAlign: 'right',
|
||||
}
|
||||
: undefined;
|
||||
const containerStyle: ViewStyle | undefined = withCustomStyles
|
||||
? {
|
||||
backgroundColor: 'lightgrey',
|
||||
}
|
||||
: undefined;
|
||||
const anchor: number | null = this._anchorRef.current
|
||||
? findNodeHandle(this._anchorRef.current)
|
||||
: null;
|
||||
|
||||
showActionSheetWithOptions(
|
||||
{
|
||||
options,
|
||||
cancelButtonIndex,
|
||||
destructiveButtonIndex,
|
||||
disabledButtonIndices,
|
||||
title,
|
||||
message,
|
||||
icons,
|
||||
//iPad only
|
||||
anchor: withAnchor && anchor ? anchor : undefined,
|
||||
// Android only
|
||||
tintIcons: true,
|
||||
// Android only; default is true
|
||||
@@ -91,9 +114,13 @@ export default class ShowActionSheetButton extends React.PureComponent<Props> {
|
||||
// Android only
|
||||
titleTextStyle,
|
||||
// Android only
|
||||
messageTextStyle, // Android only
|
||||
messageTextStyle,
|
||||
// Android only,
|
||||
containerStyle,
|
||||
// Android only,
|
||||
useModal,
|
||||
},
|
||||
buttonIndex => {
|
||||
(buttonIndex?: number) => {
|
||||
// Do something here depending on the button index selected
|
||||
onSelection(buttonIndex);
|
||||
}
|
||||
@@ -107,7 +134,11 @@ export default class ShowActionSheetButton extends React.PureComponent<Props> {
|
||||
style={{
|
||||
margin: 6,
|
||||
}}>
|
||||
<Entypo.Button name="code" backgroundColor="#3e3e3e" onPress={this._showActionSheet}>
|
||||
<Entypo.Button
|
||||
name="code"
|
||||
backgroundColor="#3e3e3e"
|
||||
onPress={this._showActionSheet}
|
||||
ref={this._anchorRef}>
|
||||
<Text
|
||||
style={{
|
||||
fontSize: 15,
|
||||
|
||||
+1
-2
@@ -4,7 +4,6 @@
|
||||
"description": "A cross-platform ActionSheet component. https://github.com/expo/react-native-action-sheet",
|
||||
"slug": "react-native-action-sheet-example",
|
||||
"privacy": "public",
|
||||
"sdkVersion": "35.0.0",
|
||||
"version": "3.0.0",
|
||||
"orientation": "portrait",
|
||||
"primaryColor": "#cccccc",
|
||||
@@ -15,4 +14,4 @@
|
||||
"web"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
module.exports = function(api) {
|
||||
module.exports = function (api) {
|
||||
api.cache(true);
|
||||
return {
|
||||
presets: ['babel-preset-expo'],
|
||||
};
|
||||
};
|
||||
};
|
||||
+10
-10
@@ -13,18 +13,18 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@expo/react-native-action-sheet": "../src",
|
||||
"@expo/vector-icons": "^10.0.0",
|
||||
"expo": "^35.0.0",
|
||||
"@expo/vector-icons": "^12.0.0",
|
||||
"expo": "^43.0.0-beta.3",
|
||||
"hoist-non-react-statics": "^3.3.0",
|
||||
"react": "16.8.3",
|
||||
"react-dom": "16.8.3",
|
||||
"react-native": "https://github.com/expo/react-native/archive/sdk-35.0.0.tar.gz",
|
||||
"react-native-web": "^0.11.5"
|
||||
"react": "17.0.1",
|
||||
"react-dom": "17.0.1",
|
||||
"react-native": "0.64.2",
|
||||
"react-native-web": "0.17.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^16.8.23",
|
||||
"@types/react-native": "^0.57.65",
|
||||
"babel-preset-expo": "^7.0.0",
|
||||
"typescript": "^3.5.3"
|
||||
"@types/react": "~17.0.21",
|
||||
"@types/react-native": "~0.64.12",
|
||||
"babel-preset-expo": "8.5.1",
|
||||
"typescript": "~4.3.5"
|
||||
}
|
||||
}
|
||||
+10
-3
@@ -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"
|
||||
}
|
||||
+3305
-2292
File diff suppressed because it is too large.
Load diff
+10
-11
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@expo/react-native-action-sheet",
|
||||
"version": "3.3.0",
|
||||
"version": "3.13.1",
|
||||
"description": "A cross-platform ActionSheet for React Native",
|
||||
"react-native": "lib/module/index.js",
|
||||
"types": "lib/typescript/index.d.ts",
|
||||
@@ -13,8 +13,9 @@
|
||||
"prepare": "bob build",
|
||||
"build": "bob build",
|
||||
"type-check": "tsc --noEmit",
|
||||
"lint": "eslint . --ext .ts,.tsx --fix",
|
||||
"fmt": "prettier --write \"{src,example}/**/*.{ts,tsx}\""
|
||||
"lint": "eslint . --fix",
|
||||
"lint-check": "eslint",
|
||||
"semantic-release": "semantic-release"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -33,19 +34,18 @@
|
||||
"homepage": "https://github.com/expo/react-native-action-sheet",
|
||||
"devDependencies": {
|
||||
"@react-native-community/bob": "^0.6.1",
|
||||
"@react-native-community/eslint-config": "^0.0.5",
|
||||
"@semantic-release/changelog": "^5.0.1",
|
||||
"@semantic-release/git": "^9.0.0",
|
||||
"@types/react": "^16.8.23",
|
||||
"@types/react-native": "^0.57.65",
|
||||
"@typescript-eslint/eslint-plugin": "^1.12.0",
|
||||
"@typescript-eslint/parser": "^1.12.0",
|
||||
"eslint": "^6.0.1",
|
||||
"eslint-config-prettier": "^6.0.0",
|
||||
"eslint-plugin-prettier": "3.1.0",
|
||||
"eslint": "^7.32.0",
|
||||
"eslint-config-universe": "^8.0.0",
|
||||
"husky": "^3.0.0",
|
||||
"lint-staged": "^9.2.0",
|
||||
"prettier": "^1.18.2",
|
||||
"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": {
|
||||
@@ -68,7 +68,6 @@
|
||||
"lint-staged": {
|
||||
"*.{js,ts,tsx}": [
|
||||
"yarn lint",
|
||||
"yarn fmt",
|
||||
"git add"
|
||||
]
|
||||
},
|
||||
|
||||
@@ -1,7 +1,18 @@
|
||||
import * as React from 'react';
|
||||
import { StyleSheet, Text, Image, View, ScrollView } from 'react-native';
|
||||
import TouchableNativeFeedbackSafe from './TouchableNativeFeedbackSafe';
|
||||
import {
|
||||
AccessibilityInfo,
|
||||
findNodeHandle,
|
||||
Image,
|
||||
Platform,
|
||||
ScrollView,
|
||||
StyleSheet,
|
||||
Text,
|
||||
UIManager,
|
||||
View,
|
||||
} from 'react-native';
|
||||
|
||||
import { ActionSheetOptions } from '../types';
|
||||
import TouchableNativeFeedbackSafe from './TouchableNativeFeedbackSafe';
|
||||
|
||||
type Props = ActionSheetOptions & {
|
||||
tintIcons: boolean | null;
|
||||
@@ -14,6 +25,40 @@ const BLACK_54PC_TRANSPARENT = '#0000008a';
|
||||
const BLACK_87PC_TRANSPARENT = '#000000de';
|
||||
const DESTRUCTIVE_COLOR = '#d32f2f';
|
||||
|
||||
/**
|
||||
* Can be used as a React ref for a component to auto-focus for accessibility on render.
|
||||
* @param ref The component to auto-focus
|
||||
*/
|
||||
const focusViewOnRender = (ref: React.Component | null) => {
|
||||
if (ref) {
|
||||
const reactTag = findNodeHandle(ref);
|
||||
if (reactTag) {
|
||||
if (Platform.OS === 'android') {
|
||||
// @ts-ignore: sendAccessibilityEvent is missing from @types/react-native
|
||||
UIManager.sendAccessibilityEvent(
|
||||
reactTag,
|
||||
// @ts-ignore: AccessibilityEventTypes is missing from @types/react-native
|
||||
UIManager.AccessibilityEventTypes.typeViewFocused
|
||||
);
|
||||
} else {
|
||||
AccessibilityInfo.setAccessibilityFocus(reactTag);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const isIndexDestructive = (index: number, destructiveIndex?: number | number[]) => {
|
||||
if (Array.isArray(destructiveIndex)) {
|
||||
return destructiveIndex.includes(index);
|
||||
}
|
||||
|
||||
return index === destructiveIndex;
|
||||
};
|
||||
|
||||
const isIndexDisabled = (index: number, disabledButtonIndices: number[] = []) => {
|
||||
return disabledButtonIndices.includes(index);
|
||||
};
|
||||
|
||||
export default class ActionGroup extends React.Component<Props> {
|
||||
static defaultProps = {
|
||||
title: null,
|
||||
@@ -25,7 +70,7 @@ export default class ActionGroup extends React.Component<Props> {
|
||||
|
||||
render() {
|
||||
return (
|
||||
<View style={styles.groupContainer}>
|
||||
<View style={[styles.groupContainer, this.props.containerStyle]}>
|
||||
{this._renderTitleContent()}
|
||||
<ScrollView>{this._renderOptionViews()}</ScrollView>
|
||||
</View>
|
||||
@@ -75,11 +120,14 @@ export default class ActionGroup extends React.Component<Props> {
|
||||
options,
|
||||
icons,
|
||||
destructiveButtonIndex,
|
||||
disabledButtonIndices,
|
||||
destructiveColor = DESTRUCTIVE_COLOR,
|
||||
onSelect,
|
||||
startIndex,
|
||||
length,
|
||||
textStyle,
|
||||
tintColor,
|
||||
autoFocus,
|
||||
showSeparators,
|
||||
} = this.props;
|
||||
const optionViews: React.ReactNode[] = [];
|
||||
@@ -92,16 +140,21 @@ export default class ActionGroup extends React.Component<Props> {
|
||||
const defaultColor = tintColor
|
||||
? tintColor
|
||||
: (textStyle || {}).color || BLACK_87PC_TRANSPARENT;
|
||||
const color = i === destructiveButtonIndex ? DESTRUCTIVE_COLOR : defaultColor;
|
||||
const disabled = isIndexDisabled(i, disabledButtonIndices);
|
||||
const color = isIndexDestructive(i, destructiveButtonIndex) ? destructiveColor : defaultColor;
|
||||
const iconSource = icons != null ? icons[i] : null;
|
||||
|
||||
optionViews.push(
|
||||
<TouchableNativeFeedbackSafe
|
||||
ref={autoFocus && i === 0 ? focusViewOnRender : undefined}
|
||||
key={i}
|
||||
pressInDelay={0}
|
||||
background={nativeFeedbackBackground}
|
||||
disabled={disabled}
|
||||
onPress={() => onSelect(i)}
|
||||
style={styles.button}>
|
||||
style={[styles.button, disabled && styles.disabledButton]}
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={options[i]}>
|
||||
{this._renderIconElement(iconSource, color)}
|
||||
<Text style={[styles.text, textStyle, { color }]}>{options[i]}</Text>
|
||||
</TouchableNativeFeedbackSafe>
|
||||
@@ -124,6 +177,9 @@ const styles = StyleSheet.create({
|
||||
height: 56,
|
||||
paddingHorizontal: 16,
|
||||
},
|
||||
disabledButton: {
|
||||
opacity: 0.5,
|
||||
},
|
||||
groupContainer: {
|
||||
backgroundColor: '#ffffff',
|
||||
overflow: 'hidden',
|
||||
@@ -132,6 +188,7 @@ const styles = StyleSheet.create({
|
||||
width: 24,
|
||||
height: 24,
|
||||
marginRight: 32,
|
||||
justifyContent: 'center',
|
||||
},
|
||||
message: {
|
||||
marginTop: 12,
|
||||
|
||||
@@ -8,10 +8,14 @@ import {
|
||||
} from 'react-native';
|
||||
|
||||
// This TouchableOpacity has the same staic method of TouchableNativeFeedback
|
||||
class CustomTouchableOpacity extends TouchableOpacity {
|
||||
class CustomTouchableOpacity extends React.Component {
|
||||
static SelectableBackground = () => ({});
|
||||
static SelectableBackgroundBorderless = () => ({});
|
||||
static Ripple = (color: string, borderless?: boolean) => ({});
|
||||
|
||||
render() {
|
||||
return <TouchableOpacity {...this.props}>{this.props.children}</TouchableOpacity>;
|
||||
}
|
||||
}
|
||||
|
||||
const TouchableComponent = Platform.select({
|
||||
|
||||
@@ -1,25 +1,41 @@
|
||||
import * as React from 'react';
|
||||
import { ActionSheetIOS, View } from 'react-native';
|
||||
import { ActionSheetIOS, View, ViewProps } from 'react-native';
|
||||
|
||||
import { ActionSheetIOSOptions } from '../types';
|
||||
|
||||
interface Props {
|
||||
readonly children: React.ReactNode;
|
||||
readonly pointerEvents?: ViewProps['pointerEvents'];
|
||||
}
|
||||
|
||||
type onSelect = (buttonIndex: number) => void;
|
||||
|
||||
export default class ActionSheet extends React.Component<Props> {
|
||||
render() {
|
||||
return <View style={{ flex: 1 }}>{React.Children.only(this.props.children)}</View>;
|
||||
return (
|
||||
<View pointerEvents={this.props.pointerEvents} style={{ flex: 1 }}>
|
||||
{React.Children.only(this.props.children)}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
showActionSheetWithOptions(options: ActionSheetIOSOptions, onSelect: onSelect) {
|
||||
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 iosOptions: ActionSheetIOSOptions = {
|
||||
...options,
|
||||
cancelButtonIndex,
|
||||
destructiveButtonIndex,
|
||||
options,
|
||||
tintColor,
|
||||
disabledButtonIndices,
|
||||
// A null title or message on iOS causes a crash
|
||||
title: options.title || undefined,
|
||||
message: options.message || undefined,
|
||||
title: dataOptions.title || undefined,
|
||||
message: dataOptions.message || undefined,
|
||||
anchor: dataOptions.anchor || undefined,
|
||||
userInterfaceStyle: dataOptions.userInterfaceStyle || undefined,
|
||||
};
|
||||
// @ts-ignore: Even though ActionSheetIOS supports array of numbers for `destructiveIndex` the types are not yet updated. See https://github.com/facebook/react-native/pull/18254.
|
||||
ActionSheetIOS.showActionSheetWithOptions(iosOptions, onSelect);
|
||||
}
|
||||
}
|
||||
+76
-23
@@ -3,12 +3,16 @@ import {
|
||||
Animated,
|
||||
BackHandler,
|
||||
Easing,
|
||||
Modal,
|
||||
Platform,
|
||||
StyleSheet,
|
||||
TouchableWithoutFeedback,
|
||||
View,
|
||||
ViewProps,
|
||||
} from 'react-native';
|
||||
import ActionGroup from './ActionGroup';
|
||||
|
||||
import { ActionSheetOptions } from '../types';
|
||||
import ActionGroup from './ActionGroup';
|
||||
|
||||
interface State {
|
||||
isVisible: boolean;
|
||||
@@ -21,12 +25,14 @@ interface State {
|
||||
|
||||
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> {
|
||||
@@ -45,13 +51,33 @@ export default class ActionSheet extends React.Component<Props, State> {
|
||||
sheetOpacity: new Animated.Value(0),
|
||||
};
|
||||
|
||||
_deferNextShow?: () => void = undefined;
|
||||
_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 } = this.state;
|
||||
const { isVisible, overlayOpacity, options } = this.state;
|
||||
const useModal = options ? options.autoFocus || options.useModal === true : false;
|
||||
const overlay = isVisible ? (
|
||||
<Animated.View
|
||||
style={[
|
||||
@@ -62,14 +88,31 @@ export default class ActionSheet extends React.Component<Props, State> {
|
||||
]}
|
||||
/>
|
||||
) : null;
|
||||
return (
|
||||
|
||||
// While the sheet is visible, hide the rest of the app's content from screen readers.
|
||||
const appContent = (
|
||||
<View
|
||||
style={{
|
||||
flex: 1,
|
||||
}}>
|
||||
style={styles.flexContainer}
|
||||
importantForAccessibility={isVisible ? 'no-hide-descendants' : 'auto'}>
|
||||
{React.Children.only(this.props.children)}
|
||||
{overlay}
|
||||
{isVisible ? this._renderSheet() : null}
|
||||
</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>
|
||||
);
|
||||
}
|
||||
@@ -86,17 +129,21 @@ export default class ActionSheet extends React.Component<Props, State> {
|
||||
icons,
|
||||
tintIcons,
|
||||
destructiveButtonIndex,
|
||||
disabledButtonIndices,
|
||||
destructiveColor,
|
||||
textStyle,
|
||||
tintColor,
|
||||
title,
|
||||
titleTextStyle,
|
||||
message,
|
||||
messageTextStyle,
|
||||
autoFocus,
|
||||
showSeparators,
|
||||
containerStyle,
|
||||
separatorStyle,
|
||||
} = options;
|
||||
return (
|
||||
<TouchableWithoutFeedback onPress={this._selectCancelButton}>
|
||||
<TouchableWithoutFeedback importantForAccessibility="yes" onPress={this._selectCancelButton}>
|
||||
<Animated.View
|
||||
needsOffscreenAlphaCompositing={isAnimating}
|
||||
style={[
|
||||
@@ -119,6 +166,8 @@ export default class ActionSheet extends React.Component<Props, State> {
|
||||
icons={icons}
|
||||
tintIcons={tintIcons === undefined ? true : tintIcons}
|
||||
destructiveButtonIndex={destructiveButtonIndex}
|
||||
destructiveColor={destructiveColor}
|
||||
disabledButtonIndices={disabledButtonIndices}
|
||||
onSelect={this._onSelect}
|
||||
startIndex={0}
|
||||
length={optionsArray.length}
|
||||
@@ -128,7 +177,9 @@ export default class ActionSheet extends React.Component<Props, State> {
|
||||
titleTextStyle={titleTextStyle}
|
||||
message={message || undefined}
|
||||
messageTextStyle={messageTextStyle}
|
||||
autoFocus={autoFocus}
|
||||
showSeparators={showSeparators}
|
||||
containerStyle={containerStyle}
|
||||
separatorStyle={separatorStyle}
|
||||
/>
|
||||
</View>
|
||||
@@ -138,14 +189,10 @@ export default class ActionSheet extends React.Component<Props, State> {
|
||||
}
|
||||
|
||||
showActionSheetWithOptions = (options: ActionSheetOptions, onSelect: (i: number) => void) => {
|
||||
const { isVisible, isAnimating, overlayOpacity, sheetOpacity } = this.state;
|
||||
|
||||
if (isVisible && isAnimating) {
|
||||
this._deferNextShow = this.showActionSheetWithOptions.bind(this, options, onSelect);
|
||||
return;
|
||||
}
|
||||
const { isVisible, overlayOpacity, sheetOpacity } = this.state;
|
||||
|
||||
if (isVisible) {
|
||||
this._deferAfterAnimation = this.showActionSheetWithOptions.bind(this, options, onSelect);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -170,12 +217,12 @@ export default class ActionSheet extends React.Component<Props, State> {
|
||||
duration: OPACITY_ANIMATION_IN_TIME,
|
||||
useNativeDriver: this.props.useNativeDriver,
|
||||
}),
|
||||
]).start(result => {
|
||||
]).start((result) => {
|
||||
if (result.finished) {
|
||||
this.setState({
|
||||
isAnimating: false,
|
||||
});
|
||||
this._deferNextShow = undefined;
|
||||
this._deferAfterAnimation = undefined;
|
||||
}
|
||||
});
|
||||
// @ts-ignore: Argument of type '"actionSheetHardwareBackPress"' is not assignable to parameter of type '"hardwareBackPress"'
|
||||
@@ -190,7 +237,7 @@ export default class ActionSheet extends React.Component<Props, State> {
|
||||
}
|
||||
|
||||
if (typeof options.cancelButtonIndex === 'undefined') {
|
||||
return;
|
||||
return false;
|
||||
} else if (typeof options.cancelButtonIndex === 'number') {
|
||||
return this._onSelect(options.cancelButtonIndex);
|
||||
} else {
|
||||
@@ -205,7 +252,10 @@ export default class ActionSheet extends React.Component<Props, State> {
|
||||
return false;
|
||||
}
|
||||
|
||||
onSelect && onSelect(index);
|
||||
if (onSelect) {
|
||||
this._deferAfterAnimation = onSelect.bind(this, index);
|
||||
}
|
||||
|
||||
return this._animateOut();
|
||||
};
|
||||
|
||||
@@ -234,15 +284,15 @@ export default class ActionSheet extends React.Component<Props, State> {
|
||||
duration: OPACITY_ANIMATION_OUT_TIME,
|
||||
useNativeDriver: this.props.useNativeDriver,
|
||||
}),
|
||||
]).start(result => {
|
||||
]).start((result) => {
|
||||
if (result.finished) {
|
||||
this.setState({
|
||||
isVisible: false,
|
||||
isAnimating: false,
|
||||
});
|
||||
|
||||
if (this._deferNextShow) {
|
||||
this._deferNextShow();
|
||||
if (this._deferAfterAnimation) {
|
||||
this._deferAfterAnimation();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -251,6 +301,9 @@ export default class ActionSheet extends React.Component<Props, State> {
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
flexContainer: {
|
||||
flex: 1,
|
||||
},
|
||||
overlay: {
|
||||
position: 'absolute',
|
||||
top: 0,
|
||||
|
||||
@@ -1,33 +1,38 @@
|
||||
import * as React from 'react';
|
||||
|
||||
import ActionSheet from './ActionSheet';
|
||||
import { Provider } from './context';
|
||||
import { ActionSheetOptions } from './types';
|
||||
import { ActionSheetOptions, ActionSheetProps } from './types';
|
||||
|
||||
interface Props {
|
||||
children: React.ReactNode;
|
||||
useNativeDriver?: boolean;
|
||||
}
|
||||
|
||||
export default class ActionSheetProvider extends React.Component<Props> {
|
||||
_actionSheetRef: React.RefObject<ActionSheet>;
|
||||
_context: ActionSheetProps;
|
||||
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
this._actionSheetRef = React.createRef();
|
||||
}
|
||||
|
||||
getContext = () => {
|
||||
return {
|
||||
this._context = {
|
||||
showActionSheetWithOptions: (options: ActionSheetOptions, callback: (i: number) => void) => {
|
||||
this._actionSheetRef.current !== null &&
|
||||
if (this._actionSheetRef.current != null) {
|
||||
this._actionSheetRef.current.showActionSheetWithOptions(options, callback);
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
getContext(): ActionSheetProps {
|
||||
return this._context;
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Provider value={this.getContext()}>
|
||||
<ActionSheet ref={this._actionSheetRef}>
|
||||
<Provider value={this._context}>
|
||||
<ActionSheet ref={this._actionSheetRef} useNativeDriver={this.props.useNativeDriver}>
|
||||
{React.Children.only(this.props.children)}
|
||||
</ActionSheet>
|
||||
</Provider>
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import * as React from 'react';
|
||||
import { Consumer, Context } from './context';
|
||||
import hoistNonReactStatic from 'hoist-non-react-statics';
|
||||
import * as React from 'react';
|
||||
|
||||
import { Consumer } from './context';
|
||||
import { ActionSheetProps } from './types';
|
||||
|
||||
export default function connectActionSheet<OwnProps = any>(
|
||||
WrappedComponent: React.ComponentType<OwnProps & Context>
|
||||
) {
|
||||
WrappedComponent: React.ComponentType<OwnProps & ActionSheetProps>
|
||||
): React.FunctionComponent<OwnProps & ActionSheetProps> {
|
||||
const ConnectedActionSheet = (props: OwnProps) => {
|
||||
return (
|
||||
<Consumer>
|
||||
|
||||
+2
-5
@@ -1,11 +1,8 @@
|
||||
import * as React from 'react';
|
||||
import { ActionSheetOptions } from './types';
|
||||
|
||||
export interface Context {
|
||||
showActionSheetWithOptions: (options: ActionSheetOptions, callback: (i: number) => void) => void;
|
||||
}
|
||||
import { ActionSheetOptions, ActionSheetProps } from './types';
|
||||
|
||||
const context = React.createContext<Context>({
|
||||
const context = React.createContext<ActionSheetProps>({
|
||||
showActionSheetWithOptions: (options: ActionSheetOptions, callback: (i: number) => void) => {},
|
||||
});
|
||||
|
||||
|
||||
+15
-1
@@ -1,6 +1,13 @@
|
||||
import * as React from 'react';
|
||||
import { TextStyle, ViewStyle } from 'react-native';
|
||||
|
||||
export interface ActionSheetProps {
|
||||
showActionSheetWithOptions: (
|
||||
options: ActionSheetOptions,
|
||||
callback: (i?: number) => void | Promise<void>
|
||||
) => void;
|
||||
}
|
||||
|
||||
// for iOS
|
||||
export interface ActionSheetIOSOptions {
|
||||
options: string[];
|
||||
@@ -8,7 +15,10 @@ export interface ActionSheetIOSOptions {
|
||||
message?: string;
|
||||
tintColor?: string;
|
||||
cancelButtonIndex?: number;
|
||||
destructiveButtonIndex?: number;
|
||||
destructiveButtonIndex?: number | number[];
|
||||
anchor?: number;
|
||||
userInterfaceStyle?: 'light' | 'dark';
|
||||
disabledButtonIndices?: number[];
|
||||
}
|
||||
|
||||
// for Android or Web
|
||||
@@ -18,6 +28,10 @@ export interface ActionSheetOptions extends ActionSheetIOSOptions {
|
||||
textStyle?: TextStyle;
|
||||
titleTextStyle?: TextStyle;
|
||||
messageTextStyle?: TextStyle;
|
||||
autoFocus?: boolean;
|
||||
showSeparators?: boolean;
|
||||
containerStyle?: ViewStyle;
|
||||
separatorStyle?: ViewStyle;
|
||||
useModal?: boolean;
|
||||
destructiveColor?: string;
|
||||
}
|
||||
+3
-2
@@ -5,9 +5,10 @@
|
||||
"module": "commonjs",
|
||||
"strict": true,
|
||||
"moduleResolution": "node",
|
||||
"lib": ["es2015", "es2016", "esnext"],
|
||||
"lib": ["dom", "es2015", "es2016", "esnext"],
|
||||
"jsx": "react-native",
|
||||
"esModuleInterop": true
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
Reference in new issue
Block a user