From 0c47230cb1a9f605f96fcf37b91fb75f8be6e6c4 Mon Sep 17 00:00:00 2001 From: Matt Sellars Date: Wed, 18 Oct 2023 12:12:33 -0600 Subject: [PATCH 1/3] Fix crash when attempting to show picker in different mode/style MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 <…> --- ios/RNDateTimePickerShadowView.m | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ios/RNDateTimePickerShadowView.m b/ios/RNDateTimePickerShadowView.m index c139440c..6072090d 100644 --- a/ios/RNDateTimePickerShadowView.m +++ b/ios/RNDateTimePickerShadowView.m @@ -47,6 +47,12 @@ static YGSize RNDateTimePickerShadowViewMeasure(YGNodeRef node, float width, YGM __block CGSize size; dispatch_sync(dispatch_get_main_queue(), ^{ + if (@available(iOS 13.4, *)) { + // if this is not reset to the default before setting style it can result in a crash + // use case: picker was first shown with mode UIDatePickerModeCountDownTimer then + [shadowPickerView.picker setDatePickerMode:UIDatePickerModeDateAndTime]; + [shadowPickerView.picker setPreferredDatePickerStyle:shadowPickerView.displayIOS]; + } [shadowPickerView.picker setDate:shadowPickerView.date]; [shadowPickerView.picker setDatePickerMode:shadowPickerView.mode]; [shadowPickerView.picker setLocale:shadowPickerView.locale]; From d7bbf0f1b03e173b30029b2dbde24d1f014a4027 Mon Sep 17 00:00:00 2001 From: Matt Sellars Date: Wed, 18 Oct 2023 12:24:59 -0600 Subject: [PATCH 2/3] clarify/fix code comment --- ios/RNDateTimePickerShadowView.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ios/RNDateTimePickerShadowView.m b/ios/RNDateTimePickerShadowView.m index 6072090d..dda5c979 100644 --- a/ios/RNDateTimePickerShadowView.m +++ b/ios/RNDateTimePickerShadowView.m @@ -49,7 +49,8 @@ static YGSize RNDateTimePickerShadowViewMeasure(YGNodeRef node, float width, YGM dispatch_sync(dispatch_get_main_queue(), ^{ if (@available(iOS 13.4, *)) { // if this is not reset to the default before setting style it can result in a crash - // use case: picker was first shown with mode UIDatePickerModeCountDownTimer then + // use case: picker was first shown with mode that is not UIDatePickerModeCountDownTimer then + // displayed again in different UI with mode UIDatePickerModeCountDownTimer [shadowPickerView.picker setDatePickerMode:UIDatePickerModeDateAndTime]; [shadowPickerView.picker setPreferredDatePickerStyle:shadowPickerView.displayIOS]; } From 77a301b91e4dab732710f6bb4fbe8fc7cd921ab5 Mon Sep 17 00:00:00 2001 From: Matt Sellars Date: Wed, 18 Oct 2023 23:17:27 -0600 Subject: [PATCH 3/3] update iOS check to 14.0 to be consistent with rest of file --- ios/RNDateTimePickerShadowView.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/RNDateTimePickerShadowView.m b/ios/RNDateTimePickerShadowView.m index dda5c979..58a96d93 100644 --- a/ios/RNDateTimePickerShadowView.m +++ b/ios/RNDateTimePickerShadowView.m @@ -47,7 +47,7 @@ static YGSize RNDateTimePickerShadowViewMeasure(YGNodeRef node, float width, YGM __block CGSize size; dispatch_sync(dispatch_get_main_queue(), ^{ - if (@available(iOS 13.4, *)) { + if (@available(iOS 14.0, *)) { // if this is not reset to the default before setting style it can result in a crash // use case: picker was first shown with mode that is not UIDatePickerModeCountDownTimer then // displayed again in different UI with mode UIDatePickerModeCountDownTimer