fixed stale datetime picker default value#910
Open
VegardHV wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Pull request overview
This PR fixes an issue where picker controls could display a “frozen” default date/time because DateTime.Now was evaluated once at static initialization and reused across instances. The fix switches these bindable properties to use defaultValueCreator so each picker instance gets a fresh “now” value when created.
Changes
- Updated
SelectedDate/SelectedDateTimebindable properties to usedefaultValueCreatorinstead of a staticDateTime.Nowdefault. - Added explanatory comments documenting why
defaultValueCreatoris needed. - Added a changelog entry describing the consumer-visible behavior fix.
📁 File summary (4 files changed)
| File | Description |
|---|---|
src/library/DIPS.Mobile.UI/Components/Pickers/DatePicker/HorizontalInLine/HorizontalInlineDatePicker.Properties.cs |
Uses defaultValueCreator to avoid shared stale default date/time. |
src/library/DIPS.Mobile.UI/Components/Pickers/DatePicker/DatePicker.Properties.cs |
Uses defaultValueCreator for per-instance default SelectedDate. |
src/library/DIPS.Mobile.UI/Components/Pickers/DateAndTimePicker/DateAndTimePicker.Properties.cs |
Uses defaultValueCreator for per-instance default SelectedDateTime. |
CHANGELOG.md |
Documents the fix as a patch release entry. |
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/library/DIPS.Mobile.UI/Components/Pickers/DatePicker/HorizontalInLine/HorizontalInlineDatePicker.Properties.cs | Per-instance default date/time via defaultValueCreator. |
| src/library/DIPS.Mobile.UI/Components/Pickers/DatePicker/DatePicker.Properties.cs | Per-instance default date/time via defaultValueCreator. |
| src/library/DIPS.Mobile.UI/Components/Pickers/DateAndTimePicker/DateAndTimePicker.Properties.cs | Per-instance default date/time via defaultValueCreator. |
| CHANGELOG.md | Adds patch note for the default-value staleness fix. |
Comment on lines
+65
to
+68
| // A plain DateTime.Now default value is read only once and then shared by every picker, | ||
| // so all pickers showed the same frozen time until app restart. The creator runs once per | ||
| // picker, so each picker gets the current time instead. | ||
| defaultValueCreator: bindable => DateTime.Now); |
Comment on lines
+21
to
+24
| // A plain DateTime.Now default value is read only once and then shared by every picker, | ||
| // so all pickers showed the same frozen time until app restart. The creator runs once per | ||
| // picker, so each picker gets the current time instead. | ||
| defaultValueCreator: bindable => DateTime.Now); |
Comment on lines
+8
to
12
| typeof(HorizontalInlineDatePicker), | ||
| defaultValue: default(DateTime), | ||
| defaultBindingMode: BindingMode.TwoWay, | ||
| propertyChanged: (b, _, _) => | ||
| { |
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.
Description of Change
Date pickers used
DateTime.Nowas their default value. That default was read only once and then shared by every picker that also have no value of their own, so they all showed the same stale datetime until the app was restarted.How to reproduce (in a version before the fix)
Fixed by using defaultValueCreator to set a default time upon creation of each individual picker.
Todos