Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions docs/docs/guides/02-theming.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -307,16 +307,19 @@ Valid `themes` keys are:
```ts
// App.tsx
import { NavigationContainer, DefaultTheme } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import {
PaperProvider,
MD3LightTheme,
adaptNavigationTheme,
} from 'react-native-paper';
const Stack = createStackNavigator();

const Stack = createNativeStackNavigator();

const { LightTheme } = adaptNavigationTheme({
reactNavigationLight: DefaultTheme,
});

export default function App() {
return (
<PaperProvider theme={MD3LightTheme}>
Expand Down
6 changes: 3 additions & 3 deletions docs/docs/guides/08-theming-with-react-navigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ But how to make them work together?

### Material Design 3

React Native Paper follows the Material Design 3 <i>(Material You)</i> color system, which differs from React Navigation’s default theme shape.
React Native Paper follows the Material Design 3 <i>(Material You)</i> color system, which differs from React Navigation’s default theme shape.

However, to simplify adapting React Navigation theme colors, to use the ones from React Native Paper, it's worth using a utility called `adaptNavigationTheme` – it accepts navigation-compliant themes in both modes and returns their equivalents adjusted to Material Design 3.

Expand Down Expand Up @@ -47,7 +47,7 @@ For React Native Paper theme to work, we need to use `PaperProvider` also at the

```js
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { TouchableOpacity } from 'react-native';
import {
Card,
Expand All @@ -56,7 +56,7 @@ import {
PaperProvider,
} from 'react-native-paper';

const Stack = createStackNavigator();
const Stack = createNativeStackNavigator();

const HomeScreen = ({ navigation }) => (
<TouchableOpacity
Expand Down
12 changes: 6 additions & 6 deletions docs/docs/guides/09-react-navigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ title: Integrate AppBar with React Navigation

- `react-native-paper`
- `react-navigation`

We assume that you have already installed the mentioned libraries above, otherwise please check out the guides below.

[React Native Paper - Getting Started](https://callstack.github.io/react-native-paper/docs/guides/getting-started)

[React Navigation - Getting Started](https://reactnavigation.org/docs/getting-started/)

## Stack Navigator
Expand All @@ -26,9 +26,9 @@ Let's create two screens. A main screen named `Home` and details screen named `D
import 'react-native-gesture-handler';
import React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import { createNativeStackNavigator } from '@react-navigation/native-stack';

const Stack = createStackNavigator();
const Stack = createNativeStackNavigator();

export default function App() {
return (
Expand Down Expand Up @@ -276,6 +276,6 @@ Final result:

<img src="/react-native-paper/screenshots/react-navigation-appBar4.gif" width="300" />

That's all we need! We have app bar that contains everything we need to navigate through screens and access an additional menu on the main screen. As you can see, with Material design `Appbar` provided by `react-native-paper` used together with `react-navigation` we can easily create an app that looks and works great.
That's all we need! We have app bar that contains everything we need to navigate through screens and access an additional menu on the main screen. As you can see, with Material design `Appbar` provided by `react-native-paper` used together with `react-navigation` we can easily create an app that looks and works great.

Grab the Expo [snack](https://snack.expo.dev/@react-native-paper/integrate-appbar-with-react-navigation) if you want to check the whole code!
8 changes: 4 additions & 4 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
"dependencies": {
"@react-native-async-storage/async-storage": "2.2.0",
"@react-native-masked-view/masked-view": "0.3.2",
"@react-navigation/bottom-tabs": "^7.3.10",
"@react-navigation/drawer": "^7.3.9",
"@react-navigation/native": "^7.1.6",
"@react-navigation/stack": "^7.2.10",
"@react-navigation/bottom-tabs": "^8.0.0-alpha.30",
"@react-navigation/drawer": "^8.0.0-alpha.31",
"@react-navigation/native": "^8.0.0-alpha.25",
"@react-navigation/native-stack": "^8.0.0-alpha.31",
"expo": "~56.0.0-preview.11",
"expo-crypto": "~56.0.3",
"expo-dev-client": "~56.0.9",
Expand Down
4 changes: 2 additions & 2 deletions example/src/ExampleList.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { FlatList } from 'react-native';

import type { StackNavigationProp } from '@react-navigation/stack';
import type { NativeStackNavigationProp } from '@react-navigation/native-stack';
import { Divider, List, useTheme } from 'react-native-paper';
import { useSafeAreaInsets } from 'react-native-safe-area-context';

Expand Down Expand Up @@ -115,7 +115,7 @@ export const examples: Record<
};

type Props = {
navigation: StackNavigationProp<{ [key: string]: undefined }>;
navigation: NativeStackNavigationProp<{ [key: string]: undefined }>;
};

type Item = {
Expand Down
4 changes: 2 additions & 2 deletions example/src/Examples/AppbarExample.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { Platform, StyleSheet, View } from 'react-native';

import type { StackNavigationProp } from '@react-navigation/stack';
import type { NativeStackNavigationProp } from '@react-navigation/native-stack';
import {
Appbar,
FAB,
Expand All @@ -18,7 +18,7 @@ import { useSafeAreaInsets } from 'react-native-safe-area-context';
import ScreenWrapper from '../ScreenWrapper';

type Props = {
navigation: StackNavigationProp<{}>;
navigation: NativeStackNavigationProp<{}>;
};

type AppbarModes = 'small' | 'medium' | 'large' | 'center-aligned';
Expand Down
66 changes: 55 additions & 11 deletions example/src/Examples/BottomNavigationBarExample.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import React from 'react';
import { View, StyleSheet } from 'react-native';
import { View, StyleSheet, Image } from 'react-native';

import Icon from '@react-native-vector-icons/material-design-icons';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { CommonActions } from '@react-navigation/native';
import {
CommonActions,
SFSymbol,
MaterialSymbol,
} from '@react-navigation/native';
import { Text, BottomNavigation } from 'react-native-paper';

const Tab = createBottomTabNavigator();
Expand All @@ -30,10 +34,9 @@ export default function BottomNavigationBarExample() {
screenOptions={{
headerShown: false,
}}
tabBar={({ navigation, state, descriptors, insets }) => (
tabBar={({ navigation, state, descriptors }) => (
<BottomNavigation.Bar
navigationState={state}
safeAreaInsets={insets}
onTabPress={({ route, preventDefault }) => {
const event = navigation.emit({
type: 'tabPress',
Expand All @@ -50,13 +53,54 @@ export default function BottomNavigationBarExample() {
});
}
}}
renderIcon={({ route, focused, color }) =>
descriptors[route.key].options.tabBarIcon?.({
focused,
color: typeof color === 'string' ? color : '',
size: 24,
}) || null
}
renderIcon={({ route, focused, color }) => {
const tabBarIcon = descriptors[route.key].options.tabBarIcon;

const size = 24;
const icon =
typeof tabBarIcon === 'function'
? tabBarIcon({ focused, color, size })
: tabBarIcon;

if (icon == null) {
return null;
}

if (React.isValidElement(icon)) {
return icon;
}

if (typeof icon === 'object' && icon !== null && 'type' in icon) {
switch (icon.type) {
case 'sfSymbol':
return (
<SFSymbol name={icon.name} size={size} color={color} />
);
case 'materialSymbol':
return (
<MaterialSymbol
name={icon.name}
size={size}
color={color}
/>
);
case 'image':
return (
<Image
accessibilityIgnoresInvertColors
source={icon.source}
resizeMode="contain"
fadeDuration={0}
style={{ width: size, height: size, tintColor: color }}
/>
);
}
}

throw new Error(
'Tab bar icon is not a valid React element, SFSymbol, MaterialSymbol, or Image.'
);
}}
getLabelText={({ route }) => descriptors[route.key].route.name}
/>
)}
Expand Down
4 changes: 2 additions & 2 deletions example/src/Examples/BottomNavigationExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
View,
} from 'react-native';

import type { StackNavigationProp } from '@react-navigation/stack';
import type { NativeStackNavigationProp } from '@react-navigation/native-stack';
import {
Appbar,
BottomNavigation,
Expand All @@ -22,7 +22,7 @@ import ScreenWrapper from '../ScreenWrapper';
type Route = { route: { key: string } };

type Props = {
navigation: StackNavigationProp<{}>;
navigation: NativeStackNavigationProp<{}>;
};

const MORE_ICON = Platform.OS === 'ios' ? 'dots-horizontal' : 'dots-vertical';
Expand Down
4 changes: 2 additions & 2 deletions example/src/Examples/MenuExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
View,
} from 'react-native';

import type { StackNavigationProp } from '@react-navigation/stack';
import type { NativeStackNavigationProp } from '@react-navigation/native-stack';
import {
Appbar,
Button,
Expand All @@ -21,7 +21,7 @@ import ScreenWrapper from '../ScreenWrapper';
type ContextualMenuCoord = { x: number; y: number };

type Props = {
navigation: StackNavigationProp<{}>;
navigation: NativeStackNavigationProp<{}>;
};

type MenuVisibility = {
Expand Down
4 changes: 2 additions & 2 deletions example/src/Examples/SearchbarExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { Keyboard, StyleSheet } from 'react-native';

import type { DrawerNavigationProp } from '@react-navigation/drawer';
import type { StackNavigationProp } from '@react-navigation/stack';
import type { NativeStackNavigationProp } from '@react-navigation/native-stack';
import {
Avatar,
List,
Expand All @@ -15,7 +15,7 @@ import {
import ScreenWrapper from '../ScreenWrapper';

type Props = {
navigation: StackNavigationProp<{}>;
navigation: NativeStackNavigationProp<{}>;
};

const SearchExample = ({ navigation }: Props) => {
Expand Down
4 changes: 2 additions & 2 deletions example/src/Examples/SegmentedButtonsExample.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';

import type { StackNavigationProp } from '@react-navigation/stack';
import type { NativeStackNavigationProp } from '@react-navigation/native-stack';
import { List } from 'react-native-paper';

import {
Expand All @@ -17,7 +17,7 @@ import {
import ScreenWrapper from '../ScreenWrapper';

type Props = {
navigation: StackNavigationProp<{ [key: string]: undefined }>;
navigation: NativeStackNavigationProp<{ [key: string]: undefined }>;
};

const SegmentedButtonExample = ({ navigation }: Props) => {
Expand Down
4 changes: 2 additions & 2 deletions example/src/Examples/TeamDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
View,
} from 'react-native';

import type { StackNavigationProp } from '@react-navigation/stack';
import type { NativeStackNavigationProp } from '@react-navigation/native-stack';
import {
Appbar,
BottomNavigation,
Expand Down Expand Up @@ -47,7 +47,7 @@ type Route = {
};

type Props = {
navigation: StackNavigationProp<{}>;
navigation: NativeStackNavigationProp<{}>;
route: Route;
};

Expand Down
4 changes: 2 additions & 2 deletions example/src/Examples/TeamsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import * as React from 'react';
import { StyleSheet } from 'react-native';

import type { ParamListBase } from '@react-navigation/native';
import type { StackScreenProps } from '@react-navigation/stack';
import type { NativeStackScreenProps } from '@react-navigation/native-stack';
import { DataTable } from 'react-native-paper';

import { teamsList } from '../../utils';
import ScreenWrapper from '../ScreenWrapper';

type Props = StackScreenProps<ParamListBase>;
type Props = NativeStackScreenProps<ParamListBase>;

const TeamsList = ({ navigation }: Props) => {
return (
Expand Down
4 changes: 2 additions & 2 deletions example/src/Examples/ThemeExample.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as React from 'react';
import { StyleSheet } from 'react-native';

import type { StackNavigationProp } from '@react-navigation/stack';
import type { NativeStackNavigationProp } from '@react-navigation/native-stack';
import { List, PaperProvider, Banner } from 'react-native-paper';

import ScreenWrapper from '../ScreenWrapper';

type Props = {
navigation: StackNavigationProp<{ [key: string]: undefined }>;
navigation: NativeStackNavigationProp<{ [key: string]: undefined }>;
};

const ThemeExample = ({ navigation }: Props) => {
Expand Down
Loading
Loading