Skip to content
This repository was archived by the owner on Nov 3, 2025. It is now read-only.

Commit 5268fb0

Browse files
committed
📝 (Canal) update doc for v2
1 parent afc8c9a commit 5268fb0

9 files changed

Lines changed: 128 additions & 48 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
This repo focuses on grouping screens by business conversion tunnels called **canals**. Why did I call it `react-gondola`? Just because I though of this package when I was visiting Venice... and I kind of hope that using this package will feel like navigating in Venice 📸
1818

19-
**When you use React Gondola**, you define several screens and you have the possibility to control their visibility with YOU're state machine. You define the rules of WHEN some screens should appear; `react-gondola` takes care of the rest.
19+
**When you use React Gondola**, you define several screens and you have the possibility to control their visibility with YOUR state machine. You define the rules of WHEN some screens should appear; `react-gondola` takes care of the rest.
2020

2121
## 👍 TLDR; Use this package if:
2222

docs/GettingStarted.mdx

Lines changed: 60 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,68 +25,99 @@ or
2525

2626
### Create a canal
2727

28-
In order to create a canal, use the `createCanal` function. Pass it your screens in the business order.
28+
In order to create a canal, use the `Canal` and `Screen` components. Your screens order is important: the order is the elevation order. If two or more screens are visible, last visible in the array is shown.
2929

3030
```ts
3131
import React from 'react';
32-
import { createCanal } from 'react-gondola';
32+
import { Canal, Screen } from 'react-gondola';
3333
import { FirstName } from './FirstName';
3434
import { LastName } from './LastName';
3535

36-
const SignInCanal = createCanal([
37-
{ name: 'firstName', Component: FirstName },
38-
{ name: 'lastName', Component: LastName },
39-
]);
40-
```
41-
42-
Then, use the canal wherever you want in your app. Specify whether to show/hide a screen by using the screen's name as a prop:
43-
44-
```ts
45-
import React, { Component } from 'react';
46-
import { SignInCanal } from './canals/SignIn';
47-
48-
export default class App extends Component {
49-
render() {
50-
return <SignInCanal firstName={true} lastName={false} />;
51-
}
52-
}
36+
const SignInCanal = () => (
37+
<Canal>
38+
<Screen name="firstname" Component={FirstName} visible />
39+
<Screen name="lastname" Component={LastName} visible={false} />
40+
</Canal>
41+
);
5342
```
5443

5544
That's all !
5645

5746
### Add a full screen page
5847

59-
If you want to add full screen page, pass the `isFullScreen` flag to the right page when creating a canal. In the following example, `confirm` is a full screen page.
48+
If you want to add full screen page, pass the `isFullScreen` flag prop to your `Screen` when creating a canal. In the following example, `lastname` is a full screen page.
6049

6150
```ts
6251
import React from 'react';
63-
import { createCanal } from 'react-gondola';
52+
import { Canal, Screen } from 'react-gondola';
6453
import { FirstName } from './FirstName';
6554
import { LastName } from './LastName';
6655

67-
const SignInCanal = createCanal([
68-
{ name: 'firstName', Component: FirstName },
69-
{ name: 'lastName', Component: LastName },
70-
{ name: 'confirm', Component: Confirm, isFullScreen: true },
71-
]);
56+
const SignInCanal = () => (
57+
<Canal>
58+
<Screen name="firstname" Component={FirstName} visible />
59+
<Screen name="lastname" Component={LastName} visible={false} isFullScreen />
60+
</Canal>
61+
);
7262
```
7363

74-
In order to render the full screen page at the top level in your app, add the `FullScreenPortal` at the top level in your rendering tree.
64+
In order to render the full screen page, add the `FullScreenPortal` at the top level in your rendering tree.
7565

7666
```ts
7767
import React, { Component } from 'react';
78-
import { SignInCanal } from './canals/SignIn';
68+
import { MyCanal } from './canals/MyCanal';
7969
import { FullScreenPortal } from 'react-gondola';
8070

8171
export default class App extends Component {
8272
render() {
8373
return (
8474
<FullScreenPortal>
85-
<SignInCanal firstName lastName confirm />
75+
<MyCanal />
8676
</FullScreenPortal>
8777
);
8878
}
8979
}
9080
```
9181

82+
### Go Back
83+
84+
Back events are also managed in a declarative way. Use the `onBack` callback prop on your screen.
85+
86+
```ts
87+
import React from 'react';
88+
import { Canal, Screen } from 'react-gondola';
89+
import { FirstName } from './FirstName';
90+
import { LastName } from './LastName';
91+
92+
const SignInCanal = () => (
93+
<Canal>
94+
<Screen name="firstname" Component={FirstName} visible />
95+
<Screen
96+
name="lastname"
97+
Component={LastName}
98+
visible={false}
99+
onBack={() => {
100+
doSomething();
101+
}}
102+
/>
103+
</Canal>
104+
);
105+
```
106+
107+
import { Info } from 'components/Info';
108+
import { Warning } from 'components/Warning';
109+
110+
<Warning>
111+
You should use a state machine in order to make your canal a controlled component. In fact, your
112+
`onBack` callbacks should modify your state in a way it affects the visibility of your screens.
113+
See the example in the repo.
114+
</Warning>
115+
<Info>
116+
If you have nested or multiple canals, here is the priority of `onBack` callbacks:
117+
<br/>
118+
- Last visible full-screen screen.
119+
<br/>
120+
- Deepest visible screen.
121+
</Info>
122+
92123
You are ready to use React-Gondola 🎸.

docs/Welcome.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ React Native declarative and reactive navigation.
1111

1212
This repo focuses on grouping screens by business conversion tunnels called **canals**. Why did I call it `react-gondola`? Just because I though of this package when I was visiting Venice... and I kind of hope that using this package will feel like navigating in Venice 📸
1313

14-
**When you use React Gondola**, you define several screens and you have the possibility to control their visibility with YOU're state machine. You define the rules of WHEN some screens should appear; `react-gondola` takes care of the rest.
14+
**When you use React Gondola**, you define several screens and you have the possibility to control their visibility with YOUR state machine. You define the rules of WHEN some screens should appear; `react-gondola` takes care of the rest.
1515

1616
## When to use this package
1717

docs/components/Info.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react';
2+
import { Text, View } from 'react-native';
3+
4+
export function Info(props: { children: string }) {
5+
return (
6+
<View
7+
style={{
8+
padding: 8,
9+
backgroundColor: '#eee',
10+
borderLeftWidth: 3,
11+
borderLeftColor: '#00b0ff',
12+
borderRadius: 4,
13+
marginBottom: 16,
14+
}}
15+
>
16+
<Text style={{ fontWeight: 'bold', fontSize: 16 }}>ℹ Info</Text>
17+
<Text style={{ marginTop: 4 }}>{props.children}</Text>
18+
</View>
19+
);
20+
}

docs/components/Warning.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export function Warning(props: { children: string }) {
1010
borderLeftWidth: 3,
1111
borderLeftColor: '#fdcb00',
1212
borderRadius: 4,
13+
marginBottom: 16,
1314
}}
1415
>
1516
<Text style={{ fontWeight: 'bold', fontSize: 16 }}>⚠️ Warning</Text>

docs/guides/Transitions.mdx

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,23 @@ route: /guides/transitions
66

77
# Transitions
88

9-
In order to use transitions between two screens, simply add the `Transitioner` key to your stops.
9+
In order to use transitions between two screens, simply add the `Transitioner` key to your screens.
1010

1111
## Basic example
1212

1313
```ts
14-
import React from "react";
15-
import { createCanal } from "react-gondola";
16-
import { SildeLeft } from "react-gondola/transitions";
17-
import { FirstName } from "./FirstName";
18-
import { LastName } from "./LastName";
19-
20-
const SignInCanal = createCanal([
21-
{ name: "firstName", Component: FirstName },
22-
{ name: "lastName", Component: LastName, Transitioner: SildeLeft }
23-
]);
14+
import React from 'react';
15+
import { Canal, Screen } from 'react-gondola';
16+
import { SildeLeft } from 'react-gondola/transitions';
17+
import { FirstName } from './FirstName';
18+
import { LastName } from './LastName';
19+
20+
const SignInCanal = () => (
21+
<Canal>
22+
<Screen name="firstname" Component={FirstName} Transitioner={SlideLeft} />
23+
<Screen name="lastname" Component={LastName} Transitioner={SlideLeft} />
24+
</Canal>
25+
);
2426
```
2527

