-
-
Notifications
You must be signed in to change notification settings - Fork 413
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
base: master
Are you sure you want to change the base?
Fix crash when attempting to show picker in different mode/style #829
Conversation
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 <…>
hello, thanks for the PR! The error message states that 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. |
@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 Does that sound good? |
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
Checklist