Skip to content

Commit e8d7407

Browse files
committed
update docs
1 parent 1eae239 commit e8d7407

File tree

17 files changed

+305
-68
lines changed

17 files changed

+305
-68
lines changed

docs/pages/guides/meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"sheetmanager": "Usage with SheetManager",
33
"passingdata": "Passing data to ActionSheet",
4+
"sheetrouter": "Using ActionSheet Router",
45
"getdata": "Returning results from ActionSheet",
56
"refaccess": "Ref access from anywhere",
67
"scrollview": "Using ScrollView",

docs/pages/guides/sheetrouter.mdx

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Using ActionSheet router
2+
3+
ActionSheet comes with a tiny router for navigation between different routes in an ActionSheet. This is useful for making different flows in your app without the need to open/close different ActionSheets.
4+
5+
You can say that using a router is like having one Sheet that can replace multiple Sheets in your app with routes.
6+
7+
Router works like any navigation router in your app.
8+
9+
```tsx
10+
import ActionSheet, {
11+
Route,
12+
RouteScreenProps,
13+
useRouter,
14+
useSheetRouteParams,
15+
} from 'react-native-actions-sheet';
16+
17+
const RouteA = ({router}: RouteScreenProps) => {
18+
return (
19+
<View>
20+
<Button
21+
title="Go to Route B"
22+
onPress={() => {
23+
router.navigate('route-b', {data: 'test'});
24+
}}
25+
/>
26+
</View>
27+
);
28+
};
29+
30+
const RouteB = () => {
31+
const router = useRouter();
32+
const params = useSheetRouteParams();
33+
34+
return (
35+
<View>
36+
<Button
37+
title="Go Back to Route A"
38+
onPress={() => {
39+
router.goBack();
40+
}}
41+
/>
42+
</View>
43+
);
44+
};
45+
46+
const routes: Route[] = [
47+
{
48+
name: 'route-a',
49+
component: RouteA,
50+
},
51+
{
52+
name: 'route-b',
53+
component: RouteB,
54+
},
55+
];
56+
57+
function Sheet(props: SheetProps) {
58+
return (
59+
<ActionSheet
60+
enableRouterBackNavigation={true}
61+
routes={routes}
62+
initialRoute="route-a"
63+
/>
64+
);
65+
}
66+
67+
export default Sheet;
68+
```

docs/pages/reference/actionsheet.mdx

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,58 @@ A function called just before the action sheet is ready to be shown.
346346
| -------- | -------- |
347347
| function | no |
348348

349+
## `onBeforeClose(data:any)`
349350

350-
## `backdropProps`
351+
A function called just before the action sheet is closing.
351352

352-
An object containing props for the backdrop layer. Used to provide accessibility props.
353+
| Type | Required |
354+
| -------- | -------- |
355+
| function | no |
356+
357+
## `routes`
358+
359+
A list of routes for this actions sheet if any.
360+
361+
| Type | Required |
362+
| --------------------------- | -------- |
363+
| [/reference/route](Route[]) | no |
364+
365+
## `onNavigate(route: string)`
366+
367+
An event called when navigating to a route in stack
353368

354369
| Type | Required |
355370
| -------- | -------- |
356-
| object | no |
371+
| function | no |
372+
373+
## `onNavigateBack(route: string)`
374+
375+
| Type | Required |
376+
| -------- | -------- |
377+
| function | no |
378+
379+
An event called when navigating back in stack.
380+
381+
## `initialRoute`
382+
383+
Initial route to navigate to when the sheet opens.
384+
385+
| Type | Required |
386+
| ------ | -------- |
387+
| string | no |
388+
389+
## `enableRouterBackNavigation`
390+
391+
Enable back navigation for router when pressing hardware back button or touching the back drop. Remember that swiping down the sheet will still close the sheet regardless of the route in stack.
392+
393+
| Type | Required |
394+
| ------- | -------- |
395+
| boolean | no |
396+
397+
## `backdropProps`
398+
399+
An object containing props for the backdrop layer. Used to provide accessibility props.
400+
401+
| Type | Required |
402+
| ------ | -------- |
403+
| object | no |

