Skip to content

Commit 9ab3769

Browse files
authored
Merge pull request #476 from ammarahm-ed/develop
v10.1.0
2 parents 45280c5 + e4d8190 commit 9ab3769

File tree

13 files changed

+341
-132
lines changed

13 files changed

+341
-132
lines changed

app/sheets.tsx

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
import {
22
RouteDefinition,
33
SheetDefinition,
4-
registerSheet,
54
SheetRegister,
5+
SheetRegisterProps
66
} from 'react-native-actions-sheet';
7-
import Hello from './examples/hello';
7+
import AlwaysOpen from './examples/always-open';
8+
import BackgroundInteraction from './examples/background-interaction';
9+
import CustomScrollHandlers from './examples/custom-scroll-handlers';
10+
import DrawUnderStatusBar from './examples/draw-under-statusbar';
11+
import FlashListSheet from './examples/flashlist';
12+
import FlatListSheet from './examples/flatlist';
13+
import FloatingSheet from './examples/floating-sheet';
814
import Gestures from './examples/gestures';
9-
import SnapMe from './examples/snap-me';
15+
import Hello from './examples/hello';
1016
import Input from './examples/input';
17+
import LegendListExample from './examples/legend-list';
18+
import NestedSheet from './examples/nested';
1119
import Payload from './examples/payload';
12-
import BackgroundInteraction from './examples/background-interaction';
13-
import AlwaysOpen from './examples/always-open';
20+
import ReturnData from './examples/return-data';
21+
import RouterSheet from './examples/router';
1422
import ScrollViewSheet from './examples/scrollview';
15-
import FlatListSheet from './examples/flatlist';
16-
import FlashListSheet from './examples/flashlist';
1723
import ResizeSheet from './examples/scrollview-resize';
18-
import NestedSheet from './examples/nested';
19-
import RouterSheet from './examples/router';
20-
import DrawUnderStatusBar from './examples/draw-under-statusbar';
21-
import ReturnData from './examples/return-data';
22-
import FloatingSheet from './examples/floating-sheet';
23-
import LegendListExample from './examples/legend-list';
24-
import CustomScrollHandlers from './examples/custom-scroll-handlers';
24+
import SnapMe from './examples/snap-me';
2525

