henninghall / react-native-date-picker

React Native Date Picker is datetime picker for Android and iOS. It includes date, time and datetime picker modes. The datepicker is customizable and is supporting different languages. It's written with native code to achieve the best possible look, feel and performance.
MIT License
2.25k stars 346 forks source link

App crashes on onConfirm and onCancel method on android os 11 and 12 for RN 0.72 #752

Open Shweta-UMR opened 10 months ago

Shweta-UMR commented 10 months ago

Hello All, I am using datepicker for my app which is working fine in RN version 0.68. when i upgraded version to 0.72 it is crashing for android version 11 and 12. but working fine with version 13. Datepicker is showing properly but when i tries to click on onConfirm and onCancel method it existed app with showing crash. my code is as below.

 <DatePicker
        modal
        open={open}
        date={date}
        onConfirm={(date) => {
          setOpen(false)
          setDate(date)
        }}
        onCancel={() => {
          setOpen(false)
        }}
      />   

Help me Thanks

henninghall commented 10 months ago

Can you provide the stack trace of the crash? (found in android studio etc)

Shweta-UMR commented 10 months ago

@henninghall thanks for response, following is my stack log found in android studio

FATAL EXCEPTION: mqt_native_modules
    Process: com.exampleApp, PID: 27077
    android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
Antho2407 commented 10 months ago

@henninghall I think we are experiencing the same issue, quite rare but always caused by the date picker on Android :

Fatal Exception: android.view.ViewRootImpl$CalledFromWrongThreadException
Only the original thread that created a view hierarchy can touch its views.
vabruzzese commented 8 months ago

+1

nerioramirez17 commented 3 months ago

I have the same error, the onCancel and onConfirm only change the state. To replicate it locally, I did something like this:

const handleCancel = () => {
    throw new Error('Forced to crash');
    setVisible(false);
};

But I don't understand how it could crash for the user at that point. Any solution?