How to fix two navigationcontainer conflict in react-native - react-native

I want to use the ZegoCloudUIkit for voice call so after setting up my project, I imported the ZegoCloudUIKit and applied it to my existing code. I runned it and was getting errors.
first error message:
Error: Looks like you have nested a 'NavigationContainer' inside another. Normally you need only one container at the root of the app, so this was probably an error. If this was intentional, pass 'independent={true}' explicitly. Note that this will make the child navigators disconnected from the parent and you won't be able to navigate between them.
so I commentted the navigationContainer Component that was nested to the ZegoUIkit component and I got a different error but the console did not through the error instead from the mobile app.
secode error message:
this is my App.tsx file
import React, {useEffect, useState} from 'react';
import {StyleSheet, View} from 'react-native';
import RNBootSplash from 'react-native-bootsplash';
import {toast, Toasts} from '#backpackapp-io/react-native-toast';
import {SafeAreaProvider} from 'react-native-safe-area-context';
import axios from 'axios';
import AsyncStorage from '#react-native-async-storage/async-storage';
import {useDispatch, useSelector} from 'react-redux';
import {
ZegoUIKitPrebuiltCallWithInvitation,
ZegoInvitationType,
ONE_ON_ONE_VIDEO_CALL_CONFIG,
ONE_ON_ONE_VOICE_CALL_CONFIG,
GROUP_VIDEO_CALL_CONFIG,
GROUP_VOICE_CALL_CONFIG,
} from '#zegocloud/zego-uikit-prebuilt-call-rn';
import ZegoUIKitSignalingPlugin from '#zegocloud/zego-uikit-signaling-plugin-rn';
import {zego_appid, zego_appkey} from '#env';
import Main from './src/Main';
import {GestureHandlerRootView} from 'react-native-gesture-handler';
import {returnListOfProviders} from './src/redux/provider/listProvider';
import {provider} from './src/apis/endpoints';
import {RootState} from './src/types/redux.type';
import whichSignedUser from './src/utils/whichSignedUser';
import IClientData from './src/interfaces/clientData';
import IProviderData from './src/interfaces/providerData';
import {
NavigationContainer,
useNavigation,
useNavigationContainerRef,
} from '#react-navigation/native';
import {isSigned} from './src/redux/auth/isSigned';
import ActivityLoader from './src/components/widgets/ActivityLoader';
import {INavigateProps} from './src/interfaces';
import {Text} from 'react-native-animatable';
const App = () => {
const dispatch = useDispatch();
React.useEffect(() => {
const init = async () => {
try {
// const response = await listProvider();
const response = await axios.get(provider);
await AsyncStorage.setItem(
'list_provider',
JSON.stringify(response.data)
);
dispatch(
returnListOfProviders(
JSON.parse(await AsyncStorage.getItem('list_provider'))
)
);
} catch (error) {
if (error.message === 'Network Error') {
toast('Network error!');
} else if (error.response) {
// Request made but the server responded with an error
toast('Ouch... Something went wrong.');
} else if (error.request) {
// Request made but no response is received from the server.
toast('Request exception: We are sorry for this!');
} else {
// Error occured while setting up the request
toast('An error occured!');
}
}
};
init().finally(async () => {
await RNBootSplash.hide({fade: true});
});
}, [dispatch]);
return (
<SafeAreaProvider>
<GestureHandlerRootView style={styles.container}>
<ZegoUIKitPrebuiltCallWithInvitation
independent
appSign={zego_appkey}
appID={zego_appid}
userID={'ALi'}
callID={'ALi'}
userName={'ALi'}
// callID={userData?.id}
// userID={userData?.phone_number} // userID can be something like a phone number or the user id on your own user system.
// userName={`${userData?.first_name} ${userData?.last_name}`}
ringtoneConfig={{
incomingCallFileName: 'zego_incoming.mp3',
outgoingCallFileName: 'zego_outgoing.mp3',
}}
requireConfig={(data: any) => {
const config =
data.invitees.length > 1
? ZegoInvitationType.videoCall === data.type
? GROUP_VIDEO_CALL_CONFIG
: GROUP_VOICE_CALL_CONFIG
: ZegoInvitationType.videoCall === data.type
? ONE_ON_ONE_VIDEO_CALL_CONFIG
: ONE_ON_ONE_VOICE_CALL_CONFIG;
return config;
}}
// config={{
// ...ONE_ON_ONE_VOICE_CALL_CONFIG,
// onOnlySelfInRoom: () => {
// navigate('drawer_nav');
// },
// onHangUp: () => {
// navigate('drawer_nav');
// },
// }}
plugins={[ZegoUIKitSignalingPlugin]} // The signaling plug-in used for call invitation must be set here.
>
{/* <NavigationContainer> */}
<Main />
<Toasts />
{/* </NavigationContainer> */}
</ZegoUIKitPrebuiltCallWithInvitation>
</GestureHandlerRootView>
</SafeAreaProvider>
);
};
const styles = StyleSheet.create({
container: {flex: 1},
});
export default App;
while these are the project dependencies:
"dependencies": {
"#backpackapp-io/react-native-toast": "^0.8.0",
"#react-native-async-storage/async-storage": "^1.17.10",
"#react-native-community/picker": "^1.8.1",
"#react-navigation/bottom-tabs": "^6.3.3",
"#react-navigation/drawer": "^6.4.4",
"#react-navigation/material-top-tabs": "^6.2.4",
"#react-navigation/native": "^6.1.2",
"#react-navigation/native-stack": "^6.9.8",
"#reduxjs/toolkit": "^1.8.6",
"#types/react-native-vector-icons": "^6.4.12",
"#zegocloud/zego-uikit-prebuilt-call-rn": "^1.3.1",
"#zegocloud/zego-uikit-rn": "^1.4.10",
"#zegocloud/zego-uikit-signaling-plugin-rn": "^1.0.4",
"axios": "0.26.0",
"react": "18.1.0",
"react-delegate-component": "^1.0.0",
"react-native": "0.70.0",
"react-native-animatable": "^1.3.3",
"react-native-bootsplash": "^4.3.2",
"react-native-calendars": "^1.1289.0",
"react-native-date-picker": "^4.2.5",
"react-native-document-picker": "^8.1.1",
"react-native-dotenv": "^3.4.2",
"react-native-gesture-handler": "^2.8.0",
"react-native-image-picker": "^4.10.1",
"react-native-kommunicate-chat": "^1.6.8",
"react-native-pager-view": "^6.0.2",
"react-native-push-notification-popup": "^1.6.1",
"react-native-quick-base64": "^2.0.5",
"react-native-reanimated": "^2.10.0",
"react-native-safe-area-context": "^4.4.1",
"react-native-screens": "^3.18.2",
"react-native-select-dropdown": "^2.0.4",
"react-native-sound": "^0.11.2",
"react-native-tab-view": "^3.1.1",
"react-native-vector-icons": "^9.2.0",
"react-redux": "^8.0.4",
"zego-express-engine-reactnative": "^3.1.2",
"zego-zim-react-native": "^2.5.0"
},
other info:
info Fetching system and libraries information...
System:
OS: Linux 5.15 Zorin OS 16.2
CPU: (4) x64 Intel(R) Core(TM) i5-7200U CPU # 2.50GHz
Memory: 3.45 GB / 7.53 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.18.1 - /tmp/yarn--1673425542734-0.8217341778464808/node
Yarn: 1.22.19 - /tmp/yarn--1673425542734-0.8217341778464808/yarn
npm: 9.2.0 - ~/.nvm/versions/node/v16.18.1/bin/npm
Watchman: Not Found
SDKs:
Android SDK: Not Found
IDEs:
Android Studio: Not Found
Languages:
Java: 17.0.5 - /usr/bin/javac
npmPackages:
#react-native-community/cli: Not Found
react: 18.1.0 => 18.1.0
react-native: 0.70.0 => 0.70.0
npmGlobalPackages:
*react-native*: Not Found
I am trying to achieve something similar to the article here.
In my case I want to have a one_on_one_voice_call where a caller can invite the other person on a call.

