Skip to content
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

Fix crash when attempting to show picker in different mode/style #829

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mattsellars123
Copy link

@mattsellars123 mattsellars123 commented Oct 18, 2023

Summary

After displaying a picker the first time in an app. The second time displaying if using countDownTimer may cause a crash depending on the picker state. Resetting the picker state before setting mode and style fixes the issue.

Stack trace:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UIDatePickerMode .countDownTimer is unsupported when using style .inline.' *** First throw call stack: ( 0 CoreFoundation 0x00000001804658a8 __exceptionPreprocess + 172 1 libobjc.A.dylib 0x000000018005c09c objc_exception_throw + 56 2 Foundation 0x0000000180cf3b90 -[NSMutableDictionary(NSMutableDictionary) classForCoder] + 0 3 UIKitCore 0x000000011c2e3728 _UIDatePickerClassForStyleAndMode + 460 4 UIKitCore 0x000000011c2e4010 -[UIDatePicker _updatePickerViewIfNecessary] + 60 5 UIKitCore 0x000000011c2e440c -[UIDatePicker setDatePickerMode:] + 68 6 0x0000000100ca4e88 -[RNDateTimePicker setDatePickerMode:] + 64 7 0x0000000100ca70a0 __RNDateTimePickerShadowViewMeasure_block_invoke <…>

  • How did you implement the solution?
    Reset mode to default then update style

  • What areas of the library does it impact?
    Only iOS UIDatePicker related

What are the steps to reproduce (after prerequisites)?

In our app a picker is shown with UIDatePickerMode that is not UIDatePickerModeCountDownTimer. Then attempting to display a picker else where in the app with the UIDatePickerModeCountDownTimer crashes the app.

Compatibility

OS Implemented
iOS
Android

Checklist

  • I have tested this on a device and a simulator

After displaying a picker the first time in an app. The second
time displaying if using countDownTimer may cause a crash depending
on the picker state. Resetting the picker state before setting mode
and style fixes the issue.

Stack trace:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UIDatePickerMode .countDownTimer is unsupported when using style .inline.' *** First throw call stack: ( 0   CoreFoundation                      0x00000001804658a8 __exceptionPreprocess + 172 1   libobjc.A.dylib                     0x000000018005c09c objc_exception_throw + 56 2   Foundation                          0x0000000180cf3b90 -[NSMutableDictionary(NSMutableDictionary) classForCoder] + 0 3   UIKitCore                           0x000000011c2e3728 _UIDatePickerClassForStyleAndMode + 460 4   UIKitCore                           0x000000011c2e4010 -[UIDatePicker _updatePickerViewIfNecessary] + 60 5   UIKitCore                           0x000000011c2e440c -[UIDatePicker setDatePickerMode:] + 68 6   <redacted>                           0x0000000100ca4e88 -[RNDateTimePicker setDatePickerMode:] + 64 7   <redacted>                           0x0000000100ca70a0 __RNDateTimePickerShadowViewMeasure_block_invoke <…>
@vonovak
Copy link
Member

vonovak commented Oct 23, 2023

hello, thanks for the PR!

The error message states that UIDatePickerMode .countDownTimer is unsupported when using style .inline..

So those two modes are incompatible. Can you please explain how the fix works? I'm not really following it 🙂 .

Thank you 👍

@mattsellars123
Copy link
Author

mattsellars123 commented Oct 23, 2023

hello, thanks for the PR!

The error message states that UIDatePickerMode .countDownTimer is unsupported when using style .inline..

So those two modes are incompatible. Can you please explain how the fix works? I'm not really following it 🙂 .

Thank you 👍

The shared instance gets into a bad state when set to inline and showing other components with different types such showing DataAndTime component then trying to show a countdown component. The code here resets the type before actually setting the other types so it accidentally put into an invalid state causing the crash.

In the demo app you can just pick inline and date, show picker, then hide picker, then pick countdown and and default and it will crash. https://share.cleanshot.com/kjjtT89V

If you do it with this PR just comment/uncomment the fix here and rerun from Xcode.

@vonovak
Copy link
Member

vonovak commented Oct 24, 2023

@mattsellars123 thanks, makes sense!

We also need to account for this bug in https://github.com/react-native-datetimepicker/datetimepicker/blob/master/ios/fabric/RNDateTimePickerComponentView.mm which used for fabric (new architecture).

Given how that fabric file is done, I think rather than pre-setting mode and style and then overwriting it (as done in this PR currently), we should be able to fix this by first setting preferredDatePickerStyle and then datePickerMode, that should fix it too I think.

Does that sound good?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants