Skip to content

Commit 26e56c8

Browse files
authored
Merge pull request #1 from ilteoood/feat/ios-event-completition
feat(ios): event completition status
2 parents 07e2855 + 1743716 commit 26e56c8

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

CalendarManager/CalendarManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313

1414
@interface CalendarManager : NSObject <RCTBridgeModule, EKEventEditViewDelegate>
1515
@property (atomic, retain) EKEventStore *eventStore;
16+
@property (nonatomic, copy) RCTPromiseResolveBlock resolver;
1617
@end

CalendarManager/CalendarManager.m

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ + (BOOL)requiresMainQueueSetup
2323

2424
UIViewController *root = RCTPresentedViewController();
2525
[root presentViewController:editEventController animated:YES completion:nil];
26-
resolver(nil);
2726
});
28-
} rejecter:rejecter];
27+
} resolver:resolver rejecter:rejecter];
2928
}
3029

3130
#pragma mark - EventView delegate
@@ -46,11 +45,20 @@ - (EKEvent *)createEvent:(NSDictionary *)eventDetails {
4645
- (void)eventEditViewController:(EKEventEditViewController *)controller didCompleteWithAction:(EKEventEditViewAction)action
4746
{
4847
dispatch_async(dispatch_get_main_queue(), ^{
49-
[controller.presentingViewController dismissViewControllerAnimated:YES completion:nil];
48+
[controller.presentingViewController dismissViewControllerAnimated:YES completion:^{
49+
if (action == EKEventEditViewActionSaved) {
50+
self.resolver(@"EVENT_CREATED");
51+
} else if (action == EKEventEditViewActionDeleted) {
52+
self.resolver(@"EVENT_DELETED");
53+
} else {
54+
self.resolver(@"EVENT_CANCELLED");
55+
}
56+
}];
5057
});
5158
}
5259

53-
- (void)eventStoreHandler:(void (^)(void))completionBlock rejecter:(RCTPromiseRejectBlock)rejecter {
60+
- (void)eventStoreHandler:(void (^)(void))completionBlock resolver:(RCTPromiseResolveBlock)resolver rejecter:(RCTPromiseRejectBlock)rejecter {
61+
self.resolver = resolver;
5462
if (!self.eventStore) {
5563
[self initEventStoreWithCalendarCapabilities:completionBlock rejecter:rejecter];
5664
} else {
@@ -73,7 +81,7 @@ - (void)initEventStoreWithCalendarCapabilities:(void (^)(void))completionBlock r
7381
}
7482
}
7583

76-
- (void)handleEventStoreAccessWithGranted:(BOOL)granted error:(NSError *)error localEventStore:(EKEventStore *)localEventStore completionBlock:(void (^)(void))completionBlock rejecter:(RCTPromiseRejectBlock)rejecter
84+
- (void)handleEventStoreAccessWithGranted:(BOOL)granted error:(NSError *)error localEventStore:(EKEventStore *)localEventStore completionBlock:(void (^)(void))completionBlock rejecter:(RCTPromiseRejectBlock)rejecter
7785
{
7886
if (error) {
7987
rejecter(@"ERR_NO_PERMISSION", @"An error occurred during calendar access", error);

index.d.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ type Event = {
77
}
88

99
interface ReactNativeCalendarManager {
10-
addEvent(event: Event): Promise<void>;
10+
addEvent(event: Event): Promise<string | undefined>;
1111
}
1212

1313
const CalendarManager: ReactNativeCalendarManager;
@@ -17,4 +17,10 @@ export const ERRORS = {
1717
NO_PERMISSION: 'ERR_NO_PERMISSION',
1818
};
1919

20+
export const RESULTS = {
21+
EVENT_SAVED: 'EVENT_SAVED',
22+
EVENT_DELETED: 'EVENT_DELETED',
23+
EVENT_CANCELLED: 'EVENT_CANCELLED',
24+
}
25+
2026
export default CalendarManager;

index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ export const ERRORS = {
55
NO_PERMISSION: 'ERR_NO_PERMISSION',
66
};
77

8+
export const RESULTS = {
9+
EVENT_SAVED: 'EVENT_SAVED',
10+
EVENT_DELETED: 'EVENT_DELETED',
11+
EVENT_CANCELLED: 'EVENT_CANCELLED',
12+
}
13+
814
const CalendarManager = NativeModules.CalendarManager;
915

1016
export default CalendarManager;

0 commit comments

Comments
 (0)