Related

Invariant Violation: requireNativeComponent: "RNSScreen" was not found in the UIManager. DUPLICATE

I have tried every solution that is being provided from this Invariant Violation: requireNativeComponent: "RNSScreen" was not found in the UIManager which the duplicate of my question. Yet, none of it works. BTW I am working on android, not on IOS so 'pod install' would not work for me.
I get this error when I tired implementing react native navigation from this source: https://reactnavigation.org/docs/hello-react-navigation
"dependencies": {
"#react-native-community/masked-view": "^0.1.11",
"#react-navigation/native": "^6.0.2",
"#react-navigation/stack": "^6.0.7",
"react": "17.0.1",
"react-native": "0.64.2",
"react-native-gesture-handler": "^1.10.3",
"react-native-safe-area-context": "^3.2.0",
"react-native-screens": "^3.4.0"
}
// App.js
import React from 'react';
import { StyleSheet} from 'react-native';
import ProductLists from './screen/ProductLists.js';;
import { NavigationContainer } from '#react-navigation/native';
import { createStackNavigator } from '#react-navigation/stack';
const Stack = createStackNavigator();
const App = () => {
return (
<NavigationContainer>
<Stack.Navigator initialRouteName={ProductLists}>
<Stack.Screen name="Home" component={ProductLists} />
</Stack.Navigator>
</NavigationContainer>
)
}
export default App;
P.S. I have tried following this too, still getting the same errors: https://reactnative.dev/docs/0.64/navigation

