|
| 1 | +--- |
| 2 | +name: Transitions |
| 3 | +menu: Guides |
| 4 | +route: /guides/transitions |
| 5 | +--- |
| 6 | + |
| 7 | +# Transitions |
| 8 | + |
| 9 | +In order to use transitions between two screens, simply add the `Transitioner` key to your stops. |
| 10 | + |
| 11 | +## Basic example |
| 12 | + |
| 13 | +```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 | +]); |
| 24 | +``` |
| 25 | + |
| 26 | +## Available transitioners |
| 27 | + |
| 28 | +| Transitioner | Import | transition | |
| 29 | +| :-------------------------------------------------------------------: | ---------------------------------------------------------- | :--------------------------------------------------: | |
| 30 | +| `SildeLeft` | `import { SildeLeft } from "react-gondola/transitions";` |  | |
| 31 | +| `SildeUp` | `import { SildeUp } from "react-gondola/transitions";` |  | |
| 32 | +| `RotateCrazy` (⚠️ experimental: this might be removed without notice) | `import { RotateCrazy } from "react-gondola/transitions";` |  | |
| 33 | + |
| 34 | +## Create your own transitioner |
| 35 | + |
| 36 | +You can create your own transitioner if the one availables does not fit your needs ! Get some inspiration by looking at `SlideLeft` source code and get started ! |
| 37 | + |
| 38 | +1. Your transitioner need to extend `TransitionComponent` (imported from `react-gondola/transitions`). |
| 39 | +2. Your transitioner will receive a `directionForward` prop. If true, your transitioner need to play the transition forward. Else, it need to play the transition backward. |
| 40 | +3. (Optionnal but recommended) If you use jest, you can test your component using `describeTransitioner` from `react-gondola/transitions/describeTransitioner` |
| 41 | + |
| 42 | +⚠️ If you use jest and want to test you Transitioner wihch uses `react-native-reanimated`, make sure you correctly mocked `react-native-reanimated`. |
| 43 | + |
| 44 | +```js |
| 45 | +// in your jest setup file, use the following |
| 46 | + |
| 47 | +jest.mock("react-native-reanimated/src/ReanimatedEventEmitter"); |
| 48 | +jest.mock("react-native-reanimated/src/ReanimatedModule", () => ({ |
| 49 | + configureNativeProps: () => {}, |
| 50 | + connectNodes: () => {}, |
| 51 | + disconnectNodes: () => {}, |
| 52 | + createNode: () => {}, |
| 53 | + configureProps: () => {}, |
| 54 | + getValue: () => {}, |
| 55 | + dropNode: () => {} |
| 56 | +})); |
| 57 | +jest.mock("react-native-reanimated/src/derived/evaluateOnce"); |
| 58 | +jest.mock("react-native-reanimated/src/core/AnimatedProps"); |
| 59 | +``` |
0 commit comments