Skip to content

Commit 268b7bb

Browse files
committed
docs: fix vector icons on snack.expo.io. fixes #675
1 parent da9f234 commit 268b7bb

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

src/components/Icon.js

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,29 @@ try {
1010
// Optionally require vector-icons
1111
MaterialIcons = require('react-native-vector-icons/MaterialIcons').default;
1212
} catch (e) {
13-
MaterialIcons = ({ name, color, size, ...rest }) => {
14-
// eslint-disable-next-line no-console
15-
console.warn(
16-
`Tried to use the icon '${name}' in a component from 'react-native-paper', but 'react-native-vector-icons' is not installed. To remove this warning, install 'react-native-vector-icons' or use another method to specify icon: https://callstack.github.io/react-native-paper/icons.html.`
17-
);
18-
19-
return (
20-
<Text
21-
{...rest}
22-
style={[styles.icon, { color, fontSize: size }]}
23-
pointerEvents="none"
24-
>
25-
26-
</Text>
27-
);
28-
};
13+
if (global.__expo && global.__expo.Icon && global.__expo.Icon.MaterialIcons) {
14+
// Snack doesn't properly bundle vector icons from subpath
15+
// Use icons from the __expo global if available
16+
MaterialIcons = global.__expo.Icon.MaterialIcons;
17+
} else {
18+
// Fallback component for icons
19+
MaterialIcons = ({ name, color, size, ...rest }) => {
20+
// eslint-disable-next-line no-console
21+
console.warn(
22+
`Tried to use the icon '${name}' in a component from 'react-native-paper', but 'react-native-vector-icons' is not installed. To remove this warning, install 'react-native-vector-icons' or use another method to specify icon: https://callstack.github.io/react-native-paper/icons.html.`
23+
);
24+
25+
return (
26+
<Text
27+
{...rest}
28+
style={[styles.icon, { color, fontSize: size }]}
29+
pointerEvents="none"
30+
>
31+
32+
</Text>
33+
);
34+
};
35+
}
2936
}
3037

3138
type IconSourceBase = string | ImageSource;

0 commit comments

Comments
 (0)