Skip to content

feat: add day of the week and year repetition #325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 20, 2021
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,13 @@ request is an object containing:

request.repeatsComponent is an object containing (each field is optionnal):

- `year`: Will repeat every selected year in your fireDate.
- `month`: Will repeat every selected month in your fireDate.
- `day`: Will repeat every selected day in your fireDate.
- `dayOfWeek`: Will repeast every selected day of the week in your fireDate.
- `hour`: Will repeat every selected hour in your fireDate.
- `minute`: Will repeat every selected minute in your fireDate.
- `second`: Will repeat every selected second in your fireDate.
- `nanosecond`: Will repeat every selected nanosecond in your fireDate.

For example, let’s say you want to have a notification repeating every day at 23:54, starting tomorrow, you will use something like this:

Expand Down
10 changes: 5 additions & 5 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ PODS:
- React-cxxreact (= 0.64.2)
- React-jsi (= 0.64.2)
- React-perflogger (= 0.64.2)
- RNCPushNotificationIOS (1.8.0):
- RNCPushNotificationIOS (1.9.0):
- React-Core
- Yoga (1.14.0)
- YogaKit (1.18.1):
Expand Down Expand Up @@ -472,17 +472,17 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
boost-for-react-native: 39c7adb57c4e60d6c5479dd8623128eb5b3f0f2c
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
DoubleConversion: cf9b38bf0b2d048436d9a82ad2abe1404f11e7de
DoubleConversion: 5805e889d232975c086db112ece9ed034df7a0b2
FBLazyVector: e686045572151edef46010a6f819ade377dfeb4b
FBReactNativeSpec: 5f16d334c9fd49a492f4db708f24d207c39bb3ac
FBReactNativeSpec: 671da7bdb2a22799bfef695306097397b129ab9e
Flipper: d3da1aa199aad94455ae725e9f3aa43f3ec17021
Flipper-DoubleConversion: 38631e41ef4f9b12861c67d17cb5518d06badc41
Flipper-Folly: 755929a4f851b2fb2c347d533a23f191b008554c
Flipper-Glog: 1dfd6abf1e922806c52ceb8701a3599a79a200a6
Flipper-PeerTalk: 116d8f857dc6ef55c7a5a75ea3ceaafe878aadc9
Flipper-RSocket: 127954abe8b162fcaf68d2134d34dc2bd7076154
FlipperKit: 8a20b5c5fcf9436cac58551dc049867247f64b00
glog: 73c2498ac6884b13ede40eda8228cb1eee9d9d62
glog: 1f3da668190260b06b429bb211bfbee5cd790c28
hermes-engine: 7d97ba46a1e29bacf3e3c61ecb2804a5ddd02d4f
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
OpenSSL-Universal: 1aa4f6a6ee7256b83db99ec1ccdaa80d10f9af9b
Expand All @@ -509,7 +509,7 @@ SPEC CHECKSUMS:
React-RCTVibration: 24600e3b1aaa77126989bc58b6747509a1ba14f3
React-runtimeexecutor: a9904c6d0218fb9f8b19d6dd88607225927668f9
ReactCommon: 149906e01aa51142707a10665185db879898e966
RNCPushNotificationIOS: 61a7c72bd1ebad3568025957d001e0f0e7b32191
RNCPushNotificationIOS: 5bffde624d1fd15bfc8b2fd202b012a517a6dc9b
Yoga: 575c581c63e0d35c9a83f4b46d01d63abc1100ac
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

Expand Down
4 changes: 2 additions & 2 deletions example/ios/example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "arm64 i386";
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = i386;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
Expand Down Expand Up @@ -625,7 +625,7 @@
COPY_PHASE_STRIP = YES;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "arm64 i386";
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = i386;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
Expand Down
13 changes: 13 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,19 @@ export type NotificationRequest = {
* Must be used with fireDate.
*/
repeats?: boolean;
/**
* Define what components should be used in the fireDate during repeats.
* Must be used with repeats and fireDate.
*/
repeatsComponent?: {
year?: boolean;
month?: boolean;
day?: boolean;
dayOfWeek?: boolean;
hour?: boolean;
minute?: boolean;
second?: boolean;
};
/**
* Sets notification to be silent
*/
Expand Down
10 changes: 6 additions & 4 deletions ios/RCTConvert+Notification.m
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,13 @@ + (UNNotificationRequest *)UNNotificationRequest:(id)json
}

NSDictionary<NSString *, id> *userDateComps = [RCTConvert NSDictionary:details[@"repeatsComponent"]];
BOOL year = [RCTConvert BOOL:userDateComps[@"year"]];
BOOL month = [RCTConvert BOOL:userDateComps[@"month"]];
BOOL day = [RCTConvert BOOL:userDateComps[@"day"]];
BOOL dayOfWeek = [RCTConvert BOOL:userDateComps[@"dayOfWeek"]];
BOOL hour = [RCTConvert BOOL:userDateComps[@"hour"]];
BOOL minute = [RCTConvert BOOL:userDateComps[@"minute"]];
BOOL second = [RCTConvert BOOL:userDateComps[@"second"]];
BOOL nanosecond = [RCTConvert BOOL:userDateComps[@"nanosecond"]];

content.userInfo = [RCTConvert NSDictionary:details[@"userInfo"]];
if (!isSilent) {
Expand All @@ -129,7 +130,7 @@ + (UNNotificationRequest *)UNNotificationRequest:(id)json
}
} else {
content.sound = [RCTConvert NSString:details[@"sound"]] ? [UNNotificationSound soundNamed:[RCTConvert NSString:details[@"sound"]]] : [UNNotificationSound defaultSound];
}```
}
}

NSDate* fireDate = [RCTConvert NSDate:details[@"fireDate"]];
Expand All @@ -142,12 +143,13 @@ + (UNNotificationRequest *)UNNotificationRequest:(id)json
NSCalendarUnitMinute |
NSCalendarUnitSecond;
NSCalendarUnit repeatDateComponents =
(year ? NSCalendarUnitYear : 0) |
(month ? NSCalendarUnitMonth : 0) |
(day ? NSCalendarUnitDay : 0) |
(dayOfWeek ? NSCalendarUnitWeekday : 0) |
(hour ? NSCalendarUnitHour : 0) |
(minute ? NSCalendarUnitMinute : 0) |
(second ? NSCalendarUnitSecond : 0) |
(nanosecond ? NSCalendarUnitNanosecond : 0);
(second ? NSCalendarUnitSecond : 0);
NSDateComponents *triggerDate = fireDate
? [[NSCalendar currentCalendar]
components:(repeats ? repeatDateComponents : defaultDateComponents) | NSCalendarUnitTimeZone
Expand Down
3 changes: 2 additions & 1 deletion js/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ export type NotificationRequest = {|
* Must be used with repeats and fireDate.
*/
repeatsComponent?: {
year?: boolean,
month?: boolean,
day?: boolean,
dayOfWeek?: boolean,
hour?: boolean,
minute?: boolean,
second?: boolean,
nanosecond?: boolean,
},
/**
* Sets notification to be silent
Expand Down