Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: drop usage of __expo #2420

Merged
merged 1 commit into from
Dec 14, 2020
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
6 changes: 5 additions & 1 deletion example/metro.config.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const APPROX_STATUSBAR_HEIGHT = 0;
Loading