react-native-date-picker icon indicating copy to clipboard operation
react-native-date-picker copied to clipboard

[Android] App crashes on release mode

Open fleuverouge opened this issue 3 years ago • 11 comments

Describe the bug App crashes when displaying the date picker modally on Android devices in release mode

Expected behavior App shouldn't crash

To Reproduce

export default class App extends Component {

  state = { date: new Date() }

  render = () =>
    <DatePicker
      date={this.state.date}
      onDateChange={date => this.setState({ date })}
      modal
                    theme="light"
                    mode={'date'}
                    locale="vi-VN"
                    cancelText="Bỏ qua"
                    confirmText="Xác nhận"
    />

}

Smartphone (please complete the following information):

  • OS: Android 9, 10, 13 (Google Pixel 5, Samsung Galaxy A8, A13, Oppo F9)
  • React Native version 0.70.6
  • react-native-date-picker version 4.2.13

Crash logs:

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Boolean.booleanValue()' on a null object reference at com.henninghall.date_picker.State.getTimeZone(State.java:8) at com.henninghall.date_picker.State.getMinimumDate(State.java:2) at com.henninghall.date_picker.wheels.YearWheel.getStartYear(YearWheel.java:2) at com.henninghall.date_picker.wheels.YearWheel.getValues(YearWheel.java:9) at com.henninghall.date_picker.wheels.Wheel.init(Wheel.java:11) at com.henninghall.date_picker.wheels.Wheel.refresh(Wheel.java:24) at com.henninghall.date_picker.wheelFunctions.Refresh.apply(Refresh.java) at com.henninghall.date_picker.ui.Wheels.applyOnAll(Wheels.java:20) at com.henninghall.date_picker.ui.UIManager.updateDisplayValues(UIManager.java:7) at com.henninghall.date_picker.PickerView.update(PickerView.java:206) at com.henninghall.date_picker.DatePickerModule.createPicker(:49) at com.henninghall.date_picker.DatePickerModule.openPicker() at java.lang.reflect.Method.invoke(Method.java) at com.facebook.react.bridge.JavaMethodWrapper.invoke(:148) at com.facebook.react.bridge.JavaModuleWrapper.invoke(:147) at com.facebook.jni.NativeRunnable.run(SourceFile) at android.os.Handler.handleCallback(Handler.java:942) at android.os.Handler.dispatchMessage(Handler.java:99) at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage() at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(:37) at java.lang.Thread.run(Thread.java:1012)

fleuverouge avatar May 10 '23 10:05 fleuverouge

I wonder how many apps are straight up broken because of this. We're seeing the same issue. Any known workarounds?

Joshuapwilley avatar May 19 '23 01:05 Joshuapwilley

Hi @Joshuapwilley Here's the patch I'm applying:

diff --git a/node_modules/react-native-date-picker/android/src/main/java/com/henninghall/date_picker/State.java b/node_modules/react-native-date-picker/android/src/main/java/com/henninghall/date_picker/State.java
index d8ea35f..5b986a7 100644
--- a/node_modules/react-native-date-picker/android/src/main/java/com/henninghall/date_picker/State.java
+++ b/node_modules/react-native-date-picker/android/src/main/java/com/henninghall/date_picker/State.java
@@ -24,6 +24,7 @@ import java.util.Calendar;
 import java.util.HashMap;
 import java.util.Locale;
 import java.util.TimeZone;
+import android.util.Log;
 
 public class State {
 
@@ -99,16 +100,23 @@ public class State {
         return Utils.isoToCalendar(maximumDateProp.getValue(), getTimeZone());
     }
 
+
     public TimeZone getTimeZone() {
-        Integer offset = timezoneOffsetInMinutesProp.getValue();
-        if(offset == null) return TimeZone.getDefault();
-        int totalOffsetMinutes = Math.abs(offset);
-        char offsetDirection = offset < 0 ? '-' : '+';
-        int offsetHours = (int) Math.floor(totalOffsetMinutes / 60f);
-        int offsetMinutes = totalOffsetMinutes - offsetHours * 60;
-        String timeZoneId = "GMT" + offsetDirection + offsetHours + ":" + Utils.toPaddedMinutes(offsetMinutes);
-        TimeZone zone = TimeZone.getTimeZone(timeZoneId);
-        return zone;
+        try {
+            Integer offset = timezoneOffsetInMinutesProp.getValue();
+            if(offset == null) return TimeZone.getDefault();
+            int totalOffsetMinutes = Math.abs(offset);
+            char offsetDirection = offset < 0 ? '-' : '+';
+            int offsetHours = (int) Math.floor(totalOffsetMinutes / 60f);
+            int offsetMinutes = totalOffsetMinutes - offsetHours * 60;
+            String timeZoneId = "GMT" + offsetDirection + offsetHours + ":" + Utils.toPaddedMinutes(offsetMinutes);
+            TimeZone zone = TimeZone.getTimeZone(timeZoneId);
+            return zone;
+        }
+        catch (Exception ex) {
+            Log.e("RNDatePicker", "getTimeZone() failed", ex);
+            return TimeZone.getDefault();
+        }
     }
 
     public String getIsoDate() {

fleuverouge avatar May 19 '23 02:05 fleuverouge

You are not using a valid combination of props, when using the modal you need to use onConfirm and onCancel, see example https://github.com/henninghall/react-native-date-picker#example-1-modal

If you still have this issue after adding those props, let us know and I'll reopen the issue.

henninghall avatar May 23 '23 17:05 henninghall

I have both props and had this issue. The proposed patch worked for me, however.

Joshuapwilley avatar May 23 '23 18:05 Joshuapwilley

Are you using proguard? In that case, have you added the lines as described in readme?

henninghall avatar May 23 '23 20:05 henninghall

I was able to reproduce this too when upgrading the library from 4.2.2 to 4.2.14, only on release mode on a physical device. I fixed it by downgrading from 4.2.14 to 4.2.2 to avoid patching this package.

aliraiki avatar Aug 28 '23 14:08 aliraiki

You are not using a valid combination of props, when using the modal you need to use onConfirm and onCancel, see example https://github.com/henninghall/react-native-date-picker#example-1-modal

If you still have this issue after adding those props, let us know and I'll reopen the issue.

Hi @henninghall Sorry for the late reply

I had all the required props, just deleted them when posting here because of some inner processing. I also updated the progard-rules as described in README.

fleuverouge avatar Sep 21 '23 03:09 fleuverouge

I was able to reproduce this too when upgrading the library from 4.2.2 to 4.2.14, only on release mode on a physical device. I fixed it by downgrading from 4.2.14 to 4.2.2 to avoid patching this package.

thank y, downgrade version helped me in my case.

DenisKenzo avatar Oct 17 '23 18:10 DenisKenzo

I was able to reproduce this too when upgrading the library from 4.2.2 to 4.2.14, only on release mode on a physical device. I fixed it by downgrading from 4.2.14 to 4.2.2 to avoid patching this package.

Downgrading to 4.2.2 helped me. In my case, the problem was related to the day picker re-rendering

bezuglyyvlad avatar Oct 17 '23 18:10 bezuglyyvlad

A similar issue was solved by clearing the cache on the phone for the specific app.

henninghall avatar Oct 24 '23 14:10 henninghall

A fix for this is released in 4.3.4. Let me know if you still are seeing this after that version update.

henninghall avatar Dec 07 '23 11:12 henninghall