Importing NativeModules from react-native on Android - react-native

I'm trying to import some native modules in my application.
In index.js I'm trying to do:
import { AppRegistry, NativeModules } from 'react-native';
The, I want to use my my module:
const { NetworkListenerModule } = NativeModules;
However, NativeModules is undefined so does NetworkListenerModule.
It does work in iOS, but I can't make it work on Android for some reason and I don't have any clue for what's wrong.

Related

Why am I getting this error if I am importing Navigator library in react native?

I am using react native under expo and have installed the required dependencies to install navigator. This is my code:
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View, SafeAreaView } from 'react-native';
import Landing from './components/Landing';
import Beach from './components/Beach';
import { createStackNavigator } from '#react-navigation/stack';
export default function App() {
return (
<Landing></Landing>
);
}
If I compile this, I am getting this error:
Error: [BABEL] G:\IntrotoIT\beach-app\node_modules\#react-navigation\stack\src\index.tsx: You gave us a visitor for the node type TSInstantiationExpression but it's not a valid type
at verify (C:\Users\Lenovo\AppData\Roaming\npm\node_modules\expo-cli\node_modules\#babel\traverse\lib\visitors.js:108:13)
at Function.explode (C:\Users\Lenovo\AppData\Roaming\npm\node_modules\expo-cli\node_modules\#babel\traverse\lib\visitors.js:30:3)
at C:\Users\Lenovo\AppData\Roaming\npm\node_modules\expo-cli\node_modules\#babel\core\lib\config\full.js:269:42
at Generator.next (<anonymous>)
at Function.<anonymous> (C:\Users\Lenovo\AppData\Roaming\npm\node_modules\expo-cli\node_modules\#babel\core\lib\gensync-utils\async.js:24:3)
at Generator.next (<anonymous>)
at evaluateSync (C:\Users\Lenovo\AppData\Roaming\npm\node_modules\expo-cli\node_modules\gensync\index.js:251:28)
at Function.sync (C:\Users\Lenovo\AppData\Roaming\npm\node_modules\expo-cli\node_modules\gensync\index.js:89:14)
at sync (C:\Users\Lenovo\AppData\Roaming\npm\node_modules\expo-cli\node_modules\#babel\core\lib\gensync-utils\async.js:67:25)
I seriously don't have clue on how to fix it. Tried deleting node modules and then npm install but it was of no use.
Thanks

React Native Module not found: Can't resolve '#react-navigation/core' with react-native-router-flux

I have this basic React Native Code which fails to compile as soon as I import anything from react-native-router-flux. It throws Module not found: Can't resolve '#react-navigation/core'
If I uncomment line import { Router, Scene } from "react-native-router-flux";, everything works fine. I also manually did npm install #react-navigation/core but to no avail
import React from "react";
import { Router, Scene } from "react-native-router-flux";
class Index extends React.Component {
render() {
return <div></div>
}
}
export default Index;
What could I be missing?
Versions
React v17.0.2
react-native-router-flux v4.3.1
React-native v0.66.3
The latest react-native version (v0.66.3) is incompatible with react-native-router-flux (v4.3.1) which is pretty old. Its better to look for #react-navigation/native
Thanks #XplosiVe06 for pointing out

React Native BluetoothManager NativeModules NULL

I'm trying to use BluetoothManager in React Native, already did these steps:
I did fresh install with react-native init MyProject
Imported NativeMoludes in App.js: import { SafeAreaView, StyleSheet, ScrollView, View, Text, StatusBar, NativeModules } from 'react-native';
Initialized BluetoothManager: const { BluetoothManager} = NativeModules;
And do alert(BluetoothManager); before return(...)
but it always alerts null. Did I miss something in the RN installation or the import?
I'm using React Native v.0.62.2. Please advice.
I would advise using https://github.com/innoveit/react-native-ble-manager or https://github.com/Polidea/react-native-ble-plx for everything bluetooth related in react-native
You are not importing BluetoothManager properly, You have to install this module,
https://github.com/innoveit/react-native-ble-manager
Link that module(if the auto-linking is not available but or pod install in the case of ios) with your project and then import like below
import BleManager from 'react-native-ble-manager';
Also here is an example of import and usage too.
https://github.com/innoveit/react-native-ble-manager/blob/master/example/App.js

Remove warning viewPagerAndroid with react native 0.59.5

After upgrading to react native 0.59.5, the app threw the following warning message on simulator:
viewPagerAndroid has been extracted from react-native core...
But there is no import of the viewPagerAndroid in the component file:
import React, { Component} from 'react';
import { SectionList, View, StyleSheet, Text, TouchableOpacity, Platform, AppRegistry } from 'react-native';
import Moment from 'moment';
import DeviceInfo from 'react-native-device-info';
import { GiftedChat } from 'react-native-gifted-chat';
How to remove the warning?
As of react-native 0.59.0 ViewPagerAndroid has been deprecated. You can see that in the changelog here.
That means that if you want to use ViewPagerAndroid in the future you will need to install it separately. You can see its repo here
You are probably seeing this warning even though you haven’t explicitly used ViewPagerAndroid because one of the dependencies that you are using used it.
Most commonly react-native-gesture-handler or react-native-tab-view both use ViewPagerHandler.
At the moment the warning is just that, a warning. It isn’t going to cause you any issues until support for ViewPagerAndroid is dropped.
You can suppress the YellowBox warning so it won’t show on device. Note even if you suppress the warning it will always show in the logs.
Import it from react-native
import { YellowBox } from 'react-native';
Then in your App.js
YellowBox.ignoreWarnings(['ViewPagerAndroid']);
You can read more about suppressing warnings here

undefined is not an object ( evaluating 'react2.propTypes.oneOfTypes')

Getting
undefined is not an object ( evaluating '_react2.PropTypes.oneOfType')
While using react-native-camera .
using react-native-camera#0.6 with following react native version.
react-native-cli: 2.0.1
react-native: 0.55.2
What i tried inside app.js is
import React, { Component, PropTypes } from 'react';
and
import PropTypes from 'prop-types';
But not worked.
PropTypes package has been separated from react since v15.5 as mentioned here
Since you're using an older version of react-native-camera, therefore they contain old dependencies in their index.js
react-native-camera index.js v0.6 contains
import React, { Component, PropTypes } from 'react';
Therefore you need to update the package since they have major changes and revamped folder structure as seen in Camera.js