I am successfully calling a JavaScript callback in a Swift native module in React Native. I need to pass data from the Native side back to React Native, but when the data is anything other than strings or numbers, the data parameter in the callback is null
. I need to pass back an array of objects as a parameter but for testing purposes I have created an instance of a Swift class:
func displayProviderDialog(_ mvpds: [Any]) {
class City: NSObject {
var name: String = "TEST STRING"
}
var city = City();
rNCallbacks.displayProviderDialogCallback([mvpds, city])
}
The in Typescript on the React Native side:
export function displayProviderDialog(MVPDs: unknown[], city: any) {
console.log(`${JSON.stringify(MVPDs)} >>>>>>>>>>>>> ${JSON.stringify(city)}}`
);
}
Both MVPDs
and city
are null
in React Native, but are not null in Swift / Xcode.
How can I pass back arrays and objects from Swift native modules to React Native?