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.
-
Did you figure this out? I have a similar issue and any help would be great!Aayush Chadha– Aayush Chadha2018-06-08 13:04:30 +00:00Commented Jun 8, 2018 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?darkheartfelt– darkheartfelt2018-08-15 17:21:14 +00:00Commented Aug 15, 2018 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– Sivajee Battina2018-08-18 06:14:19 +00:00Commented Aug 18, 2018 at 6:14
Add a comment
|
1 Answer
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.