2626
/**
2727
* We extend some of the types here to give us great intellisense
@@ -66,29 +66,27 @@ declare module 'react-native-actions-sheet' {
6666
}
6767
}
6868

69-
export const Sheets = () => {
70-
return (
71-
<SheetRegister
72-
sheets={{
73-
hello: Hello,
74-
gestures: Gestures,
75-
'snap-me': SnapMe,
76-
input: Input,
77-
payload: Payload,
78-
'background-interaction': BackgroundInteraction,
79-
'always-open': AlwaysOpen,
80-
scrollview: ScrollViewSheet,
81-
flashlist: FlashListSheet,
82-
flatlist: FlatListSheet,
83-
'scrollview-resize': ResizeSheet,
84-
'nested-sheets': NestedSheet,
85-
'sheet-router': RouterSheet,
86-
'draw-under-statusbar': DrawUnderStatusBar,
87-
'return-data': ReturnData,
88-
'floating-sheet': FloatingSheet,
89-
'legend-list': LegendListExample,
90-
'custom-scroll-handlers': CustomScrollHandlers,
91-
}}
92-
/>
93-
);
69+
const sheets: SheetRegisterProps['sheets'] = {
70+
hello: Hello,
71+
gestures: Gestures,
72+
'snap-me': SnapMe,
73+
input: Input,
74+
payload: Payload,
75+
'background-interaction': BackgroundInteraction,
76+
'always-open': AlwaysOpen,
77+
scrollview: ScrollViewSheet,
78+
flashlist: FlashListSheet,
79+
flatlist: FlatListSheet,
80+
'scrollview-resize': ResizeSheet,
81+
'nested-sheets': NestedSheet,
82+
'sheet-router': RouterSheet,
83+
'draw-under-statusbar': DrawUnderStatusBar,
84+
'return-data': ReturnData,
85+
'floating-sheet': FloatingSheet,
86+
'legend-list': LegendListExample,
87+
'custom-scroll-handlers': CustomScrollHandlers,
88+
};
89+
90+
export const AppSheets = () => {
91+
return <SheetRegister sheets={sheets} />;
9492
};

docs/pages/guides/migrate.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ The following props have been changed in `ActionSheet` component:
6161
6262
The following new props have been added to `ActionSheet` component:
6363
64-
1. `enableElevation`: Now you can disable default elevation/shadow of the action sheet by setting this prop to false.
64+
1. `disableElevation`: Now you can disable default elevation/shadow of the action sheet by setting this prop to `true`.
6565
2. `initialTranslateFactor`: This prop allows you to set the initial translate factor of the action sheet when it opens. Default is `1` which means the action sheet will open from bottom of the screen. You can set it to `0.5` to have it open from half way of the screen.
6666
3. `returnValue`: The prop replaces `payload` prop to return data when the sheet is closed.
6767

docs/pages/reference/actionsheet.mdx

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ Default: `false`
9494

9595
Provide snap points ranging from 0 to 100. ActionSheet will snap between these points. If no snap points are provided, the default is a single snap point set to `100` which means that the sheet will be opened 100% on becoming visible.
9696

97+
Note. `snapPoints` are relative to the height of the content inside ActionSheet. 100 = All content visible and 50 = half of the content is visible.
98+
9799
| Type | Required |
98100
| ---------- | -------- |
99101
| `number[]` | no |
@@ -114,17 +116,29 @@ Default: `0`
114116

115117
The top indicator bar on the action sheet is a regular `View` component and can be styles as such.
116118

117-
| Type | Required |
118-
| ----------- | -------- |
119-
| `ViewStyle` | no |
119+
| Type | Required |
120+
| ----------------------- | -------- |
121+
| `StyleProp<ViewStyle> ` | no |
120122

121123
## `containerStyle`
122124

123125
Style the main container in the action sheet that wraps your content.
124126

125-
| Type | Required |
126-
| ------ | -------- |
127-
| Object | no |
127+
Note: You can set most styles here except `maxHeight`, `marginBottom` and `paddingBottom`. These are used internally. You can do this instead:
128+
129+
```tsx
130+
<ActionSheet>
131+
<View
132+
style={{
133+
paddingBottom: 50,
134+
}}
135+
/>
136+
</ActionSheet>
137+
```
138+
139+
| Type | Required |
140+
| ---------------------- | -------- |
141+
| `StyleProp<ViewStyle>` | no |
128142

129143
## `openAnimationConfig`
130144

@@ -444,18 +458,33 @@ Callback invoked when the snap position of the sheet changes.
444458
| -------- | -------- |
445459
| function | no |
446460

447-
448461
## `initialTranslateFactor`
462+
449463
Set the initial translate factor of the action sheet when it opens. Default is `1` which means the action sheet will open from bottom of the screen. You can set it to `0.5` to have it open from half way of the screen.
450464

451-
| Type | Required |
452-
| -------- | -------- |
453-
| number | no |
465+
| Type | Required |
466+
| ------ | -------- |
467+
| number | no |
454468

455469
Default: `1`
456470

457471
## `disableElevation`
472+
458473
Disable elevation/shadow of the action sheet.
459-
| Type | Required |
474+
| Type | Required |
460475
| --------- | -------- |
461-
| `boolean` | no |
476+
| `boolean` | no |
477+
478+
## `onRequestClose`
479+
480+
Called when the ActionSheet is closing based on some user actions:
481+
482+
Touching backdrop
483+
System back navigation
484+
Swiping down to close the ActionSheet
485+
486+
Return `false` to cancel closing the ActionSheet.
487+
488+
| Type | Required |
489+
| ------------------------------------- | -------- |
490+
| `(type: CloseRequestType) => boolean` | no |

docs/pages/reference/showoptions.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,11 @@ Any data that is sent from the `hide` function of `SheetManager` can be recieved
4949
| Type | Required |
5050
| ---------- | -------- |
5151
| `function` | false |
52+
53+
`snapIndex`
54+
55+
Set the snap point for the action sheet on open
56+
57+
| Type | Required |
58+
| -------- | -------- |
59+
| `number` | false |

example/App.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import React from 'react';
22
import { SheetProvider } from 'react-native-actions-sheet';
33
import { GestureHandlerRootView } from 'react-native-gesture-handler';
44
import changeNavigationBarColor from 'react-native-navigation-bar-color';
5-
import MainScreen from '../app/examples';
6-
import { Sheets } from '../app/sheets';
75
import { SafeAreaProvider } from 'react-native-safe-area-context';
6+
import MainScreen from '../app/examples';
7+
import { AppSheets } from '../app/sheets';
88

99
const App = () => {
1010
// To match the style of action sheet navigation bar, we use react-native-navigation-bar-color on android and the app.
@@ -15,7 +15,7 @@ const App = () => {
1515
return (
1616
<>
1717
<SafeAreaProvider>
18-
<Sheets />
18+
<AppSheets />
1919
<GestureHandlerRootView
2020
style={{
2121
flex: 1,

expo-example/App.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import {Sheets} from '../app/sheets';
2+
import {AppSheets} from '../app/sheets';
33
import {SheetProvider} from 'react-native-actions-sheet';
44
import MainScreen from '../app/examples';
55
import {GestureHandlerRootView} from 'react-native-gesture-handler';
@@ -9,7 +9,7 @@ const App = () => {
99
return (
1010
<>
1111
<SafeAreaProvider>
12-
<Sheets />
12+
<AppSheets />
1313
<GestureHandlerRootView
1414
style={{
1515
flex: 1,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-actions-sheet",
3-
"version": "10.0.1",
3+
"version": "10.1.0",
44
"description": "A Cross Platform(Android & iOS) ActionSheet with a robust and flexible api, native performance and zero dependency code for react native. Create anything you want inside ActionSheet.",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",

src/hooks/use-accessibility.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import {AccessibilityInfo, Platform} from 'react-native';
2+
import {useEffect, useRef} from 'react';
3+
4+
let accessibilityInfo = {
5+
prefersCrossFadeTransitions: false,
6+
isReduceMotionEnabled: false,
7+
};
8+
9+
export async function getAccessibilityInfo() {
10+
if (Platform.OS !== "ios") return accessibilityInfo;
11+
try {
12+
accessibilityInfo.isReduceMotionEnabled =
13+
await AccessibilityInfo.isReduceMotionEnabled();
14+
if (!accessibilityInfo.isReduceMotionEnabled) {
15+
accessibilityInfo.prefersCrossFadeTransitions = false;
16+
return accessibilityInfo;
17+
}
18+
accessibilityInfo.prefersCrossFadeTransitions =
19+
await AccessibilityInfo.prefersCrossFadeTransitions();
20+
return accessibilityInfo;
21+
} catch (e) {
22+
return accessibilityInfo;
23+
}
24+
}
25+
26+
getAccessibilityInfo();
27+
28+
export function useAccessibility() {
29+
const accessibilityRef = useRef(accessibilityInfo);
30+
31+
useEffect(() => {
32+
let subscription: {remove: () => void};
33+
if (Platform.OS === 'ios') {
34+
const handler = () => {
35+
getAccessibilityInfo().then(
36+
result => (accessibilityRef.current = result),
37+
);
38+
};
39+
40+
subscription = AccessibilityInfo.addEventListener?.('change', handler);
41+
handler();
42+
}
43+
44+
return () => {
45+
subscription?.remove?.();
46+
};
47+
}, []);
48+
49+
return accessibilityRef;
50+
}

src/hooks/use-sheet-manager.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable curly */
2-
import {useEffect, useState} from 'react';
2+
import {useEffect, useRef, useState} from 'react';
33
import {actionSheetEventManager} from '../eventmanager';
44
import {useProviderContext} from '../provider';
55