2628
## Available transitioners
@@ -29,6 +31,7 @@ const SignInCanal = createCanal([
2931
| :-------------------------------------------------------------------: | ---------------------------------------------------------- | :--------------------------------------------------: |
3032
| `SildeLeft` | `import { SildeLeft } from "react-gondola/transitions";` | ![Slide Left transition](./assets/slideLeft.gif) |
3133
| `SildeUp` | `import { SildeUp } from "react-gondola/transitions";` | ![Slide Up transition](./assets/slideUp.gif) |
34+
| `ConvexUp` | `import { ConvexUp } from "react-gondola/transitions";` | |
3235
| `RotateCrazy` (⚠️ experimental: this might be removed without notice) | `import { RotateCrazy } from "react-gondola/transitions";` | ![Rotate Crazy transition](./assets/rotateCrazy.gif) |
3336

3437
## Create your own transitioner
@@ -44,16 +47,16 @@ You can create your own transitioner if the one availables does not fit your nee
4447
```js
4548
// in your jest setup file, use the following
4649

47-
jest.mock("react-native-reanimated/src/ReanimatedEventEmitter");
48-
jest.mock("react-native-reanimated/src/ReanimatedModule", () => ({
50+
jest.mock('react-native-reanimated/src/ReanimatedEventEmitter');
51+
jest.mock('react-native-reanimated/src/ReanimatedModule', () => ({
4952
configureNativeProps: () => {},
5053
connectNodes: () => {},
5154
disconnectNodes: () => {},
5255
createNode: () => {},
5356
configureProps: () => {},
5457
getValue: () => {},
55-
dropNode: () => {}
58+
dropNode: () => {},
5659
}));
57-
jest.mock("react-native-reanimated/src/derived/evaluateOnce");
58-
jest.mock("react-native-reanimated/src/core/AnimatedProps");
60+
jest.mock('react-native-reanimated/src/derived/evaluateOnce');
61+
jest.mock('react-native-reanimated/src/core/AnimatedProps');
5962
```

docs/mocks/react-native-reanimated.js

Whitespace-only changes.

doczrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = {
1010
'Example',
1111
'Contribute',
1212
'Roadmap',
13-
{ name: 'API', menu: ['createCanal', 'FullScreenPortal'] },
13+
{ name: 'API', menu: ['Screen', 'FullScreenPortal'] },
1414
],
1515
modifyBundlerConfig: config => {
1616
// Combine the default docz aliases with our custom aliases.
@@ -19,6 +19,7 @@ module.exports = {
1919
'react-native$': 'react-native-web',
2020
'react-gondola$': path.resolve(__dirname, 'src/index.ts'), // eslint-disable-line
2121
'react-gondola/transitions$': path.resolve(__dirname, 'src/transitions/index.ts'), // eslint-disable-line
22+
'react-native-reanimated$': path.resolve(__dirname, 'docs/mocks/react-native-reanimated'), // eslint-disable-line
2223
});
2324
return config;
2425
},

src/Screen.mdx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
name: Screen
3+
menu: API
4+
route: /api/screen
5+
---
6+
7+
import { Props } from 'docz';
8+
import { Screen } from 'react-gondola';
9+
10+
# Screen
11+
12+
`type: React.Component`
13+
14+
## Props
15+
16+
| Prop name | Required | Default | Usage |
17+
| :-------------: | :------: | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
18+
| `isFullScreen` | `false` | `false` | Specifies if the screen should be render in the `FullScreenPortal`. |
19+
| `onBack` | `false` | `undefined` | Function to call when a back event occurs. Use this prop and `visible` to control your Canal. |
20+
| `name` | `true` | `undefined` | Unique identifier of the screen. |
21+
| `Component` | `true` | `undefined` | Component to render. This is your page. |
22+
| `props` | `false` | `undefined` | Props to pass to the Component. Those props are transition-safe. This means while a transition occurs, those props are frozen. When the transition completes, the props flow is released. |
23+
| `Transtitioner` | `false` | `None` | Transition to apply to the screen when it appears or disappears. |
24+
| `visible` | `true` | `false` | Visibility of your screen. Use this prop and `onBack` to control your Canal. |

0 commit comments

Comments
 (0)