react-native: [Android] Clipboard.getString() error: "...only one callback may be registered to a function in a native module."
I’m trying to use the Clipboard
module. It works fine in iOS, however, in Android I am getting the following error:
To test, I made a new React Native project and tried the following code:
// index.android.js
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Clipboard
} from 'react-native';
class clippy extends Component {
render() {
Clipboard.getString();
return (
<View>
<Text>
Welcome to React Native!
</Text>
</View>
);
}
}
AppRegistry.registerComponent('clippy', () => clippy);
And I am getting the same error.
Any thoughts?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 6
- Comments: 17 (3 by maintainers)
This is also happening to me, expect for a custom native module I developed, it seems to be related to passing in the promises reject and resolve block to a native method.
Edit: I was calling the reject callback twice, due to a badly formatted if let in swift. After fixing that error this error went away for me.
Well, turned out I was invoking the callback twice in the native method and thus the error.
This happens on android if you invoke the same Callback in native more than once.
but office doc say :“A native module is supposed to invoke its callback only once. It can, however, store the callback and invoke it later.”, how to fix it? I need to invoke the callback more than once…
Something similar also happened to our prod iOS app which is using 0.26.
The callback showActionSheetWithOptions() exists in module RCTActionSheetManager, but only one callback may be registered to a function in a native module.