From cf658c7b7f5a3ba2850d1a5e6f31655e6272368a Mon Sep 17 00:00:00 2001 From: Borin Ouch Date: Fri, 16 Oct 2020 18:41:27 -0700 Subject: [PATCH 1/3] Call setDate with copy of date to fix issue with countdown not trigger on first change --- ios/RNDateTimePicker.m | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ios/RNDateTimePicker.m b/ios/RNDateTimePicker.m index 8d1737d1..cea2e2a5 100644 --- a/ios/RNDateTimePicker.m +++ b/ios/RNDateTimePicker.m @@ -31,6 +31,14 @@ - (instancetype)initWithFrame:(CGRect)frame RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) +- (void)willMoveToSuperview:(UIView *)newSuperview +{ + [super willMoveToSuperview:newSuperview]; + NSDate *dateCopy = [[NSDate alloc] initWithTimeInterval:0 sinceDate:self.date]; + [self setDate:[NSDate dateWithTimeIntervalSince1970:0]]; + [self setDate:dateCopy animated:YES]; +} + - (void)didChange { if (_onChange) { From fb28064e26c2db92dbb0c0bf653ce81d1914ed68 Mon Sep 17 00:00:00 2001 From: Borin Ouch Date: Fri, 16 Oct 2020 19:27:18 -0700 Subject: [PATCH 2/3] Fix countdown change issue when user selects 0 --- ios/RNDateTimePicker.m | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/ios/RNDateTimePicker.m b/ios/RNDateTimePicker.m index cea2e2a5..765025e1 100644 --- a/ios/RNDateTimePicker.m +++ b/ios/RNDateTimePicker.m @@ -34,9 +34,7 @@ - (instancetype)initWithFrame:(CGRect)frame - (void)willMoveToSuperview:(UIView *)newSuperview { [super willMoveToSuperview:newSuperview]; - NSDate *dateCopy = [[NSDate alloc] initWithTimeInterval:0 sinceDate:self.date]; - [self setDate:[NSDate dateWithTimeIntervalSince1970:0]]; - [self setDate:dateCopy animated:YES]; + [self resetDate]; } - (void)didChange @@ -44,6 +42,10 @@ - (void)didChange if (_onChange) { _onChange(@{ @"timestamp": @(self.date.timeIntervalSince1970 * 1000.0) }); } + + if ([self datePickerMode] == UIDatePickerModeCountDownTimer) { + [self resetDate]; + } } - (void)setDatePickerMode:(UIDatePickerMode)datePickerMode @@ -66,4 +68,11 @@ - (void)setDate:(NSDate *)date { } } +- (void)resetDate +{ + NSDate *dateCopy = [[NSDate alloc] initWithTimeInterval:0 sinceDate:self.date]; + [self setDate:[NSDate dateWithTimeIntervalSince1970:0]]; + [self setDate:dateCopy animated:YES]; +} + @end From 0ae378e81c9f0812407433547d84e33a8cf2eb92 Mon Sep 17 00:00:00 2001 From: Borin Ouch Date: Sun, 22 Nov 2020 00:38:25 -0800 Subject: [PATCH 3/3] Update ios/RNDateTimePicker.m Only call resetDate when datePickerMode is UIDatePickerModeCountDownTimer Co-authored-by: Vojtech Novak --- ios/RNDateTimePicker.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ios/RNDateTimePicker.m b/ios/RNDateTimePicker.m index 765025e1..5254680c 100644 --- a/ios/RNDateTimePicker.m +++ b/ios/RNDateTimePicker.m @@ -34,7 +34,9 @@ - (instancetype)initWithFrame:(CGRect)frame - (void)willMoveToSuperview:(UIView *)newSuperview { [super willMoveToSuperview:newSuperview]; - [self resetDate]; + if ([self datePickerMode] == UIDatePickerModeCountDownTimer) { + [self resetDate]; + } } - (void)didChange