Skip to content

Conversation

@sterlingwes
Copy link
Collaborator

Summary

Follow-up to the min/max constraint fix in #1009. There was a pre-existing issue when the component gets unmounted: the native component gets recycled for future reuse but keeps its picker instance properties along with their state.

This likely would have also fixed the earlier issue but I think those changes are worth keeping as they make it clearer how the UIDatePicker constraints operate.

Test Plan

Video showing the crash case:

pickerbug.mp4

Two breakpoints here:

  • one in the recycle lifecycle method to show that the picker retains constraints
  • one right before we apply props for the next picker to show that the constraints are stale before the crash

Video showing the fix:

pickerbugfixed.mp4

Breakpoints show that the min/max date constraints are cleared

What's required for testing (prerequisites)?

I copied over this component from the reproduction app (provided by @Junveloper in the prior PR). You can reference this branch for the changes required: sterlingwes#1

What are the steps to reproduce (after prerequisites)?

  • open the modal
    • pick two dates in the next month
    • submit / close modal
  • open modal again
    • tap to pick first date and it should crash

Compatibility

OS Implemented
iOS
Android

Checklist

  • I have tested this on a simulator
  • I added the documentation in README.md
  • I updated the typed files (TS and Flow)
  • 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

{
self.minimumDate = nil;
self.maximumDate = nil;
self.date = [NSDate date];
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't set this to nil - this appears to be the default when you instantiate a UIDatePicker

@Junveloper
Copy link

Thank you for this @sterlingwes , can't wait for this to be merged! :)

Copy link
Member

@vonovak vonovak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the PR. Could this be resolved by disabling recycling altogether? The benefit for date pickers is minimal and there's a lot of internal state that could mess things up.

see https://blog.swmansion.com/react-natives-new-architecture-the-tricky-parts-1-2-bb0c16950f2d

+ (BOOL)shouldBeRecycled
{
  return NO;
}

@sterlingwes
Copy link
Collaborator Author

yup good call @vonovak , simpler is better here for sure

did the same before / after test and can confirm this fixes as shown above

@sterlingwes sterlingwes merged commit 48e89d2 into react-native-datetimepicker:master Nov 25, 2025
5 checks passed
@sterlingwes sterlingwes deleted the fix-picker-state-recycling branch November 25, 2025 00:31
@Junveloper
Copy link

Thank you @vonovak and @sterlingwes . When could I expect a new release? :)

@sterlingwes
Copy link
Collaborator Author

@Junveloper momentarily - when this MR lands: #1027

Thanks for sharing the reproduction case! And to vonovak for the quick review 🙏🏻

@Junveloper
Copy link

Thank you, you guys are legends!

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.

3 participants