Can't find variable DeviceEventEmitter - android

I am implementing the react-native-push-notification package in react-native.
In the example on the link: https://github.com/zo0r/react-native-push-notification#2-specify-handlers-for-the-notification-actions.
Error is displayed: Can't find variable: DeviceEventEmitter.
What can I do?

You need to import the DeviceEventEmitter from 'react-native'
import { DeviceEventEmitter } from 'react-native';

Related

How do I use realm with react-native correctly?

I have a "small" problem trying to use realm in combination with my react-native app.
I just started with react native and I have installed and updated everything I need for development.
I installed first realm with the command
npm install realm
after that I followed the tutorial given by MongoDB.
But all I get is this error:
Unexpected identifier 'realm'. Expected ';' after variable declaration
After that I tried to look at a template provided by #realm/react.
I installed it and started to build the aplication on my phone via react-native run-android
But I get the exact same error without changing anything.
does realm only work with a specific version of react-native?
or am I doing somthing wrong?
I am getting that error even by just declaring a scheme.
import React, { useState } from 'react';
import { View, Text, StyleSheet, TouchableOpacity,ScrollView, Image, Alert } from 'react-native';
import { NavigationContainer } from '#react-navigation/native';
import { createStackNavigator, TransitionPresets, CardStyleInterpolators } from '#react-navigation/stack';
import { Icon, Button } from "#rneui/themed";
import { styles } from './CSS/style';
import Realm from "realm";
const TaskSchema = {
name: "Task",
properties: {
_id: "int",
name: "string",
status: "string?",
},
primaryKey: "_id",
};

React native RecordScreen Native Module is null

I want to use RecordScreen NativeModule in my react native app.
import {NativeModules} from 'react-native'
console.log(NativeModules) // This is empty {}
console.log(NativeModules.RecordScreen) // This is null
Currently I'm testing on android device yarn android build.
What is the reason for NativeModules is empty and NativeModules.RecordScreen is null ?
import {requireNativeComponent} from 'react-native';
const RecordComponent = requireNativeComponent('RecordComponent')
console.log(RecordComponent);
Try this instead
or if you wish to use the same one you can also do it like this:
import NativeModules from 'react-native'

Material Ui - Uncaught Error: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function

When I am loading this LoginScreen.js I m getting the above mentioned exception.
Before that I had installed
npm install #material-ui/core
import React from 'react';
import {Button} from '#material-ui/core/Button';
import { View } from 'react-native';
export default function LoginScreen() {
return (
<View>
<Button></Button>
</View>
);
}
You need to import differently. Try as the following:
import Button from '#material-ui/core/Button';
// or
import { Button } from '#material-ui/core';
Check from the official documentation here: Button API - Import.
I hope this helps!

react-native import component from another component

i have project in react-native and its ok , my problem is when i tried to import component in another component its failed but when import at index.android.js its ok why ??
index.android.js
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
TextInput,
TouchableOpacity,
ToastAndroid,
ListView,
Navigator,
} from 'react-native';
import LoginView from './App/LoginView';
its ok but when tried to import the same in another screen like this
import React, { Component } from 'react';
import {
StyleSheet,
ToolbarAndroid
,AppRegistry,
View,
Text,
TouchableHighlight,
TextInput,
ListView,ActionButton,
Image
} from 'react-native';
import LoginView from './App/LoginView';
export default class MyOrders extends Component
{
i got this error , "Ruquring unknown module if you are sure the module is there try to restarting the packeger or running npm install" ????
Possible cause may be relative path('./App/LoginView') could be wrong with respect to the component while importing.Try updating the relative path accordingly.After updating stop the react-native dev server and again start it using react-native start.
Let us consider that you are importing AboutUs page in index.ios.js
by using the following
var AboutUs = require('./Views/AboutUs');
AboutUs.js is located in "Views" directory which is located in place where index.ios.js page located. And in AboutUs.js page you have to export the component by
module.exports = AboutUs;
Where,
class AboutUs extends Component {
.....
}

Android sensor manager-react native error

I need to access accelerometer in my react native app. Apparently the only one for Android is this one and it does not work. Ive even tried it on a separate clean project and still shows undefined is not an object (evaluating mSensorManager.startAccelerometer). I'm using the sample code provided in readme, What am I doing wrong?
PS: I'm using an actual device, not a VM.
The problem is solved here. I added to MainActivity.java following code:
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.sensormanager.SensorManagerPackage;
import java.util.Arrays;
import java.util.List;
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new SensorManagerPackage()
);
}
Make sure to follow the steps in the README file.
after you do the npm i react-native-sensor-manager --save ,
instead of doing rnpm link , my approach was to do react-native link react-native-sensor-manager and you are done.
import it using import { SensorManager } from 'NativeModules'
It would definitely work.

Categories

Resources