I recently set up react-native project with expo and later on I added #react-navigation packages.
It seems like this wasn't enough as NavigationContainer render complains about SafeAreaContext
I tried to install required packages with expo install react-native-safe-area-context ... but It didn't solve it.
Thought deleting node_modules && npm install could help, but it didn't work either.
There were related questions to this issue
, but they didn't provide much help
I will appreciate your help.
Here's what I get in android emulator
terminal
Unable to resolve "./SafeAreaContext" from "node_modules\react-native-safe-area-context\src\index.tsx"
Failed building JavaScript bundle.
App.tsx
import React, { useState } from 'react';
import { AppLoading } from 'expo'
import { View, Text } from 'react-native';
import { NavigationContainer } from '#react-navigation/native';
import { createBottomTabNavigator } from '#react-navigation/bottom-tabs';
import { createStackNavigator } from '#react-navigation/stack';
function Test() {
return (
<View
style={{ flex: 1, justifyContent: 'space-between', alignItems: 'center' }}
>
<Text>Test</Text>
</View>
);
}
const Stack = createStackNavigator();
const Tab = createBottomTabNavigator();
export default function App() {
const [loaded, setLoaded] = useState(false);
if(!loaded) {
return <AppLoading
startAsync={() => Promise.resolve()}
onFinish={() => setLoaded(true)}/>
}
return <NavigationContainer>
</NavigationContainer>
}
package.json
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject"
},
"dependencies": {
"#expo/vector-icons": "^10.2.0",
"#react-native-community/masked-view": "^0.1.6",
"#react-navigation/bottom-tabs": "^5.5.1",
"#react-navigation/native": "^5.5.0",
"#react-navigation/stack": "^5.4.1",
"expo": "^37.0.12",
"expo-asset": "^8.1.5",
"expo-constants": "^9.0.0",
"expo-linking": "^1.0.1",
"expo-splash-screen": "^0.2.3",
"expo-web-browser": "^8.2.1",
"react": "~16.9.0",
"react-dom": "~16.9.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz",
"react-native-gesture-handler": "~1.6.0",
"react-native-reanimated": "~1.7.0",
"react-native-safe-area-context": "0.7.3",
"react-native-safe-area-view": "^1.1.1",
"react-native-screens": "~2.2.0",
"react-native-web": "~0.11.7",
"react-redux": "^7.2.0",
"redux": "^4.0.5"
},
"devDependencies": {
"#babel/core": "^7.8.6",
"#types/react": "~16.9.23",
"#types/react-native": "~0.61.17",
"babel-preset-expo": "~8.1.0",
"typescript": "~3.8.3"
},
"private": true
}
Look like cleaning expo cache helped
expo r -c
expo r --help
Usage: start|r [options] [project-dir]
Starts or restarts a local server for your app and gives you a URL to it
Options:
-c, --clear Clear the Metro bundler cache
....
expo --version
3.21.3
Installing following two,
npm install --save #react-native-community/masked-view
npm install react-native-safe-area-context
it is work for me
Related
i followed a tutorial for adding web support using to a expo project **. using typescript, react-native-web and webpack. looks like it works for everyone. but for me, i get a blank web page after Web Bundling complete.
Started Metro Bundler
Web Bundling complete
even though it works just fine on the emulator. i get no error in the console.
package.json:
{
"name": "imibonano",
"version": "1.0.0",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject",
"test": "jest --watchAll",
"deploy": "gh-pages -d web-build",
"predeploy": "expo build:web",
"commit": "node scripts/github.js"
},
"dependencies": {
"#expo-google-fonts/poppins": "^0.2.2",
"#expo/webpack-config": "^0.16.24",
"#react-native-community/masked-view": "0.1.10",
"#react-native-community/slider": "4.2.1",
"#react-native-firebase/app": "^14.2.3",
"#react-native-picker/picker": "2.4.0",
"#react-navigation/bottom-tabs": "^6.0.9",
"#react-navigation/material-bottom-tabs": "^5.3.15",
"#react-navigation/native": "^6.0.6",
"#react-navigation/native-stack": "^6.2.5",
"#react-navigation/stack": "^6.0.11",
"dotenv": "^14.2.0",
"expo": "~45.0.0",
"expo-app-loading": "^2.0.0",
"expo-cli": "^5.4.8",
"expo-font": "~10.1.0",
"expo-google-app-auth": "^8.1.7",
"expo-linear-gradient": "~11.3.0",
"expo-modules-core": "~0.9.2",
"expo-splash-screen": "^0.15.1",
"expo-status-bar": "~1.3.0",
"firebase": "^9.6.4",
"jest": "^28.1.0",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-native": "0.68.2",
"react-native-custom-swiper": "^1.0.16",
"react-native-flipper": "^0.146.1",
"react-native-gesture-handler": " ~2.2.1",
"react-native-pager-view": "5.4.15",
"react-native-paper": "^4.7.2",
"react-native-reanimated": "~2.8.0",
"react-native-safe-area-context": "4.2.4",
"react-native-screens": "~3.11.1",
"react-native-swiper-flatlist": "^3.0.16",
"react-native-vector-icons": "^8.1.0",
"react-native-web": "0.17.7",
"react-native-web-swiper": "^2.2.2",
"react-query": "^3.39.1",
"react-query-native-devtools": "^4.0.0",
"react-redux": "^8.0.2"
},
"devDependencies": {
"#babel/core": "^7.12.9",
"#types/react": "~17.0.21",
"#types/react-native": "~0.66.13",
"ts-node": "^10.8.1",
"typescript": "^4.7.3"
},
"jest": {
"preset": "react-native",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
]
},
"private": true
}
app.tsx:
import { StatusBar } from "expo-status-bar";
import React from "react";
import NavigationStack from "./navigation/NavigationStack";
import Providers from "./navigation/index";
import useCachedResources from './hooks/useCachedResources';
import useColorScheme from './hooks/useColorScheme';
import AppLoading from 'expo-app-loading';
import { AuthProvider } from "./navigation/AuthProvider";
import { SafeAreaView, StyleSheet, Text } from "react-native";
import AppNavigation from './navigation';
import {
useFonts,
// Poppins_100Thin,
// Poppins_100Thin_Italic,
// Poppins_200ExtraLight,
// Poppins_200ExtraLight_Italic,
// Poppins_300Light,
// Poppins_300Light_Italic,
Poppins_400Regular,
// Poppins_400Regular_Italic,
Poppins_500Medium,
// Poppins_500Medium_Italic,
Poppins_600SemiBold,
// Poppins_600SemiBold_Italic,
// Poppins_700Bold,
// Poppins_700Bold_Italic,
// Poppins_800ExtraBold,
// Poppins_800ExtraBold_Italic,
// Poppins_900Black,
// Poppins_900Black_Italic
} from '#expo-google-fonts/poppins';
export default function App() {
const isLoadingComplete = useCachedResources();
const colorScheme = useColorScheme();
const [loaded] = useFonts({
title: require('./assets/fonts/klarissa.regular.ttf'),
Poppins_400Regular,
Poppins_600SemiBold,
Poppins_500Medium
});
if (!isLoadingComplete || !loaded) {
return <AppLoading />;
} else {
return <Providers />;
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#0a0a0a",
alignItems: "center",
justifyContent: "center",
}
})
index.js:
import React from "react";
import { SafeAreaView, StyleSheet, Text } from "react-native";
import { AuthProvider } from "./AuthProvider";
import NavigationStack from "./NavigationStack";
export default function Providers() {
return (
<AuthProvider>
<SafeAreaView style={styles.container}>
<NavigationStack />
</SafeAreaView>
</AuthProvider>
);
}
It looks like an easy question with an easy answer i.e.
npm install #react-native-community/checkbox
but it doesn't work. I had an error saying that the package had a dependency to react-native-windows, so I also downloaded this package which lead to not solving my issue.
I really don't get why it happens...
Here is my package.json:
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject"
},
"dependencies": {
"#react-native-community/checkbox": "^0.5.6",
"expo": "~39.0.2",
"expo-status-bar": "~1.0.2",
"moviedb-promise": "^3.1.2",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-image": "^4.0.3",
"react-native": "https://github.com/expo/react-native/archive/sdk-39.0.2.tar.gz",
"react-native-web": "~0.13.12",
"react-native-windows": "^1.0.0",
"react-tinder-card": "^1.3.1"
},
"devDependencies": {
"#babel/core": "~7.9.0"
},
"private": true
}
EDIT
Here is my code:
import React from 'react'
import { View, Text } from 'react-native';
import CheckBoxSetting from './CheckBoxSetting';
import PressableSetting from './PressableSetting'
import SwitchSetting from './SwitchSetting';
function SettingItemFactory () {
this.createSettingItem = function (name, type, initState) {
let settingItem = <Text/>;
switch(type){
case 'pressable':
settingItem = <PressableSetting title={name}/>;
break;
case 'switch':
settingItem = <SwitchSetting name={name} state={initState}/>
break;
case 'check':
settingItem = <CheckBoxSetting name={name} state={initState}/>
break;
default:
settingItem = <PressableSetting title={name} />;
}
return settingItem;
}
}
export default SettingItemFactory;
import React from 'react'
import {View, Text, ImagePropTypes} from 'react-native'
import CheckBox from '#react-native-community/checkbox'
const CheckBoxSetting = (props) => {
return (
<View>
<Text>
{props.name}
</Text>
</View>
)
}
export default CheckBoxSetting;
The answer was given by Tushar Khatiwada in the comments of the original post:
As of right now, the library isn't supported by expo. Thanks Tushar!
If you're using expo in your react native project, expo provides a Checkbox component that can be leveraged, and it appears to utilize the same API as the react-native CheckBox component. :)
https://docs.expo.io/versions/latest/sdk/checkbox/
It's not supported in the expo.
in react-native CLI, make sure linking is done and do pod install.
I've got a TypeScript function which returns a React Native View.
import React from "react";
import JSX, {View} from "react-native";
class DummyClass {
static getView() {
return (
<View style={{flex: 1}}/>
);
}
}
export default DummyClass;
And I'm calling this function in this way:
import JSX from "react-native";
import DummyClass from "./util/dummy";
const DummyWrapper = () => {
return (DummyClass.getView());
};
export default DummyWrapper;
And when I run eslint, I get a warning.
5:5 warning Missing return type on function #typescript-eslint/explicit-module-boundary-types
So, I need to be returning something. JSX.Element seems reasonable enough, but that doesn't seem to be working. For one, when I try to return a JSX.Element, VSCode can't resolve it and pretends it's any instead. And moreover, it causes errors in other places that call the function.
So, doing this:
static getView() : JSX.Element {
and const DummyWrapper = () : JSX.Element => {
Results in the following error in DummyCaller:
5:5 error Unsafe return of an any typed value #typescript-eslint/no-unsafe-return
So now I'm not sure exactly what to do. I've tried a few other things, such as returning View, typeof View, React.Component (and typeof), and a few other things. I've also messed around with where JSX is being imported from. If I import from react, it seems to work even worse than if I import it from react-native. Also in my research, I see the most common problem is that one's React and React Native types are out of date, but as far as I can tell, I'm on the most up-to-date versions.
My packages.json:
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject",
"lint": "eslint -c .eslintrc.js --ext .tsx ."
},
"dependencies": {
"#dudigital/react-native-zoomable-view": "^1.0.15",
"#react-native-community/masked-view": "^0.1.10",
"#react-navigation/native": "^5.7.6",
"#react-navigation/stack": "^5.9.3",
"#types/react-native-vector-icons": "^6.4.6",
"change-case": "^4.1.1",
"expo": "~39.0.2",
"expo-status-bar": "~1.0.2",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-39.0.2.tar.gz",
"react-native-gesture-handler": "^1.8.0",
"react-native-paper": "^4.2.0",
"react-native-reanimated": "^1.13.1",
"react-native-safe-area-context": "^3.1.8",
"react-native-screens": "^2.11.0",
"react-native-tab-view": "^2.15.2",
"react-native-vector-icons": "^7.1.0",
"react-native-web": "^0.13.18"
},
"devDependencies": {
"#babel/core": "~7.9.0",
"#types/jest": "^26.0.15",
"#types/react": "^16.9.53",
"#types/react-dom": "^16.9.8",
"#types/react-native": "^0.63.27",
"#types/react-navigation": "^3.4.0",
"#types/react-redux": "^7.1.9",
"#types/react-test-renderer": "^16.9.3",
"#typescript-eslint/eslint-plugin": "^4.5.0",
"#typescript-eslint/parser": "^4.5.0",
"commonjs": "latest",
"eslint": "^7.11.0",
"eslint-plugin-jsdoc": "^30.7.3",
"eslint-plugin-prefer-arrow": "^1.2.2",
"eslint-plugin-react": "^7.21.5",
"react-native-typescript-transformer": "^1.2.13",
"requirejs": "latest",
"ts-jest": "^26.4.1",
"tslib": "^2.0.3",
"typescript": "^4.0.3"
},
"private": true
}
React should be putting JSX into the global namespace, so if you don't import it from anywhere then returning JSX.Element should work.
You can also import {ReactElement} from "react" and return ReactElement.
You can also import {FunctionComponent} from "react" and type the DummyWrapper function itself, not the return type, as DummyWrapper: FunctionComponent<{}>.
There's a lot of options.
But I really do not understand the use case where you would be creating an element from a static method on a class. This seems like a bad design that you should rethink. Can you make getView into a function component? Do you need the class DummyClass at all?
I am trying to import a very old react-native project. I updated the expo version to 36 and updated almost the dependencies to the latest version. It was a working code but upon running now, I get the following error in the below line
Unexpected token (59:18)
57 | navigationOptions:{
58 | drawerLabel: "Change Format",
> 59 | drawerIcon: <Icon name="list" size={20} color={TXT_COLOR_PRIMARY} />,
| ^
60 | },
61 | },
62 | Stops :{
Failed building JavaScript bundle.
Please find my App.js file
{
"name": "AwesomeProject",
"version": "0.1.0",
"private": true,
"devDependencies": {
"babel-preset-env": "^1.7.0",
"flow-bin": "^0.41.0",
"jest-expo": "36.0.0",
"react-native-scripts": "^1.14.1",
"react-test-renderer": "16.3.0-alpha.1"
},
"main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
"scripts": {
"start": "react-native-scripts start",
"eject": "react-native-scripts eject",
"android": "react-native-scripts android",
"ios": "react-native-scripts ios",
"test": "jest",
"flow": "flow"
},
"jest": {
"preset": "jest-expo"
},
"dependencies": {
"core-js": "^3.6.4",
"create-react-class": "^15.6.3",
"eslint-cli": "^1.1.1",
"expo": "^36.0.0",
"material-ui": "^0.20.0",
"native-base": "^2.13.12",
"react": "^16.8.3",
"react-dom": "^16.4.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-36.0.0.tar.gz",
"react-native-audio-player-recorder-no-linking": "^1.0.2",
"react-native-elements": "^1.2.7",
"react-native-fetch-blob": "^0.10.8",
"react-native-file-uploader": "0.0.2",
"react-native-flexi-radio-button": "^0.2.2",
"react-native-material-buttons": "^0.6.0",
"react-native-material-ui": "^1.30.1",
"react-native-permissions": "^2.0.10",
"react-native-radio-button": "^2.0.1",
"react-native-simple-radio-button": "^2.7.4",
"react-native-sound": "^0.11.0",
"react-native-sound-player": "^0.10.4",
"react-native-sound-recorder": "^1.3.4",
"react-native-table-component": "^1.2.1",
"react-native-tts": "^3.1.1",
"react-native-upload-file": "^0.1.1",
"react-native-vector-icons": "^6.6.0",
"react-navigation": "^4.3.0",
"react-timer-mixin": "^0.13.4"
}
}
Import statements in App.js
import React from 'react';
import {View, Text, StyleSheet,Image, TouchableHighlight} from 'react-native';
import {Radio, Right, ListItem} from 'native-base';
import { Icon } from 'react-native-elements';
import { TextButton, RaisedTextButton } from 'react-native-material-buttons';
import { StackNavigator,DrawerNavigator } from 'react-navigation'; // Version can be specified in package.json
import { Button, ThemeProvider } from 'react-native-material-ui';
import HomeScreen from './Screens/HomeScreen';
import Screen2 from './Screens/Screen2';
import Screen3 from './Screens/Screen3';
import Screen4 from './Screens/Screen4';
import Settings from './Screens/Settings';
import Stop_Info_Screen from './Screens/Stop_Info_Screen';
import AboutUsScreen from './Screens/AboutUs';
import FeedbackScreen from './Screens/Feedback';
import DrawerContent from './Additional_Components/SideDrawer'
import styles from './Styles/commonStyles';
import {COLOR_PRIMARY,COLOR_SECONDARY,TXT_COLOR_PRIMARY,TXT_COLOR_SECONDARY,DARK_PRIMARY_COLOR} from './constants';
I started working on react native only from yesterday. I apologize if this is silly. I tried googling this but I believe it is a very generic error. Any help will be highly appreciated.
I am getting the following error on creating the navigation stack as follows:
Unable to resolve "./vendor/TransitionConfigs/CardStyleInterpolators" from "node_modules/react-navigation-stack/lib/module/index.js"
App.js:-
import React from "react";
import {createAppContainer,createSwitchNavigator} from "react-navigation";
import {createStackNavigator} from "react-navigation-stack";
import {createBottomTabNavigator} from "react-navigation-tabs";
import AccountScreen from "./src/screens/AccountScreen";
import SigninScreen ...... ;
const switchNavigator=createSwitchNavigator({
loginFlow:createStackNavigator({
Signin:SigninScreen,
Signup:SignupScreen
}),
mainFlow:createBottomTabNavigator({
trackListFlow:createStackNavigator({
TrackList:TrackListScreen,
TrackDetails:TrackDetailsScreen
}),
TrackCreate:TrackCreateScreen,
Account:AccountScreen
})
});
export default createAppContainer(switchNavigator);
I am using the following dependency version:-
Package.json:-
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject"
},
"dependencies": {
"expo": "~36.0.0",
"react": "~16.9.0",
"react-dom": "~16.9.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-36.0.0.tar.gz",
"react-native-gesture-handler": "^1.5.3",
"react-native-reanimated": "^1.4.0",
"react-native-web": "~0.11.7",
"react-navigation": "^4.0.10",
"react-navigation-stack": "^1.10.3",
"react-navigation-tabs": "^2.7.0"
},
"devDependencies": {
"babel-preset-expo": "~8.0.0",
"#babel/core": "^7.0.0"
},
"private": true
}
While bundling I am getting the following error although I am using stable version of all the dependencies...
You need to clear your metro Cache.
Since you're using Expo, first stop Expo server. Then run:
expo start -c
If you're not, run:
react-native start --reset-cache