Я новичок в React Native. В то время как я разрабатывал собственный модуль, у меня возникла проблема с обратными вызовами. Ниже приведено сообщение об ошибке от React Native
02-05 17:43:26.387 32301-32570/com.awesomeproject2 E/ReactNativeJNI: Got JS Exception: Exception calling object as function: abc,function f1() {
_ToastExample2.default.show('1111', _ToastExample2.default.SHORT);
},72,73 is not usable as a native method argument (<unknown file>:1845)
02-05 17:43:26.387 32301-32570/com.awesomeproject2 E/ReactNativeJNI: Got JS Stack: invariant@http://localhost:8081/index.delta?platform=android&dev=true&minify=false:1838:26
enqueueNativeCall@http://localhost:8081/index.delta?platform=android&dev=true&minify=false:2259:20
fn@http://localhost:8081/index.delta?platform=android&dev=true&minify=false:1999:40
onBtnPress@http://localhost:8081/index.delta?platform=android&dev=true&minify=false:58362:32
proxiedMethod@http://localhost:8081/index.delta?platform=android&dev=true&minify=false:34324:37
proxiedMethod@[native code]
touchableHandlePress@http://localhost:8081/index.delta?platform=android&dev=true&minify=false:37170:47
touchableHandlePress@[native code]
_performSideEffectsForTransition@http://localhost:8081/index.delta?platform=android&dev=true&minify=false:36821:36
_performSideEffectsForTransition@[native code]
_receiveSignal@http://localhost:8081/index.delta?platform=android&dev=true&minify=false:36754:46
_receiveSignal@[native code]
touchableHandleResponderRelease@http://localhost:8081/index.delta?platform=android&dev=true&
02-05 17:43:26.393 32301-32570/com.awesomeproject2 E/unknown:ReactNative: Exception in native call
java.lang.RuntimeException: Error calling RCTEventEmitter.receiveTouches
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
at android.os.Looper.loop(Looper.java:135)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:194)
at java.lang.Thread.run(Thread.java:818)
Caused by: com.facebook.jni.CppException: Exception calling object as function: abc,function f1() {
_ToastExample2.default.show('1111', _ToastExample2.default.SHORT);
},72,73 is not usable as a native method argument (<unknown file>:1845)
... 7 more
И мой родной модуль выглядит так
@ReactMethod
public void testCallback(String message, Callback c1, Callback c2, Callback c3) {
if (message.equals("123")) {
c1.invoke(message);
} else if (message.equals("abc")) {
c2.invoke(message);
} else {
c3.invoke(message);
}
}
И моя функция вызова от реакции
onBtnPress() {
function f1 () {
ToastExample.show('1111', ToastExample.SHORT);
};
function f2 () {
ToastExample.show('2222', ToastExample.SHORT);
};
function f3 () {
ToastExample.show('3333', ToastExample.SHORT);
};
ToastExample.testCallback('abc', f1, f2, f3);
}
Я понятия не имею, почему эта ошибка происходит, может кто-нибудь мне помочь? Благодарю.
Я также получил сообщение об ошибке " is not usable as a native method argument
", потому что я прокомментировал и/или удалил метод render()
компонента, как показано ниже, например:
import React from 'react';
import Reinput from 'reinput'
export default class TextField extends Reinput {
//render() {
// return (
// <>
// {super.render()}
// </>
// );
//}
}
Примечание. Я использовал Inheritance для создания подкласса, основанного на существующем компоненте, и думал, что метод
render()
базового класса будет использоваться, если я не переопределю его. (в то время я не знал, что мы можем использовать<>
и</>
)
Invariant Violation: Invariant Violation: [25,"AndroidTextInput",71,{"autoCapitalize":16384,"allowFontScaling":true,"onContentSizeChange":true,"onSelectionChange":true,"onScroll":true,"color":-65536,"height":"<<NaN>>","textAlignVertical":"top","underlineColorAndroid":0,"mostRecentEventCount":0,"text":""}] is not usable as a native method argument
This error is located at:
in AndroidTextInput (at TextInput.js:1193)
in TouchableWithoutFeedback (at TextInput.js:1211)
in TextInput (at Input.js:82)
in RCTView (at View.js:45)
in View (at Input.js:76)
in RCTView (at View.js:45)
in View (at Input.js:75)
in RCTView (at View.js:45)
in View (at Input.js:73)
in ReinputInput (at login.view.tsx:42)
in RCTView (at View.js:45)
in View (at login.view.tsx:32)
in LoginView (at SceneView.js:9)
in SceneView (at StackViewLayout.js:786)
in RCTView (at View.js:45)
in View (at StackViewLayout.js:785)
in RCTView (at View.js:45)
in View (at StackViewLayout.js:784)
in RCTView (at View.js:45)
in View (at createAnimatedComponent.js:151)
in AnimatedComponent (at StackViewCard.js:69)
in RCTView (at View.js:45)
in View (at createAnimatedComponent.js:151)
in AnimatedComponent (at screens.native.js:59)
in Screen (at StackViewCard.js:57)
in Card (at createPointerEventsContainer.js:27)
in Container (at StackViewLayout.js:862)
in RCTView (at View.js:45)
in View (at screens.native.js:83)
in ScreenContainer (at StackViewLayout.js:313)
in RCTView (at View.js:45)
in View (at createAnimatedComponent.js:151)
in AnimatedComponent (at StackViewLayout.js:309)
in PanGestureHandler (at StackViewLayout.js:302)
in StackViewLayout (at withOrientation.js:30)
in withOrientation (at StackView.js:79)
in RCTView (at View.js:45)
in View (at Transitioner.js:214)
in Transitioner (at StackView.js:22)
in StackView (at createNavigator.js:61)
in Navigator (at createKeyboardAwareNavigator.js:12)
in KeyboardAwareNavigator (at createAppContainer.js:387)
in NavigationContainer (at App.tsx:42)
in App (at renderApplication.js:35)
in RCTView (at View.js:45)
in View (at AppContainer.js:98)
in RCTView (at View.js:45)
in View (at AppContainer.js:115)
in AppContainer (at renderApplication.js:34)
This error is located at:
in NavigationContainer (at App.tsx:42)
in App (at renderApplication.js:35)
in RCTView (at View.js:45)
in View (at AppContainer.js:98)
in RCTView (at View.js:45)
in View (at AppContainer.js:115)
in AppContainer (at renderApplication.js:34)
enqueueNativeCall
D:\my-app\node_modules\react-native\Libraries\ART\ReactNativeART.js:292:16
fn
D:\my-app\node_modules\react-native\Libraries\Components\ActivityIndicator\ActivityIndicator.js:111
createInstance
D:\my-app\node_modules\react-native\Libraries\Lists\VirtualizedList.js:666:4
completeWork
D:\my-app\node_modules\react\cjs\react.development.js:624:26
completeUnitOfWork
D:\my-app\node_modules\prop-types\factoryWithTypeCheckers.js:162:34
performUnitOfWork
D:\my-app\node_modules\prop-types\factoryWithTypeCheckers.js:325:9
workLoop
D:\my-app\node_modules\prop-types\factoryWithTypeCheckers.js:333:8
renderRoot
performWorkOnRoot
D:\my-app\node_modules\react-native\Libraries\Utilities\MatrixMath.js:142:21
performWork
D:\my-app\node_modules\react-native\Libraries\Utilities\MatrixMath.js:47:27
performSyncWork
D:\my-app\node_modules\react-native\Libraries\Utilities\deprecatedPropType.js:22:68
requestWork
scheduleWork
scheduleRootUpdate
D:\my-app\node_modules\react-native\Libraries\Utilities\MatrixMath.js:537:16
render
D:\my-app\node_modules\react-native\Libraries\Renderer\oss\ReactNativeRenderer-dev.js:737:20
renderApplication
D:\my-app\node_modules\react-native\Libraries\Components\Picker\PickerAndroid.android.js:106:11
run
runApplication
D:\my-app\node_modules\react-native\Libraries\YellowBox\Data\YellowBoxWarning.js:56:4
__callFunction
D:\my-app\node_modules\react-native\Libraries\ART\ReactNativeART.js:389:6
<unknown>
D:\my-app\node_modules\react-native\Libraries\ART\ReactNativeART.js:156:4
__guard
D:\my-app\node_modules\react-native\Libraries\ART\ReactNativeART.js:342:13
callFunctionReturnFlushedQueue
D:\my-app\node_modules\react-native\Libraries\ART\ReactNativeART.js:157:6
callFunctionReturnFlushedQueue
[native code]
У меня такое же исключение с 3 обратными вызовами. Если вы используете один или два обратных вызова, он отлично работает
@ReactMethod public void testCallback (сообщение String, обратный вызов c1, обратный вызов c2)
работает