Skip to content

Commit 490a502

Browse files
committed
fix(docs): resolve docs build and icon issues
- define `__DEV__` with webpack `DefinePlugin` - standardize docs icons on `@react-native-vector-icons/material-design-icons` - update docs examples and icon guidance - alias `@react-native-vector-icons/get-image` to `false` - flatten CSS nesting in `custom.css` - add `isDynamicColorSupported = false` to the non-Android `DynamicTheme` fallback - fix the `TypescaleKey` type re-export
1 parent 8720eac commit 490a502

9 files changed

Lines changed: 40 additions & 48 deletions

File tree

docs/docs/guides/01-getting-started.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@ Minimum requirements:
4949

5050
Follow the [React Native Reanimated installation guide](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/getting-started/).
5151

52-
If you're on a vanilla React Native project, you also need to install and link [@react-native-vector-icons/material-design-icons](https://github.com/oblador/react-native-vector-icons).
52+
If you're on a vanilla React Native project, you also need to install [@react-native-vector-icons/material-design-icons](https://github.com/oblador/react-native-vector-icons/tree/master/packages/material-design-icons).
5353

54-
Specifically `MaterialDesignIcons` icon pack needs to be included in the project, because some components use those internally (e.g. `AppBar.BackAction` on Android).
54+
Specifically, the `MaterialDesignIcons` icon pack needs to be included in the project because some components use those icons internally, such as `AppBar.BackAction` on Android.
5555

5656
```bash npm2yarn
5757
npm install @react-native-vector-icons/material-design-icons
5858
```
5959

6060
:::note
61-
The `react-native-vector-icons` library requires some additional setup steps for each platform. To ensure proper use of icon fonts, please follow their [installation guide](https://github.com/oblador/react-native-vector-icons?tab=readme-ov-file#setup).
61+
`@react-native-vector-icons/material-design-icons` may require some additional setup steps depending on platform. To ensure the icon font is configured correctly, please follow the upstream [installation guide](https://github.com/oblador/react-native-vector-icons?tab=readme-ov-file#setup).
6262
:::
6363

6464
:::info

docs/docs/guides/03-icons.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import IconsList from '@site/src/components/IconsList.tsx';
1010

1111
## Configuring icons
1212

13-
Many of the components require the [react-native-vector-icons](https://github.com/oblador/react-native-vector-icons) library to render correctly. If you're using Expo, you don't need to do anything extra, but if it's a vanilla React Native project, you need to link the library as described in the [getting started guide](./01-getting-started.mdx).
13+
Many of the components render icon names using [`@react-native-vector-icons/material-design-icons`](https://github.com/oblador/react-native-vector-icons/tree/master/packages/material-design-icons). In Expo projects this usually works without extra setup. In vanilla React Native projects, install the package and complete any required platform setup as described in the [getting started guide](./01-getting-started.mdx).
1414

1515
:::note
1616
If you opted out of vector icons support using [babel-plugin-optional-require](https://github.com/satya164/babel-plugin-optional-require), you won't be able to use icon names for the icon prop. Some components may not look correct without vector icons and might need extra configuration.

docs/plugins/docusaurus-react-native-plugin.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const path = require('path');
2+
const webpack = require('webpack');
23

34
module.exports = function () {
45
return {
@@ -11,12 +12,15 @@ module.exports = function () {
1112
react: path.resolve('node_modules/react'),
1213
'react-native$': 'react-native-web',
1314
'react-native-paper': path.resolve('../src'),
14-
'react-native-vector-icons/MaterialCommunityIcons': path.resolve(
15-
'node_modules/@react-native-vector-icons/material-design-icons'
16-
),
15+
'@react-native-vector-icons/get-image': false,
1716
},
1817
extensions: ['.web.js'],
1918
},
19+
plugins: [
20+
new webpack.DefinePlugin({
21+
__DEV__: JSON.stringify(process.env.NODE_ENV !== 'production'),
22+
}),
23+
],
2024
};
2125
},
2226
};

docs/src/css/custom.css

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,10 @@ html[data-theme='light'] .gallery-dark {
128128
height: 124px;
129129
align-items: center;
130130
text-align: center;
131+
}
131132

132-
@media (max-width: 680px) {
133+
@media (max-width: 680px) {
134+
.icons-list-icon-container {
133135
width: 96px;
134136
}
135137
}
@@ -153,10 +155,10 @@ html[data-theme='light'] .gallery-dark {
153155
flex-wrap: wrap;
154156
justify-content: center;
155157
margin: 24px 0;
158+
}
156159

157-
&:last-child {
158-
justify-content: flex-start;
159-
}
160+
.icons-list-results:last-child {
161+
justify-content: flex-start;
160162
}
161163

162164
.icons-list-searchbar {
@@ -171,15 +173,15 @@ html[data-theme='light'] .gallery-dark {
171173
border-radius: 3px;
172174
transition: background-color 0.3s;
173175
outline: 0;
176+
}
174177

175-
&:focus,
176-
&:hover {
177-
background-color: #e7e7e7;
178-
}
178+
.icons-list-searchbar:focus,
179+
.icons-list-searchbar:hover {
180+
background-color: #e7e7e7;
181+
}
179182

180-
*:focus-visible {
181-
outline: auto;
182-
}
183+
.icons-list-searchbar:focus-visible {
184+
outline: auto;
183185
}
184186

185187
@font-face {

docs/src/data/extendedExamples/BottomNavigationBar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const staticCode = `import { Text, View } from 'react-native';
22
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
33
import { Provider, BottomNavigation } from 'react-native-paper';
4-
import MaterialCommunityIcons from '@expo/vector-icons/MaterialCommunityIcons';
4+
import MaterialCommunityIcons from '@react-native-vector-icons/material-design-icons';
55
import {
66
CommonActions,
77
createStaticNavigation,
@@ -103,7 +103,7 @@ const dynamicCode = `import { Text, View } from 'react-native';
103103
import { NavigationContainer, CommonActions } from '@react-navigation/native';
104104
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
105105
import { Provider, BottomNavigation } from 'react-native-paper';
106-
import MaterialCommunityIcons from '@expo/vector-icons/MaterialCommunityIcons';
106+
import MaterialCommunityIcons from '@react-native-vector-icons/material-design-icons';
107107
108108
function HomeScreen() {
109109
return (

src/components/BottomNavigation/BottomNavigationBar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ const Touchable = <Route extends BaseRoute>({
241241
* import { useState } from 'react';
242242
* import { View } from 'react-native';
243243
* import { BottomNavigation, Text, Provider } from 'react-native-paper';
244-
* import MaterialCommunityIcons from '@expo/vector-icons/MaterialCommunityIcons';
244+
* import MaterialCommunityIcons from '@react-native-vector-icons/material-design-icons';
245245
*
246246
* function HomeScreen() {
247247
* return (

src/components/MaterialCommunityIcon.tsx

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as React from 'react';
2-
import { ComponentProps } from 'react';
32
import {
43
ColorValue,
54
Platform,
@@ -12,7 +11,7 @@ import {
1211
import { black } from '../theme/colors';
1312

1413
export type IconProps = {
15-
name: ComponentProps<typeof MaterialCommunityIcons>['name'];
14+
name: string;
1615
color?: ColorValue;
1716
size: number;
1817
direction: 'rtl' | 'ltr';
@@ -41,48 +40,33 @@ export const accessibilityProps: AccessibilityProps =
4140
importantForAccessibility: 'no-hide-descendants',
4241
};
4342

44-
/**
45-
* Loads the appropriate icon module based on available dependencies
46-
*/
4743
const loadIconModule = () => {
4844
try {
4945
return require('@react-native-vector-icons/material-design-icons').default;
5046
} catch (e) {
51-
try {
52-
return require('@expo/vector-icons/MaterialCommunityIcons').default;
53-
} catch (e) {
54-
try {
55-
return require('react-native-vector-icons/MaterialCommunityIcons')
56-
.default;
57-
} catch (e) {
58-
return null;
59-
}
60-
}
47+
return null;
6148
}
6249
};
6350

6451
type IconModuleType = React.ComponentType<
65-
React.ComponentProps<
66-
| typeof import('@react-native-vector-icons/material-design-icons').default
67-
| typeof import('react-native-vector-icons/MaterialCommunityIcons').default
52+
Omit<
53+
React.ComponentProps<
54+
typeof import('@react-native-vector-icons/material-design-icons').default
55+
>,
56+
'name'
6857
> & {
58+
name: string;
6959
color: ColorValue;
7060
pointerEvents?: ViewProps['pointerEvents'];
7161
}
7262
>;
7363

7464
const IconModule = loadIconModule();
7565

76-
/**
77-
* Fallback component displayed when no icon library is available
78-
*/
7966
const FallbackIcon = ({ name, color, size, ...rest }: IconProps) => {
8067
console.warn(
81-
`Tried to use the icon '${name}' in a component from 'react-native-paper', but none of the required icon libraries are installed.`,
82-
`To fix this, please install one of the following:\n` +
83-
`- @expo/vector-icons\n` +
84-
`- @react-native-vector-icons/material-design-icons\n` +
85-
`- react-native-vector-icons\n\n` +
68+
`Tried to use the icon '${name}' in a component from 'react-native-paper', but the required icon library is not installed.`,
69+
`To fix this, please install '@react-native-vector-icons/material-design-icons'.\n\n` +
8670
`You can also use another method to specify icon: https://callstack.github.io/react-native-paper/docs/guides/icons`
8771
);
8872

src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,4 @@ export type { Props as SegmentedButtonsProps } from './components/SegmentedButto
137137
export type { Props as ListImageProps } from './components/List/ListImage';
138138
export type { Props as TooltipProps } from './components/Tooltip/Tooltip';
139139

140-
export { TypescaleKey, type Theme, type Elevation } from './types';
140+
export { type TypescaleKey, type Theme, type Elevation } from './types';

src/theme/schemes/DynamicTheme.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
export { DarkTheme as DynamicDarkTheme } from './DarkTheme';
22
export { LightTheme as DynamicLightTheme } from './LightTheme';
3+
4+
export const isDynamicColorSupported = false;

0 commit comments

Comments
 (0)