wmcmahan / react-native-calendar-events

📆 React Native Module for iOS and Android Calendar Events
MIT License
905 stars 292 forks source link

Patch for recurring events in Android #445

Closed LeandraH closed 11 months ago

LeandraH commented 1 year ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch react-native-calendar-events@2.2.0 for the project I'm working on.

My app would crash in Android whenever I tried to export recurring events that had an endDate (in the eventOptions, not in the recurrenceOptions). Looking into the package, I saw that there was a duration of one hour ("PT1H") being set. Removing that solved my issue, maybe some other people stumble upon the same one.

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-calendar-events/android/src/main/java/com/calendarevents/RNCalendarEvents.java b/node_modules/react-native-calendar-events/android/src/main/java/com/calendarevents/RNCalendarEvents.java
index 782a0da..4b43154 100644
--- a/node_modules/react-native-calendar-events/android/src/main/java/com/calendarevents/RNCalendarEvents.java
+++ b/node_modules/react-native-calendar-events/android/src/main/java/com/calendarevents/RNCalendarEvents.java
@@ -543,7 +543,6 @@ public class RNCalendarEvents extends ReactContextBaseJavaModule implements Perm

             if (recurrenceRule.hasKey("frequency")) {
                 String frequency = recurrenceRule.getString("frequency");
-                String duration = "PT1H";
                 Integer interval = null;
                 Integer occurrence = null;
                 String endDate = null;
@@ -555,10 +554,6 @@ public class RNCalendarEvents extends ReactContextBaseJavaModule implements Perm
                     interval = recurrenceRule.getInt("interval");
                 }

-                if (recurrenceRule.hasKey("duration")) {
-                    duration = recurrenceRule.getString("duration");
-                }
-
                 if (recurrenceRule.hasKey("occurrence")) {
                     occurrence = recurrenceRule.getInt("occurrence");
                 }
@@ -589,9 +584,6 @@ public class RNCalendarEvents extends ReactContextBaseJavaModule implements Perm
                 }

                 String rule = createRecurrenceRule(frequency, interval, endDate, occurrence, daysOfWeek, weekStart, weekPositionInMonth);
-                if (duration != null) {
-                    eventValues.put(CalendarContract.Events.DURATION, duration);
-                }
                 if (rule != null) {
                     eventValues.put(CalendarContract.Events.RRULE, rule);
                 }

This issue body was partially generated by patch-package.

Thanks again for the package!

LeandraH commented 11 months ago

It turns out there's an easier fix by adding duration: null to the recurrenceRule, as discussed in #159