From 99e3182d2049d8b361b5f3abbd957b2333b2ead5 Mon Sep 17 00:00:00 2001 From: Moksh Upadhyay Date: Sat, 28 Nov 2026 04:04:17 +0530 Subject: [PATCH] fix(ios): avoid crash when changing timeZone with minimumDate or maximumDate set UIDatePicker keeps a loaded calendar's visible month across a time zone change. When minimumDate/maximumDate sits near a month boundary, that month can fall outside the range in the new zone and UIKit throws an NSInternalInconsistencyException. Clear the range while the zone changes and restore it afterwards. The override lives on RNDateTimePicker, so it covers both the Fabric and the old-architecture view. Refs #1028 --- ios/RNDateTimePicker.m | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ios/RNDateTimePicker.m b/ios/RNDateTimePicker.m index 9c73c8ef..d52e6032 100644 --- a/ios/RNDateTimePicker.m +++ b/ios/RNDateTimePicker.m @@ -65,6 +65,21 @@ - (void)setMinuteInterval:(NSInteger)minuteInterval _reactMinuteInterval = minuteInterval; } +- (void)setTimeZone:(NSTimeZone *)timeZone +{ + // A loaded calendar keeps its visible month across a time zone change. With a minimum/maximum date + // near a month boundary that month can fall outside the range in the new zone, and UIKit throws + // (e.g. "Trying to scroll to a month marked as visible that is not loaded."). Clearing the range + // while the zone changes avoids that; restoring it re-applies the limits in the new zone. + NSDate *minimumDate = self.minimumDate; + NSDate *maximumDate = self.maximumDate; + self.minimumDate = nil; + self.maximumDate = nil; + [super setTimeZone:timeZone]; + self.minimumDate = minimumDate; + self.maximumDate = maximumDate; +} + - (void)setDate:(NSDate *)date { // Need to avoid the case where values coming back through the bridge trigger a new valueChanged event if (![self.date isEqualToDate:date]) {