I'm a newbie in react-native. I'm adding one feature in react-native to an existing swift application. I presented the RCTRootview
from my native view controller. From there when user clicks on back button I have to go to Homepage which is written in swift. How do I communicate from react-native to native application code. Can someone please help me with this scenerio. I stuck at this point from last 2 days. Thanks in advance.
Asked
Active
Viewed 1,770 times
4

Sivajee Battina
- 4,124
- 2
- 22
- 45
-
Did you figure this out? I have a similar issue and any help would be great! – Aayush Chadha Jun 08 '18 at 13:04
-
2Possible duplicate of [React-Native iOS - How can I navigate to a non-React-Native view (native iOS view controller) from a React-Native view with a button press?](https://stackoverflow.com/questions/45741903/react-native-ios-how-can-i-navigate-to-a-non-react-native-view-native-ios-vie) – darkheartfelt Aug 15 '18 at 17:21
-
2Hey @darkheartfelt Did you see that date when he answered from the link you shared? I answered this first. Then how come this became duplicate? The link you shared should be the duplicate of this? – Sivajee Battina Aug 18 '18 at 06:14
1 Answers
-3
Yes. I found out the answer for this. It is all possible with RCTBridgeModule. This piece of code illustrate how to do that.
#import "CalendarManager.h"
#import <React/RCTLog.h>
@implementation CalendarManager
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(addEvent:(NSString *)name location:(NSString *)location)
{
RCTLogInfo(@"Pretending to create an event %@ at %@", name, location);
}
Now, from your JavaScript file you can call the method like this:
import {NativeModules} from 'react-native';
var CalendarManager = NativeModules.CalendarManager;
CalendarManager.addEvent('Birthday Party', '4 Privet Drive, Surrey');
Please follow the below official link about the concept and how to do it.

Sivajee Battina
- 4,124
- 2
- 22
- 45