Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CalendarManager/CalendarManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@

@interface CalendarManager : NSObject <RCTBridgeModule, EKEventEditViewDelegate>
@property (atomic, retain) EKEventStore *eventStore;
@property (nonatomic, copy) RCTPromiseResolveBlock resolver;
@end
18 changes: 13 additions & 5 deletions CalendarManager/CalendarManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ + (BOOL)requiresMainQueueSetup

UIViewController *root = RCTPresentedViewController();
[root presentViewController:editEventController animated:YES completion:nil];
resolver(nil);
});
} rejecter:rejecter];
} resolver:resolver rejecter:rejecter];
}

#pragma mark - EventView delegate
Expand All @@ -46,11 +45,20 @@ - (EKEvent *)createEvent:(NSDictionary *)eventDetails {
- (void)eventEditViewController:(EKEventEditViewController *)controller didCompleteWithAction:(EKEventEditViewAction)action
{
dispatch_async(dispatch_get_main_queue(), ^{
[controller.presentingViewController dismissViewControllerAnimated:YES completion:nil];
[controller.presentingViewController dismissViewControllerAnimated:YES completion:^{
if (action == EKEventEditViewActionSaved) {
self.resolver(@"EVENT_CREATED");
} else if (action == EKEventEditViewActionDeleted) {
self.resolver(@"EVENT_DELETED");
} else {
self.resolver(@"EVENT_CANCELLED");
}
}];
});
}

- (void)eventStoreHandler:(void (^)(void))completionBlock rejecter:(RCTPromiseRejectBlock)rejecter {
- (void)eventStoreHandler:(void (^)(void))completionBlock resolver:(RCTPromiseResolveBlock)resolver rejecter:(RCTPromiseRejectBlock)rejecter {
self.resolver = resolver;
if (!self.eventStore) {
[self initEventStoreWithCalendarCapabilities:completionBlock rejecter:rejecter];
} else {
Expand All @@ -73,7 +81,7 @@ - (void)initEventStoreWithCalendarCapabilities:(void (^)(void))completionBlock r
}
}

- (void)handleEventStoreAccessWithGranted:(BOOL)granted error:(NSError *)error localEventStore:(EKEventStore *)localEventStore completionBlock:(void (^)(void))completionBlock rejecter:(RCTPromiseRejectBlock)rejecter
- (void)handleEventStoreAccessWithGranted:(BOOL)granted error:(NSError *)error localEventStore:(EKEventStore *)localEventStore completionBlock:(void (^)(void))completionBlock rejecter:(RCTPromiseRejectBlock)rejecter
{
if (error) {
rejecter(@"ERR_NO_PERMISSION", @"An error occurred during calendar access", error);
Expand Down
8 changes: 7 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type Event = {
}

interface ReactNativeCalendarManager {
addEvent(event: Event): Promise<void>;
addEvent(event: Event): Promise<string | undefined>;
}

const CalendarManager: ReactNativeCalendarManager;
Expand All @@ -17,4 +17,10 @@ export const ERRORS = {
NO_PERMISSION: 'ERR_NO_PERMISSION',
};

export const RESULTS = {
EVENT_SAVED: 'EVENT_SAVED',
EVENT_DELETED: 'EVENT_DELETED',
EVENT_CANCELLED: 'EVENT_CANCELLED',
}

export default CalendarManager;
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ export const ERRORS = {
NO_PERMISSION: 'ERR_NO_PERMISSION',
};

export const RESULTS = {
EVENT_SAVED: 'EVENT_SAVED',
EVENT_DELETED: 'EVENT_DELETED',
EVENT_CANCELLED: 'EVENT_CANCELLED',
}

const CalendarManager = NativeModules.CalendarManager;

export default CalendarManager;