Fix crash when attempting to show picker in different mode/style #829
+7
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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