Skip to content

Commit

Permalink
fix: drop usage of __expo (#2420)
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Dec 14, 2020
1 parent c17e157 commit 3c8ac3f
Show file tree
Hide file tree
Showing 7 changed files with 1,052 additions and 70 deletions.
6 changes: 5 additions & 1 deletion example/metro.config.js
Expand Up @@ -7,7 +7,11 @@ const pak = require('../package.json');

const root = path.resolve(__dirname, '..');

const modules = ['@expo/vector-icons', ...Object.keys(pak.peerDependencies)];
const modules = [
'@expo/vector-icons',
'expo-constants',
...Object.keys(pak.peerDependencies),
];

module.exports = {
projectRoot: __dirname,
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -78,6 +78,7 @@
"eslint-config-callstack-io": "^1.1.1",
"eslint-plugin-prettier": "^3.0.0",
"eslint-plugin-react-native": "^3.5.0",
"expo-constants": "^9.3.5",
"flow-bin": "0.92.0",
"glob": "^7.1.3",
"husky": "^1.3.1",
Expand Down
74 changes: 30 additions & 44 deletions src/components/MaterialCommunityIcon.tsx
Expand Up @@ -16,54 +16,40 @@ try {
MaterialCommunityIcons = require('react-native-vector-icons/MaterialCommunityIcons')
.default;
} catch (e) {
if (
// @ts-ignore
global.__expo &&
// @ts-ignore
global.__expo.Icon &&
// @ts-ignore
global.__expo.Icon.MaterialCommunityIcons
) {
// Snack doesn't properly bundle vector icons from subpath
// Use icons from the __expo global if available
// @ts-ignore
MaterialCommunityIcons = global.__expo.Icon.MaterialCommunityIcons;
} else {
let isErrorLogged = false;
let isErrorLogged = false;

// Fallback component for icons
// @ts-ignore
MaterialCommunityIcons = ({ name, color, size, ...rest }) => {
/* eslint-disable no-console */
if (!isErrorLogged) {
if (
!/(Cannot find module|Module not found|Cannot resolve module)/.test(
e.message
)
) {
console.error(e);
}

console.warn(
`Tried to use the icon '${name}' in a component from 'react-native-paper', but 'react-native-vector-icons' 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.`
);

isErrorLogged = true;
// Fallback component for icons
// @ts-ignore
MaterialCommunityIcons = ({ name, color, size, ...rest }) => {
/* eslint-disable no-console */
if (!isErrorLogged) {
if (
!/(Cannot find module|Module not found|Cannot resolve module)/.test(
e.message
)
) {
console.error(e);
}

return (
<Text
{...rest}
style={[styles.icon, { color, fontSize: size }]}
// @ts-ignore
pointerEvents="none"
>
</Text>
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.`
);
};
}

isErrorLogged = true;
}

return (
<Text
{...rest}
style={[styles.icon, { color, fontSize: size }]}
// @ts-ignore
pointerEvents="none"
>
</Text>
);
};
}

export const accessibilityProps =
Expand Down
7 changes: 7 additions & 0 deletions src/constants.expo.tsx
@@ -0,0 +1,7 @@
import { Platform } from 'react-native';
import Constants from 'expo-constants';

export const APPROX_STATUSBAR_HEIGHT = Platform.select({
android: Constants.statusBarHeight,
ios: Platform.Version < 11 ? Constants.statusBarHeight : 0,
});
13 changes: 0 additions & 13 deletions src/constants.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/constants.tsx
@@ -0,0 +1 @@
export const APPROX_STATUSBAR_HEIGHT = 0;

0 comments on commit 3c8ac3f

Please sign in to comment.