new NativeEventEmitter()는 필수 addListener 메서드 없이 null 이외의 인수를 사용하여 호출되었습니다.
나는 그 문제를 해결할 수 없다.응용 프로그램 로드가 네이티브 슬로우 경고를 반응할 때
WARN `new NativeEventEmitter()` was called with a non-null argument without the required `addListener` method.
WARN `new NativeEventEmitter()` was called with a non-null argument without the required `removeListeners` method.
이는 리액트 네이티브의 최신 버전이 원인일 수 있습니다.많은 라이브러리가 이러한 경고(또는 경우에 따라 오류)를 처리할 새 버전을 아직 출시하지 않았습니다.예를 들어 https://github.com/react-navigation/react-navigation/issues/9882 및 https://github.com/APSL/react-native-keyboard-aware-scroll-view/pull/501 등이 있습니다.문제가 있는 경우는, 일단 경고를 숨길 수 있습니다(소스).
import { LogBox } from 'react-native';
LogBox.ignoreLogs(['new NativeEventEmitter']); // Ignore log notification by message
LogBox.ignoreAllLogs(); //Ignore all log notifications
메인 자바 모듈에 두 가지 기능만 추가하면 됩니다.
// Required for rn built in EventEmitter Calls.
@ReactMethod
public void addListener(String eventName) {
}
@ReactMethod
public void removeListeners(Integer count) {
}
예: 경고 수정의 경우react-native-fs기능을 추가하다android/src/main/java/com/rnfs/RNFSManager.java파일.
Kotlin의 경우 다음 코드를 사용합니다.
@ReactMethod
fun addListener(type: String?) {
// Keep: Required for RN built in Event Emitter Calls.
}
@ReactMethod
fun removeListeners(type: Int?) {
// Keep: Required for RN built in Event Emitter Calls.
}
같은 에러입니다.
바꾸다
const eventEmitter = new NativeEventEmitter(NativeModules.CustomModule);
로.
const eventEmitter = new NativeEventEmitter();
작동하다
1- 리액트 리액트 리액트 리액트 리액트 리액트 리액트 리액트 리액트 리액트 리액트 리액트 리액트 리액트 리액트 리애니메이션 라이브러리를 "2.0.0"
2- babel.config.json 파일을 업데이트하고 react-native-renimated/plugin을 플러그인에 추가합니다.
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: [
"react-native-reanimated/plugin",
],
};
이것으로 문제가 해결됩니다.
내 경우 리액트 네이티브 로케이션 이너블러가 문제를 일으키고 있었다.
플랫폼 체크를 추가하고 iOS 전용이 아닌 안드로이드 전용의 "React-Native-Location-enabler" 특정 코드를 모두 실행했습니다.
이것으로 문제가 해결되었다.
리액트 네이티브 리애니메이션 라이브러리와 관련된 문제입니다.라이브러리를 언인스톨 하고 나서 재인스톨 하면 해결할 수 있습니다.https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/installation에서 제공하는 react-display-reanimated 라이브러리의 설치 절차를 모두 삭제합니다.
npm install react-native-reanimated@2.3.0-beta.1 명령을 사용하여 라이브러리를 설치합니다.
문제가 해결되지 않으면 Android Studio에서 프로젝트를 엽니다.file-> invalidate cache로 이동합니다.그 후에는 모든 것이 잘 된다.
경고는 명확합니다.필요하지 않은 매개 변수를 생성자에서 전달하고 있습니다.
변경:
const eventEmitter = new NativeEventEmitter(CustomModule);
로.
const eventEmitter = new NativeEventEmitter();
잘 될 거야.
Expo 사용자: @config-plugins/react-native-ble-plx를 버전 5.0.0으로 업그레이드하여 경고가 사라졌습니다.
@voximplant/react-native-forground-service를 사용하는 경우,node_modules/@voximplant/react-native-foreground-service/index.js타고
/*
* Copyright (c) 2011-2019, Zingaya, Inc. All rights reserved.
*/
'use strict';
import { NativeModules, NativeEventEmitter, Platform } from 'react-native';
const isIOS = Platform.OS === 'ios';
const isAndroid = Platform.OS === 'android';
const ForegroundServiceModule = NativeModules.VIForegroundService;
let EventEmitter;
if (isAndroid) {
EventEmitter = new NativeEventEmitter(ForegroundServiceModule);
}
/**
* @property {string} channelId - Notification channel id to display notification
* @property {number} id - Unique notification id
* @property {string} title - Notification title
* @property {string} text - Notification text
* @property {string} icon - Small icon name
* @property {number} [priority] - Priority of this notification. One of:
* 0 - PRIORITY_DEFAULT (by default),
* -1 - PRIORITY_LOW,
* -2 - PRIORITY_MIN,
* 1 - PRIORITY_HIGH,
* 2- PRIORITY_MAX
* @property {string} button - If this property exist, notification will be contain button with text as button value
*/
const NotificationConfig = {
};
/**
* @property {string} id - Unique channel ID
* @property {string} name - Notification channel name
* @property {string} [description] - Notification channel description
* @property {number} [importance] - Notification channel importance. One of:
* 1 - 'min',
* 2 - 'low' (by default),
* 3 - 'default',
* 4 - 'high',
* 5 - 'max'.
* @property {boolean} [enableVibration] - Sets whether notification posted to this channel should vibrate. False by default.
*/
const NotificationChannelConfig = {
};
class VIForegroundService {
static _serviceInstance = null;
_listeners = new Map();
/**
* @private
*/
constructor() {
if (isAndroid) {
EventEmitter.addListener('VIForegroundServiceButtonPressed', this._VIForegroundServiceButtonPressed.bind(this));
}
}
static getInstance() {
if (this._serviceInstance === null) {
this._serviceInstance = new VIForegroundService();
}
return this._serviceInstance;
}
/**
* Create notification channel for foreground service
*
* @param {NotificationChannelConfig} channelConfig - Notification channel configuration
* @return Promise
*/
async createNotificationChannel(channelConfig) {
if (isIOS) {
console.warn("ForegroundService may be used only Android platfrom.")
return;
}
return await ForegroundServiceModule.createNotificationChannel(channelConfig);
}
/**
* Start foreground service
* @param {NotificationConfig} notificationConfig - Notification config
* @return Promise
*/
async startService(notificationConfig) {
if (isIOS) {
console.warn("ForegroundService may be used only Android platfrom.")
return;
}
return await ForegroundServiceModule.startService(notificationConfig);
}
/**
* Stop foreground service
*
* @return Promise
*/
async stopService() {
if (isIOS) {
console.warn("ForegroundService may be used only Android platfrom.")
return;
}
return await ForegroundServiceModule.stopService();
}
/**
* Adds a handler to be invoked when button on notification will be pressed.
* The data arguments emitted will be passed to the handler function.
*
* @param event - Name of the event to listen to
* @param handler - Function to invoke when the specified event is emitted
*/
on(event, handler) {
if (isIOS) {
console.warn("ForegroundService may be used only Android platfrom.")
return;
}
if (!handler || !(handler instanceof Function)) {
console.warn(`ForegroundService: on: handler is not a Function`);
return;
}
if (!this._listeners.has(event)) {
this._listeners.set(event, new Set());
}
this._listeners.get(event)?.add(handler);
}
/**
* Removes the registered `handler` for the specified event.
*
* If `handler` is not provided, this function will remove all registered handlers.
*
* @param event - Name of the event to stop to listen to.
* @param handler - Handler function.
*/
off(event, handler) {
if (isIOS) {
console.warn("ForegroundService may be used only Android platfrom.")
return;
}
if (!this._listeners.has(event)) {
return;
}
if (handler && handler instanceof Function) {
this._listeners.get(event)?.delete(handler);
} else {
this._listeners.set(event, new Set());
}
}
/**
* @private
*/
_emit(event, ...args) {
const handlers = this._listeners.get(event);
if (handlers) {
handlers.forEach((handler) => handler(...args));
} else {
console.log(`[VIForegroundService]: _emit: no handlers for event: ${event}`);
}
}
/**
* @private
*/
_VIForegroundServiceButtonPressed(event) {
this._emit('VIForegroundServiceButtonPressed', event);
}
}
export default VIForegroundService;
솔루션은 이쪽
언급URL : https://stackoverflow.com/questions/69538962/new-nativeeventemitter-was-called-with-a-non-null-argument-without-the-requir
'programing' 카테고리의 다른 글
| XSLT는 JSON에 상당합니다. (0) | 2023.03.23 |
|---|---|
| jq 필터에 인수 전달 (0) | 2023.03.23 |
| Woocommerce - 고객이 특정 역할인 경우 다른 PayPal 이메일 주소를 설정합니다. (0) | 2023.03.23 |
| Java용 JWT(JSON Web Token) 라이브러리 (0) | 2023.03.23 |
| Java 8에서 Java 11로의 JAXWS 애플리케이션 이행 (0) | 2023.03.18 |