Skip to content

fix(ios): avoid crash when changing timeZone with minimumDate or maximumDate set - #1079

Open
mokshupadhyay wants to merge 1 commit into
react-native-datetimepicker:masterfrom
mokshupadhyay:fix/ios-timezone-minimum-date
Open

mokshupadhyay wants to merge 1 commit into
react-native-datetimepicker:masterfrom
mokshupadhyay:fix/ios-timezone-minimum-date

Conversation

@mokshupadhyay

Copy link
Copy Markdown

Summary

Refs #1028

On iOS, changing the time zone of a picker that is already showing its calendar crashes the app when minimumDate or maximumDate is near a month boundary in the new zone. UIDatePicker keeps the calendar's visible month across the time zone change, that month can then fall outside the allowed range, and UIKit throws:

NSInternalInconsistencyException: 'Trying to scroll to a month marked as visible that is not loaded.'
  -[UICalendarView _updateCollectionViewScrollPosition:]
  -[UICalendarView _setVisibleMonth:animated:updateDataSource:updateCollectionView:...]
  -[UICalendarView _reloadVisibleMonthIfNeeded]
  ... -[UIDatePicker setTimeZone:] (from RNDateTimePickerComponentView updatePropsForPicker)

RNDateTimePicker now overrides setTimeZone:: it clears minimumDate / maximumDate, sets the zone, and puts them back, so the limits are applied again in the new zone. The Fabric view and the old-architecture manager both use RNDateTimePicker, so both get it.

I believe this is the crash in #1028 (the message there, "Unable to set a visible month that is before the minimum or after the maximum date", is a sibling check in the same UICalendarView method), but I could only reproduce it when the time zone changes after the calendar is shown, not on the first render, and I couldn't test the "device date is the 1st" part without changing the system clock. So this says Refs rather than Fixes; @-mentioning the reporter on the issue to check their setup.

Test Plan

iOS 18.6 simulator, example app (RN 0.83, new architecture), device time zone set with SIMCTL_CHILD_TZ.

What's required for testing (prerequisites)?

A mode="datetime" picker with display="inline", value and minimumDate = 2026-11-30T23:30:00Z, launched with the device in Europe/London, and timeZoneName="Europe/Paris" set about a second after mount (e.g. from state).

What are the steps to reproduce (after prerequisites)?

  1. Open the screen: the calendar shows November.
  2. When timeZoneName changes, main crashes with the exception above.
  3. With this change it doesn't crash, and the picker shows Dec 1, 12:30 AM with the back arrow disabled (the minimum still applies).

The same crash on main, and no crash with the change, for: device Paris / picker London with maximumDate, device Los Angeles / picker Tokyo with minimumDate, and timeZoneOffsetInMinutes={60} set after mount. Setting the zone on the first render, the compact display, and changing minimumDate or the value after mount did not crash before either. yarn test and yarn lint pass. The old architecture is covered by the same class but I could not run it on RN 0.83.

Compatibility

OS Implemented
iOS ✅
Android ❌

Checklist

  • I have tested this on a device and a simulator (simulator only)
  • I added the documentation in README.md (no API change)
  • I updated the typed files (TS and Flow) (no API change)
  • I added a sample use of the API in the example project (example/App.js)
  • I have added automated tests, either in JS or e2e tests, as applicable

An AI coding assistant (Claude Code) helped me find and fix this; I reviewed the change and the results.

…mumDate 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 react-native-datetimepicker#1028
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant