UNPKG

2.52 kBJavaScriptView Raw
1function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
3import * as React from 'react';
4import { StyleSheet, Text, Platform } from 'react-native';
5let MaterialCommunityIcons;
6
7try {
8 // Optionally require vector-icons
9 MaterialCommunityIcons = require('react-native-vector-icons/MaterialCommunityIcons').default;
10} catch (e) {
11 let isErrorLogged = false; // Fallback component for icons
12
13 MaterialCommunityIcons = _ref => {
14 let {
15 name,
16 color,
17 size,
18 ...rest
19 } = _ref;
20
21 /* eslint-disable no-console */
22 if (!isErrorLogged) {
23 if (!/(Cannot find module|Module not found|Cannot resolve module)/.test(e.message)) {
24 console.error(e);
25 }
26
27 console.warn(`Tried to use the icon '${name}' in a component from 'react-native-paper', but 'react-native-vector-icons/MaterialCommunityIcons' could not be loaded.`, `To remove this warning, try installing 'react-native-vector-icons' or use another method to specify icon: https://callstack.github.io/react-native-paper/icons.html.`);
28 isErrorLogged = true;
29 }
30
31 return /*#__PURE__*/React.createElement(Text, _extends({}, rest, {
32 style: [styles.icon, {
33 color,
34 fontSize: size
35 }] // @ts-expect-error: Text doesn't support this, but it seems to affect TouchableNativeFeedback
36 ,
37 pointerEvents: "none",
38 selectable: false
39 }), "\u25A1");
40 };
41}
42
43export const accessibilityProps = Platform.OS === 'web' ? {
44 role: 'img',
45 focusable: false
46} : {
47 accessibilityElementsHidden: true,
48 importantForAccessibility: 'no-hide-descendants'
49};
50
51const defaultIcon = _ref2 => {
52 let {
53 name,
54 color,
55 size,
56 direction,
57 allowFontScaling
58 } = _ref2;
59 return /*#__PURE__*/React.createElement(MaterialCommunityIcons, _extends({
60 allowFontScaling: allowFontScaling,
61 name: name,
62 color: color,
63 size: size,
64 style: [{
65 transform: [{
66 scaleX: direction === 'rtl' ? -1 : 1
67 }],
68 lineHeight: size
69 }, styles.icon],
70 pointerEvents: "none",
71 selectable: false
72 }, accessibilityProps));
73};
74
75const styles = StyleSheet.create({
76 icon: {
77 backgroundColor: 'transparent'
78 }
79});
80export default defaultIcon;
81//# sourceMappingURL=MaterialCommunityIcon.js.map
\No newline at end of file