React.createElement: type is invalid -- expected a string [Expo42 - React Navigation 4]

I just updated my project from expo 39 to 42. The project use React Navigation 4.
Before the update everything worked and now I get the annoying error:
Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite
components) but got: undefined. You likely forgot to export your
component from the file it's defined in, or you might have mixed up
default and named imports.
Check your code at App.js:89.
in App (created by ExpoRoot)
in ExpoRoot (at renderApplication.js:45)
in RCTView (at View.js:34)
in View (at AppContainer.js:106)
in DevAppContainer (at AppContainer.js:121)
in RCTView (at View.js:34)
in View (at AppContainer.js:132)
in AppContainer (at renderApplication.js:39)
App.js
import React from 'react';
import { StyleSheet, View } from 'react-native';
import { GlobalColor } from './src/config/helpers';
import { AppContainer } from './src/config/navigation.js';
import { AppLoading } from 'expo';
import { Asset } from 'expo-asset';
import * as Font from 'expo-font';
function cacheImages(images) {
return images.map(image => {
if (typeof image === 'string') {
return Image.prefetch(image);
} else {
return Asset.fromModule(image).downloadAsync();
}
});
}
function cacheFonts(fonts) {
return fonts.map(font => Font.loadAsync(font));
}
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
isLoadingComplete: false,
};
}
async _loadAssetsAsync() {
const imageAssets = cacheImages([
...
]);
const fontAssets = cacheFonts([{
...
}]);
await Promise.all([...imageAssets, ...fontAssets]);
}
_handleLoadingError = error => {
// do something
};
_handleFinishLoading = () => {
this.setState({ isLoadingComplete: true });
};
componentDidMount() {}
render() {
if (!this.state.isLoadingComplete) {
return (
<AppLoading
startAsync={this._loadAssetsAsync}
onFinish={this._handleFinishLoading}
onError={this._handleLoadingError}
/>
);
} else {
return (
<View style={styles.container}>
<AppContainer />
</View>
);
}
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: GlobalColor.white,
justifyContent: 'center',
},
});
Navigation.js
import { ScreenWidth, EaseOutQuint } from '../config/helpers';
import { createAppContainer, createSwitchNavigator } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';
// Main Screens
import ...
// Account Screens
import ...
...
...
const AppStack = createSwitchNavigator({
SplashView : SplashView,
UserLoggedOut : OriginStack,
UserLoggedIn: MainStack,
},{
headerMode: 'none',
});
export const AppContainer = createAppContainer(AppStack);
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/netinfo": "6.0.0",
"expo": "^42.0.0",
"expo-haptics": "~10.1.0",
"firebase": "8.2.3",
"node-fetch": "^2.6.1",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-42.0.0.tar.gz",
"react-native-gesture-handler": "~1.10.2",
"react-native-page-control": "^1.1.1",
"react-native-reanimated": "~2.2.0",
"react-native-web": "^0.17.1",
"react-native-webview": "11.6.2",
"react-navigation": "^4.0.1",
"react-navigation-stack": "^1.5.4"
},
"devDependencies": {
"babel-eslint": "^10.1.0",
"babel-preset-expo": "8.3.0",
"eslint": "^6.8.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-plugin-import": "^2.24.0",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-react": "^7.24.0",
"eslint-plugin-react-hooks": "^1.7.0"
},
"private": true
}
AppLoading didn't update to the latest version so had to run
expo install expo-app-loading
and then change the import
import AppLoading from 'expo-app-loading';
Try installing the following dependencies
npm i expo-asset
npm i expo-font
The error message says:
Warning: React.createElement: type is invalid -- expected a string
(for built-in components) or a class/function (for composite
components) but got: undefined.
This means that a component is being referenced but doesn't exist (henced the undefined, when React tries to validate the type).
The error message also points to line 89 of App.js. See what code is there and trace it from there.
Check that whatever component referenced there is exported/imported properly. If the component in turn contains other imported components, check that these are too.
Most of the time, this is due to an incorrect export/import, but there a few other reasons that could also cause this error:
Conflict with a file of the same name as the component, but different file extension.
In that case, specify the extension in the import statement.
Improperly passing a component as properties.
In that case, check that you're passing the component with the correct syntax, and inspect the component beforehand to check that it's the correct type.

