fix(android): keep hour when changing minutes in spinner with minuteInterval 20 or 30 - #1066
Open
huytdps13400 wants to merge 1 commit into
Conversation
…nterval 20 or 30 The platform TimePicker spinner moves the hour by one whenever the minute spinner goes from its max to its min value (or back), assuming the wheel wrapped around. With minuteInterval 20 or 30 the minute spinner has too few values to wrap, so every such change shifted the hour. Restore the hour in that case. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1033
Fixes #822
On Android, with
display="spinner"andminuteInterval={30}(or20), changing the minutes also changes the hour: picking:30from 8:00 gives 7:30, and picking:00from 8:30 gives 9:00.Root cause: the platform
TimePickerSpinnerDelegatemoves the hour by one whenever the minute spinner goes from its max value to its min value (or the other way), because it assumes the wheel wrapped around. WithminuteInterval30 the minute spinner only has 2 values (00,30), and with 20 it has 3.NumberPickerdoes not allow wrapping with fewer than 3 steps between min and max, so these changes are never real wrap-arounds. With interval 30, every minute change shifted the hour.Change: in
MinuteIntervalSnappableTimePickerDialog, in spinner mode, when the minute spinner cannot wrap (NumberPicker#getWrapSelectorWheel()is false) and a singleonTimeChangedchanges both the minute and the hour, the hour is restored to its previous value. Intervals whose minute spinner can wrap (1–15) are unchanged, so a real wrap such as 8:45 → 9:00 still works. Clock mode is unchanged.Test Plan
I verified this with a local Robolectric test, which I did not include because the repo has no Android unit test setup. I can add it if you want. The test opens
RNDismissableTimePickerDialogwithR.style.SpinnerTimePickerDialog, changes theminuteNumberPickerthe way a user scroll does (setValueInternal(index, true)), presses the positive button and checks the hour and minute reported toOnTimeSetListener. It ran on SDK 26, 28, 30, 33, 34 and 35.30000030→00→3030updateTime(10, …)then pick0040(typed)00(real wrap)00(real wrap)I also compiled the library with
:react-native-community_datetimepicker:testDebugUnitTest(old arch).yarn testandyarn lintdon't cover this change because it is Java only.What's required for testing (prerequisites)?
An Android device or emulator.
What are the steps to reproduce (after prerequisites)?
Open the example app with
mode="time",display="spinner"andminuteInterval={30}, then scroll the minutes between00and30. The hour should stay the same.Compatibility
Checklist
README.md(not needed)example/App.js) (not needed)This fix was prepared with AI assistance (Claude Code) and verified locally with the tests above.
🤖 Generated with Claude Code