Skip to content

Instantly share code, notes, and snippets.

@himelnagrana
Created January 3, 2018 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save himelnagrana/e8678737333925baf75c2200626c65d1 to your computer and use it in GitHub Desktop.
Save himelnagrana/e8678737333925baf75c2200626c65d1 to your computer and use it in GitHub Desktop.
iOS Native Modules
#import <React/RCTBridgeModule.h>
@interface CalendarManager : NSObject <RCTBridgeModule>
@end
#import "CalendarManager.h"
#import <React/RCTLog.h>
@implementation CalendarManager
RCT_EXPORT_MODULE(EmpManCalendarManager); // for naming the module as CalendarManager just use `RCT_EXPORT_MODULE();`
RCT_EXPORT_METHOD(addEvent:(NSString *)name location:(NSString *)location)
{
RCTLogInfo(@"Pretending to create an event %@ at %@", name, location);
}
@end
/**
* This exposes the native EmpManCalendarManager module as a JS module. This has a
* function 'addEvent' which takes the following parameters:
*
* 1. String name: A string for event name
* 2. string location: A string for event location
*/
import {NativeModules} from 'react-native';
module.exports = NativeModules.EmpManCalendarManager;
import EmpManCalendarManager from './EmpManCalendarManager';
if (Platform.OS == "ios") {
EmpManCalendarManager.addEvent('Birthday Party', '4 Privet Drive, Surrey');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment