diff --git a/ios/RNDateTimePicker.m b/ios/RNDateTimePicker.m index 8d1737d1..5254680c 100644 --- a/ios/RNDateTimePicker.m +++ b/ios/RNDateTimePicker.m @@ -31,11 +31,23 @@ - (instancetype)initWithFrame:(CGRect)frame RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) +- (void)willMoveToSuperview:(UIView *)newSuperview +{ + [super willMoveToSuperview:newSuperview]; + if ([self datePickerMode] == UIDatePickerModeCountDownTimer) { + [self resetDate]; + } +} + - (void)didChange { if (_onChange) { _onChange(@{ @"timestamp": @(self.date.timeIntervalSince1970 * 1000.0) }); } + + if ([self datePickerMode] == UIDatePickerModeCountDownTimer) { + [self resetDate]; + } } - (void)setDatePickerMode:(UIDatePickerMode)datePickerMode @@ -58,4 +70,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