react-redux-firebase Firestore not ever loading the data

I have a react-native app that is using react-redux-firebase, react-native-firebase to connect to a firestore to return some todo records. There are records in the store, however all that is displayed is the "loading" text. It never updates the todos.
I have tried connecting directly within the app and it works fine so I'm assuming that firebase is configured correctly.
this.ref.get().then((querySnapshot) => {
console.log("ListItemFS: started query snapshot", querySnapshot);
this.handleSnapshot(querySnapshot);
});
This is my App.tsx
import React from 'react'
import { Provider } from 'react-redux'
import { ReactReduxFirebaseProvider } from 'react-redux-firebase';
import firebase from 'react-native-firebase'
import { createStore, compose } from 'redux'
import { composeWithDevTools } from "redux-devtools-extension";
import { createFirestoreInstance, firestoreReducer } from 'redux-firestore'
import { combineReducers } from 'redux';
import { firebaseStateReducer } from 'react-redux-firebase'
import Todos from './Todos';
//Configure firebase
const fbConfig = {
userProfile: 'users',
useFirestoreForProfile: true, // Firestore for Profile instead of Realtime DB,
enableLogging: true
}
//firebase.initializeApp(fbConfig) // <- I have tried with and without this with no difference.
//let db = firebase.firestore(); makes no difference
//Configure reducers
const rootReducer = combineReducers({
firebase:firebaseStateReducer,
firestore: firestoreReducer
})
// Configure store
const store = createStore(rootReducer, compose(composeWithDevTools()))
export default () => (
<Provider store={store}>
<ReactReduxFirebaseProvider
firebase={firebase}
config={fbConfig}
dispatch={store.dispatch}
createFirestoreInstance={createFirestoreInstance}
>
<Todos />
</ReactReduxFirebaseProvider>
</Provider>
)
This is my TODO component
import React from 'react'
import { connect } from 'react-redux'
import { compose } from 'redux'
import { isLoaded, isEmpty } from 'react-redux-firebase/lib/helpers'
import { View ,Text} from 'react-native'
import { firestoreConnect } from 'react-redux-firebase'
function Todos({ todos, firebase, state }) {
console.log("ToDos",todos);
console.log("state",state);
if (!isLoaded(todos)) {
return <Text>Loading...</Text>
}
if (isEmpty(todos)) {
return <Text>Todos List Is Empty</Text>
}
return (
<View>
{
Object.keys(todos).map(
(key, id) => (
<Text >First Key:{todos[key]}</Text>
)
)
}
</View>
)
}
export default compose(
firestoreConnect(() => [
{ collection: 'todos' } //'todos' // { path: '/todos' } // neither works
]),
connect(state => ({
todos: state.firestore.data.todos
// profile: state.firebase.profile // load profile
}))
)(Todos)
The following are my dependencies
"dependencies": {
"expo": "^34.0.1",
"fbjs": "^1.0.0",
"react": "16.8.3",
"react-dom": "16.8.3",
"react-native": "0.59.10",
"react-native-firebase": "5.2.0",
"react-native-gesture-handler": "~1.3.0",
"react-native-reanimated": "~1.1.0",
"react-native-router-flux": "^4.1.0-beta.8",
"react-native-screens": "1.0.0-alpha.22",
"react-native-size-matters": "^0.2.1",
"react-native-unimodules": "~0.5.2",
"react-native-web": "^0.11.4",
"react-navigation-deprecated-tab-navigator": "^1.3.0",
"react-redux": "^5.0.6",
"react-redux-firebase": "^3.0.0-beta.2",
"recompose": "^0.30.0",
"redux": "3.x.x",
"redux-devtools-extension": "^2.13.8",
"redux-firestore": "^0.8.0"
}
If you have any suggestions on what I've done wrong I would be really grateful.
Try to add
import 'react-native-firebase/firestore'
in your App.tsx