docs/pages/reference/meta.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,10 @@
77
"usescrollhandlers": "useScrollHandlers",
88
"registersheet": "registerSheet",
99
"showoptions": "ShowOptions",
10-
"hideoptions": "HideOptions"
10+
"hideoptions": "HideOptions",
11+
"userouter": "useRouter",
12+
"usesheetrouteparams": "useSheetRouteParams",
13+
"usesheetidcontext": "useSheetIDContext",
14+
"useprovidercontext": "useProviderContext",
15+
"route": "Route"
1116
}

docs/pages/reference/route.mdx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Route
2+
3+
A single component in router navigation stack.
4+
5+
## `name`
6+
7+
A name for the route
8+
9+
| Type | Required |
10+
| ------ | -------- |
11+
| string | true |
12+
13+
## `component`
14+
15+
A component to render when navigating to this route
16+
17+
| Type | Required |
18+
| --------------- | -------- |
19+
| React Component | true |
20+
21+
## `params`
22+
23+
Initial params for the route
24+
25+
| Type | Required |
26+
| ---- | -------- |
27+
| any | false |
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# useProviderContext
2+
3+
Get id of the current Sheet provider.
4+
5+
6+

docs/pages/reference/userouter.mdx

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# useRouter
2+
3+
A hook that helps you navigate between routes inside the sheet.
4+
5+
## `currentRoute:[/reference/route](Route)`
6+
7+
The current navigation route in stack that has been navigated to.
8+
9+
## `navigate(name: string, params?: any, snap?: number)`
10+
11+
Navigate to a route
12+
13+
Parameters:
14+
15+
`name`
16+
17+
Name of the route to navigate to.
18+
19+
| Type | Required |
20+
| ------ | -------- |
21+
| string | true |
22+
23+
`params`:
24+
25+
Any data to pass to the route during navigation.
26+
27+
| Type | Required |
28+
| ---- | -------- |
29+
| any | false |
30+
31+
`snap`:
32+
33+
Snap value for navigation animation. Between -100 to 100. A positive value snaps inwards, while a negative value snaps outwards.
34+
35+
| Type | Required |
36+
| ----------- | -------- |
37+
| -100 to 100 | true |
38+
39+
## `goBack(name?:string, snap?:number)`
40+
41+
Navigate back from a route.
42+
43+
Parameters:
44+
45+
`name`
46+
47+
Name of the route to navigate to.
48+
49+
| Type | Required |
50+
| ------ | -------- |
51+
| string | false |
52+
53+
`snap`:
54+
55+
Snap value for navigation animation. Between -100 to 100. A positive value snaps inwards, while a negative value snaps outwards.
56+
57+
| Type | Required |
58+
| ----------- | -------- |
59+
| -100 to 100 | true |
60+
61+
## `close()`
62+
63+
Close the sheet
64+
65+
## `popToTop()`
66+
67+
Pop to top of the stack
68+
69+
## `hasRoutes()`
70+
71+
Check whether any routes have been registered with this sheet.
72+
73+
## `stack: [/reference/route](Route[])`
74+
75+
Get the current rendered stack.
76+
77+
## `canGoBack()`
78+
79+
Check whether router can go back in navigation.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# useSheetIDContext
2+
3+
A simple hook that returns current sheet id.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `useSheetRouteParams`
2+
3+
Get route params passed to this route during navigation

example/src/confirm.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const RouteA = ({router}: RouteScreenProps) => {
2121
<Button
2222
title="No"
2323
onPress={() => {
24-
router?.navigate('route-b', undefined, 1);
24+
SheetManager.hide('confirm-sheet');
2525
}}
2626
/>
2727
</View>
@@ -63,15 +63,13 @@ const routes: Route[] = [
6363
function ConfirmSheet(props: SheetProps) {
6464
return (
6565
<ActionSheet
66+
id={props.sheetId}
6667
statusBarTranslucent={false}
6768
drawUnderStatusBar={false}
6869
gestureEnabled={true}
6970
containerStyle={{
7071
paddingHorizontal: 12,
7172
}}
72-
onClose={data => {
73-
SheetManager.hide(props.sheetId);
74-
}}
7573
enableRouterBackNavigation={true}
7674
routes={routes}
7775
initialRoute="route-a"

0 commit comments

Comments
 (0)