@@ -11,23 +11,26 @@ const useSheetManager = ({
1111
}: {
1212
id?: string;
1313
onHide: (data?: any) => void;
14-
onBeforeShow?: (data?: any) => void;
14+
onBeforeShow?: (data?: any, snapIndex?: number) => void;
1515
onContextUpdate: () => void;
1616
}) => {
1717
const [visible, setVisible] = useState(false);
1818
const currentContext = useProviderContext();
19-
19+
const visibleRef = useRef({
20+
value: visible,
21+
});
22+
visibleRef.current.value = visible;
2023
useEffect(() => {
2124
if (!id) return undefined;
2225

2326
const subscriptions = [
2427
actionSheetEventManager.subscribe(
2528
`show_${id}`,
26-
(data: any, context?: string) => {
29+
(data: any, context?: string, snapIndex?: number) => {
2730
if (currentContext !== context) return;
2831
if (visible) return;
2932
onContextUpdate?.();
30-
onBeforeShow?.(data);
33+
onBeforeShow?.(data, snapIndex);
3134
setVisible(true);
3235
},
3336
),
@@ -44,6 +47,7 @@ const useSheetManager = ({
4447
return {
4548
visible,
4649
setVisible,
50+
visibleRef: visibleRef,
4751
};
4852
};
4953

0 commit comments

Comments
 (0)