Expo, React Native AsyncStorage not resolving Promise

React Native's AsyncStorage is never resolving its promise. Here's the code :
import {Component} from 'react';
import React from 'react';
import {AsyncStorage} from 'react-native';
export default class Session extends Component {
componentDidMount() {
console.log('foo');
debugger; // This hits
AsyncStorage.getItem('token').then(() => {
console.log('baz');
debugger; // This never hits
}).catch(() => {
console.log('catch');
debugger; // This never hits
});
debugger; // This hits
console.log('bar');
}
render() {
return (
<React.Fragment>
{this.props.children}
</React.Fragment>
);
}
}
The componentDidMount method logs "foo" and "bar" but not "baz" or "catch"
I'm running this on a GenyMotion Android Emulator.
The behavior is the same whether I'm in remote debug mode or not.
Here's my package.json deps:
"dependencies": {
"#expo/samples": "2.1.1",
"eslint-plugin-react-native": "^3.2.1",
"expo": "29.0.0",
"prop-types": "^15.6.2",
"ramda": "^0.25.0",
"react": "16.3.1",
"react-connect-context": "^1.1.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-29.0.0.tar.gz",
"react-native-elements": "^1.0.0-beta5",
"react-navigation": "^2.9.3",
"styled-components": "^3.4.2"
}
This is an existing issue with react native. We experienced the same problem a few months ago. Since we were using Expo, we decided to use Expo SecureStore instead of AsyncStorage, and it was fine for our requirements.
More info on the issue can be found here. The title of the issue says that it only happens when remote debugging, but if you look at the comments it happens whether remote debugging or not.

Issues with upgrading to React Native 0.26

I'm in a bind , I don't know how to debug this issue as the app fails before the debugger is available.
It all started when I tried to upgrade to React Native 0.26 ( upgrading to 0.29 would be a huge change set to for our codebase, so doing this in multiple steps).
I have followed the documentation to import Component from react and the rest from react-native
I have updated to the latest dependencies or atleast as far as the modules support 0.26
However I'm seeing the Module AppRegistry is not a registered callable module. and I cannot attach a debugger (I hope I'm mistaken here). I have searched the code base and there are no components that use AppRegistry.
Here's the package.json
{
"name": "MyProjectName",
"version": "1.2.0",
"private": true,
"dependencies": {
"code-push": "^1.8.0-beta",
"dateformat": "^1.0.12",
"jasmine-core": "^2.4.1",
"key-mirror": "^1.0.1",
"numeral": "^1.5.3",
"react": "15.0.2",
"react-addons-update": "15.0.2",
"react-mixin": "^3.0.3",
"react-native": "^0.26.3",
"react-native-code-push": "^1.10.0-beta",
"react-native-collapsible": "^0.7.0",
"react-native-custom-action-sheet": "0.0.11",
"react-native-datetime": "0.1.2",
"react-native-dismiss-keyboard": "^1.0.0",
"react-native-drawer": "^2.2.6",
"react-native-fabric": "0.0.2",
"react-native-loading-spinner-overlay": "^0.1.1",
"react-native-onesignal": "^1.1.5",
"react-native-picker-android": "^1.0.2",
"react-native-tab-navigator": "^0.3.2",
"react-redux": "^4.4.0",
"react-timer-mixin": "^0.13.3",
"realm": "^0.14.1",
"redux": "^3.5.2",
"redux-logger": "^2.6.1",
"validator": "^5.4.0"
},
"devDependencies": {}
}
Here's the index.ios.js (the android version is also the exact same thing)
'use strict';
import React, { Component } from 'react';
import {
StyleSheet,
Text,
View,
Navigator,
} from 'react-native';
import { Provider } from 'react-redux';
import configureStore from './lib/store/configureStore';
import App from './lib/app';
class MyProjectName extends Component {
constructor(props) {
super(props);
}
render() {
let store = configureStore({});
return (
<Provider store={store}>
<App {...this.props}/>
</Provider>
);
}
componentWillMount() {
}
componentDidMount(){
// const CodePush = require('react-native-code-push');
// wait for 3 seconds otherwise rollback this change
// CodePush.sync({ rollbackTimeout: 3000 });
}
}
module.exports = MyProjectName;
Any hints on how to solve this ?
I got this message when a module in node_modules was still requiring React from react-native.
I would suggest going through all of your react native modules and looking for the ones which still use:
var React = require('react-native');
and replace them with:
import React from 'react';
And similarly import react native modules from react-native