Skip to content

Commit

Permalink
Use admonitions syntax for notes
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Nov 22, 2023
1 parent f6d409a commit 8fabf6d
Show file tree
Hide file tree
Showing 58 changed files with 455 additions and 97 deletions.
12 changes: 10 additions & 2 deletions versioned_docs/version-6.x/MST-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@ title: Integrating with MobX State Tree
sidebar_label: MobX State Tree integration
---

> TODO: This guide is incomplete. Please help improve this by sending pull requests.
:::note

This guide is incomplete. Please help improve this by sending pull requests.

:::

This guide explores possible way to use React Navigation in a React Native project that uses [MobX State Tree](https://github.com/mobxjs/mobx-state-tree)(MST) for state management. The guide is accompanied by a [sample app](https://github.com/vonovak/react-navigation-mst-demo). Parts of the guide may be relevant also for users of [MobX](https://github.com/mobxjs/mobx) but please be aware of the fact that MobX does not come with a built-in solution for (de)serializing its state.

> Please note that in this guide, Mobx State Tree is not used to manage the navigation state itself - just the navigation params!
:::note

Please note that in this guide, Mobx State Tree is not used to manage the navigation state itself - just the navigation params!

:::

## Overview

Expand Down
18 changes: 15 additions & 3 deletions versioned_docs/version-6.x/auth-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ Most apps require that a user authenticates in some way to have access to data a
- When the state has loaded, the user is presented with either authentication screens or the main app, depending on whether valid authentication state was loaded.
- When the user signs out, we clear the authentication state and send them back to authentication screens.

> Note: We say "authentication screens" because usually there is more than one. You may have a main screen with a username and password field, another for "forgot password", and another set for sign up.
:::note

We say "authentication screens" because usually there is more than one. You may have a main screen with a username and password field, another for "forgot password", and another set for sign up.

:::

## What we need

Expand Down Expand Up @@ -118,11 +122,19 @@ state.userToken == null ? (
);
```

> If you have both your login-related screens and rest of the screens in two different Stack navigators, we recommend to use a single Stack navigator and place the conditional inside instead of using 2 different navigators. This makes it possible to have a proper transition animation during login/logout.
:::tip

If you have both your login-related screens and rest of the screens in two different Stack navigators, we recommend to use a single Stack navigator and place the conditional inside instead of using 2 different navigators. This makes it possible to have a proper transition animation during login/logout.

:::

## Implement the logic for restoring the token

> Note: The following is just an example of how you might implement the logic for authentication in your app. You don't need to follow it as is.
:::note

The following is just an example of how you might implement the logic for authentication in your app. You don't need to follow it as is.

:::

From the previous snippet, we can see that we need 3 state variables:

Expand Down
6 changes: 5 additions & 1 deletion versioned_docs/version-6.x/bottom-tab-navigator.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ function MyTabs() {
}
```

> For a complete usage guide please visit [Tab Navigation](tab-based-navigation.md)
:::note

For a complete usage guide please visit [Tab Navigation](tab-based-navigation.md)

:::

### Props

Expand Down
6 changes: 5 additions & 1 deletion versioned_docs/version-6.x/configuring-links.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ function App() {

When you specify the `linking` prop, React Navigation will handle incoming links automatically. On Android and iOS, it'll use React Native's [`Linking` module](https://reactnative.dev/docs/linking) to handle incoming links, both when the app was opened with the link, and when new links are received when the app is open. On the Web, it'll use the [History API](https://developer.mozilla.org/en-US/docs/Web/API/History_API) to sync the URL with the browser.

> Note: Currently there seems to be bug ([facebook/react-native#25675](https://github.com/facebook/react-native/issues/25675)) which results in it never resolving on Android. We add a timeout to avoid getting stuck forever, but it means that the link might not be handled in some cases.
:::warning

Currently there seems to be bug ([facebook/react-native#25675](https://github.com/facebook/react-native/issues/25675)) which results in it never resolving on Android. We add a timeout to avoid getting stuck forever, but it means that the link might not be handled in some cases.

:::

You can also pass a [`fallback`](navigation-container.md#fallback) prop to `NavigationContainer` which controls what's displayed when React Navigation is trying to resolve the initial deep link URL.

Expand Down
6 changes: 5 additions & 1 deletion versioned_docs/version-6.x/devtools.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ The package exposes the following APIs:

This hook provides integration with [Flipper](https://fbflipper.com/) for React Native apps.

> This doesn't work in Expo managed apps since they don't support Flipper.
:::warning

This doesn't work in Expo managed apps since they don't support Flipper.

:::

To be able to use this hook, you need to:

Expand Down
6 changes: 5 additions & 1 deletion versioned_docs/version-6.x/drawer-layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ Then, you need to install and configure the libraries that are required by the d
import 'react-native-gesture-handler';
```

> Note: If you are building for Android or iOS, do not skip this step, or your app may crash in production even if it works fine in development. This is not applicable to other platforms.
:::warning

If you are building for Android or iOS, do not skip this step, or your app may crash in production even if it works fine in development. This is not applicable to other platforms.

:::

3. If you're on a Mac and developing for iOS, you also need to install the pods (via [Cocoapods](https://cocoapods.org/)) to complete the linking.

Expand Down
12 changes: 10 additions & 2 deletions versioned_docs/version-6.x/drawer-navigator.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ Then, you need to install and configure the libraries that are required by the d
import 'react-native-gesture-handler';
```

> Note: If you are building for Android or iOS, do not skip this step, or your app may crash in production even if it works fine in development. This is not applicable to other platforms.
:::warning

If you are building for Android or iOS, do not skip this step, or your app may crash in production even if it works fine in development. This is not applicable to other platforms.

:::

3. If you're on a Mac and developing for iOS, you also need to install the pods (via [Cocoapods](https://cocoapods.org/)) to complete the linking.

Expand Down Expand Up @@ -75,7 +79,11 @@ function MyDrawer() {
}
```

> For a complete usage guide please visit [Drawer Navigation](drawer-based-navigation.md).
:::note

For a complete usage guide please visit [Drawer Navigation](drawer-based-navigation.md).

:::

### Props

Expand Down
18 changes: 15 additions & 3 deletions versioned_docs/version-6.x/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ In your project directory, run:
npm install react-native-screens react-native-safe-area-context
```

> Note: You might get warnings related to peer dependencies after installation. They are usually caused by incorrect version ranges specified in some packages. You can safely ignore most warnings as long as your app builds.
:::note

You might get warnings related to peer dependencies after installation. They are usually caused by incorrect version ranges specified in some packages. You can safely ignore most warnings as long as your app builds.

:::

From React Native 0.60 and higher, [linking is automatic](https://github.com/react-native-community/cli/blob/master/docs/autolinking.md). So you **don't need to run** `react-native link`.

Expand Down Expand Up @@ -89,7 +93,11 @@ import android.os.Bundle;

This change is required to avoid crashes related to View state being not persisted consistently across Activity restarts.

> Note: When you use a navigator (such as stack navigator), you'll need to follow the installation instructions of that navigator for any additional dependencies. If you're getting an error "Unable to resolve module", you need to install that module in your project.
:::info

When you use a navigator (such as stack navigator), you'll need to follow the installation instructions of that navigator for any additional dependencies. If you're getting an error "Unable to resolve module", you need to install that module in your project.

:::

## Wrapping your app in `NavigationContainer`

Expand All @@ -106,7 +114,11 @@ export default function App() {
}
```

> Note: In a typical React Native app, the `NavigationContainer` should be only used once in your app at the root. You shouldn't nest multiple `NavigationContainer`s unless you have a specific use case for them.
:::warning

In a typical React Native app, the `NavigationContainer` should be only used once in your app at the root. You shouldn't nest multiple `NavigationContainer`s unless you have a specific use case for them.

:::

Now you are ready to build and run your app on the device/simulator.

Expand Down
6 changes: 5 additions & 1 deletion versioned_docs/version-6.x/glossary-of-terms.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ title: Glossary of terms
sidebar_label: Glossary of terms
---

> This is a new section of the documentation and it's missing a lot of terms! Please [submit a pull request or an issue](https://github.com/react-navigation/react-navigation.github.io) with a term that you think should be explained here.
:::note

This is a new section of the documentation and it's missing a lot of terms! Please [submit a pull request or an issue](https://github.com/react-navigation/react-navigation.github.io) with a term that you think should be explained here.

:::

## Navigator

Expand Down
6 changes: 5 additions & 1 deletion versioned_docs/version-6.x/handling-safe-area.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ It's tempting to solve (a) by wrapping your entire app in a container with paddi

While React Native exports a `SafeAreaView` component, this component only supports iOS 10+ with no support for older iOS versions or Android. In addition, it also has some issues, i.e. if a screen containing safe area is animating, it causes jumpy behavior. So we recommend to use the `useSafeAreaInsets` hook from the [react-native-safe-area-context](https://github.com/th3rdwave/react-native-safe-area-context) library to handle safe areas in a more reliable way.

> Note: The `react-native-safe-area-context` library also exports a `SafeAreaView` component. While it works on Android, it also has the same issues related to jumpy behavior when animating. So we recommend always using the `useSafeAreaInsets` hook instead and avoid using the `SafeAreaView` component.
:::warning

The `react-native-safe-area-context` library also exports a `SafeAreaView` component. While it works on Android, it also has the same issues related to jumpy behavior when animating. So we recommend always using the `useSafeAreaInsets` hook instead and avoid using the `SafeAreaView` component.

:::

The rest of this guide gives more information on how to support safe areas in React Navigation.

Expand Down
6 changes: 5 additions & 1 deletion versioned_docs/version-6.x/headers.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,11 @@ function StackScreen() {
}
```

> You might be wondering, why `headerTitle` when we provide a component and not `title`, like before? The reason is that `headerTitle` is a property that is specific to stack navigators, the `headerTitle` defaults to a `Text` component that displays the `title`.
:::note

You might be wondering, why `headerTitle` when we provide a component and not `title`, like before? The reason is that `headerTitle` is a property that is specific to headers, whereas `title` will be used for tab bars, drawers etc. as well. The `headerTitle` defaults to a `Text` component that displays the `title`.

:::

## Additional configuration

Expand Down
18 changes: 15 additions & 3 deletions versioned_docs/version-6.x/hello-react-navigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ export default App;

If you run this code, you will see a screen with an empty navigation bar and a grey content area containing your `HomeScreen` component (shown above). The styles you see for the navigation bar and the content area are the default configuration for a stack navigator, we'll learn how to configure those later.

> The casing of the route name doesn't matter -- you can use lowercase `home` or capitalized `Home`, it's up to you. We prefer capitalizing our route names.
:::tip

The casing of the route name doesn't matter -- you can use lowercase `home` or capitalized `Home`, it's up to you. We prefer capitalizing our route names.

:::

### Configuring the navigator

Expand Down Expand Up @@ -100,7 +104,11 @@ Now our stack has two _routes_, a `Home` route and a `Details` route. A route ca

Here, the `Home` route corresponds to the `HomeScreen` component, and the `Details` route corresponds to the `DetailsScreen` component. The initial route for the stack is the `Home` route. Try changing it to `Details` and reload the app (React Native's Fast Refresh won't update changes from `initialRouteName`, as you might expect), notice that you will now see the `Details` screen. Then change it back to `Home` and reload once more.

> Note: The `component` prop accepts component, not a render function. Don't pass an inline function (e.g. `component={() => <HomeScreen />}`), or your component will unmount and remount losing all state when the parent component re-renders. See [Passing additional props](#passing-additional-props) for alternatives.
:::warning

The `component` prop accepts component, not a render function. Don't pass an inline function (e.g. `component={() => <HomeScreen />}`), or your component will unmount and remount losing all state when the parent component re-renders. See [Passing additional props](#passing-additional-props) for alternatives.

:::

### Specifying options

Expand Down Expand Up @@ -131,7 +139,11 @@ Sometimes we might want to pass additional props to a screen. We can do that wit
</Stack.Screen>
```

> Note: By default, React Navigation applies optimizations to screen components to prevent unnecessary renders. Using a render callback removes those optimizations. So if you use a render callback, you'll need to ensure that you use [`React.memo`](https://reactjs.org/docs/react-api.html#reactmemo) or [`React.PureComponent`](https://reactjs.org/docs/react-api.html#reactpurecomponent) for your screen components to avoid performance issues.
:::warning

By default, React Navigation applies optimizations to screen components to prevent unnecessary renders. Using a render callback removes those optimizations. So if you use a render callback, you'll need to ensure that you use [`React.memo`](https://reactjs.org/docs/react-api.html#reactmemo) or [`React.PureComponent`](https://reactjs.org/docs/react-api.html#reactpurecomponent) for your screen components to avoid performance issues.

:::

## What's next?

Expand Down
12 changes: 10 additions & 2 deletions versioned_docs/version-6.x/material-bottom-tab-navigator.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ title: Material Bottom Tabs Navigator
sidebar_label: Material Bottom Tabs
---

> The `material-bottom-tabs` navigator is moved to [`react-native-paper`](https://reactnativepaper.com/). Refer to [`react-native-paper`'s documentation](https://callstack.github.io/react-native-paper/docs/components/BottomNavigation/createMaterialBottomTabNavigator) for API and usage. For any issues with the navigator, please open an issue in [`react-native-paper`'s repository](https://github.com/callstack/react-native-paper/).
:::warning

The `material-bottom-tabs` navigator is moved to [`react-native-paper`](https://reactnativepaper.com/). Refer to [`react-native-paper`'s documentation](https://callstack.github.io/react-native-paper/docs/components/BottomNavigation/createMaterialBottomTabNavigator) for API and usage. For any issues with the navigator, please open an issue in [`react-native-paper`'s repository](https://github.com/callstack/react-native-paper/).

:::

A material-design themed tab bar on the bottom of the screen that lets you switch between different routes with animation. Routes are lazily initialized - their screen components are not mounted until they are first focused.

Expand Down Expand Up @@ -47,7 +51,11 @@ function MyTabs() {
}
```

> For a complete usage guide please visit [Tab Navigation](tab-based-navigation.md)
:::note

For a complete usage guide please visit [Tab Navigation](tab-based-navigation.md)

:::

## RouteConfigs

Expand Down
6 changes: 5 additions & 1 deletion versioned_docs/version-6.x/material-top-tab-navigator.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ function MyTabs() {
}
```

> For a complete usage guide please visit [Tab Navigation](tab-based-navigation.md)
:::note

For a complete usage guide please visit [Tab Navigation](tab-based-navigation.md)

:::

### Props

Expand Down
12 changes: 10 additions & 2 deletions versioned_docs/version-6.x/navigating.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ Let's break this down:
- `navigation` - the `navigation` prop is passed in to every **screen component** ([definition](glossary-of-terms.md#screen-component)) in the native stack navigator (more about this later in ["The navigation prop in depth"](navigation-prop.md)).
- `navigate('Details')` - we call the `navigate` function (on the `navigation` prop &mdash; naming is hard!) with the name of the route that we'd like to move the user to.

> If we call `navigation.navigate` with a route name that we haven't defined in a navigator, it'll print an error in development builds and nothing will happen in production builds. Said another way, we can only navigate to routes that have been defined on our navigator &mdash; we cannot navigate to an arbitrary component.
:::note

If we call `navigation.navigate` with a route name that we haven't defined in a navigator, it'll print an error in development builds and nothing will happen in production builds. Said another way, we can only navigate to routes that have been defined on our navigator &mdash; we cannot navigate to an arbitrary component.

:::

So we now have a stack with two routes: 1) the `Home` route 2) the `Details` route. What would happen if we navigated to the `Details` route again, from the `Details` screen?

Expand Down Expand Up @@ -123,7 +127,11 @@ function DetailsScreen({ navigation }) {
}
```

> On Android, React Navigation hooks in to the hardware back button and fires the `goBack()` function for you when the user presses it, so it behaves as the user would expect.
:::note

On Android, React Navigation hooks in to the hardware back button and fires the `goBack()` function for you when the user presses it, so it behaves as the user would expect.

:::

Another common requirement is to be able to go back _multiple_ screens -- for example, if you are several screens deep in a stack and want to dismiss all of them to go back to the first screen. In this case, we know that we want to go back to `Home` so we can use `navigate('Home')` (not `push`! try that out and see the difference). Another alternative would be `navigation.popToTop()`, which goes back to the first screen in the stack.

Expand Down
6 changes: 5 additions & 1 deletion versioned_docs/version-6.x/navigation-actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ navigation.dispatch(state => {
});
```

> Note: Consider the navigator's state object to be internal and subject to change in a minor release. Avoid using properties from the [navigation state](navigation-state.md) state object except `index` and `routes`, unless you really need it. If there is some functionality you cannot achieve without relying on the structure of the state object, please open an issue.
:::warning

Consider the navigator's state object to be internal and subject to change in a minor release. Avoid using properties from the [navigation state](navigation-state.md) state object except `index` and `routes`, unless you really need it. If there is some functionality you cannot achieve without relying on the structure of the state object, please open an issue.

:::

### goBack

Expand Down
6 changes: 5 additions & 1 deletion versioned_docs/version-6.x/navigation-container.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,11 @@ See [state persistence guide](state-persistence.md) for more details on how to p

### `onStateChange`

> Note: Consider the navigator's state object to be internal and subject to change in a minor release. Avoid using properties from the navigation state object except `index` and `routes`, unless you really need it. If there is some functionality you cannot achieve without relying on the structure of the state object, please open an issue.
:::warning

Consider the navigator's state object to be internal and subject to change in a minor release. Avoid using properties from the [navigation state](navigation-state.md) state object except `index` and `routes`, unless you really need it. If there is some functionality you cannot achieve without relying on the structure of the state object, please open an issue.

:::

Function that gets called every time [navigation state](navigation-state.md) changes. It receives the new navigation state as the argument.

Expand Down
Loading

0 comments on commit 8fabf6d

Please sign in to comment.