Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] DatePicker Graphical Bug #25943

Open
michalpobuta opened this issue Nov 19, 2024 · 0 comments · May be fixed by #26064
Open

[Android] DatePicker Graphical Bug #25943

michalpobuta opened this issue Nov 19, 2024 · 0 comments · May be fixed by #26064
Assignees
Labels
area-controls-picker Picker p/2 Work that is important, but is currently not scheduled for release platform/android 🤖 t/bug Something isn't working
Milestone

Comments

@michalpobuta
Copy link

michalpobuta commented Nov 19, 2024

Description

Date picker have problem with showing correct selected Date. Date picker showing wrong selected date when we go to next month.

Example:
If date binding is set to todays date (19.11), and we open date picker it will shows 19.11 what is okey, but if we go to next month it will show that 19.12 is selected what is incorrect. This is just graphical issue, binding is not changing.

I tested it on .net8 and .net9 and on both problem exsit.

Example on video (When I started clicking like monkey problem disappeared lol)

Nagranie.z.ekranu.2024-11-19.o.11.49.07.mov

Steps to Reproduce

  1. Crate new MAUI APP
  2. Add ViewModel with 3 observable properties: Date (Set for date today), MaxDate (Today + 60 days), MinDate(Today - 60days)
  3. Set this VM as BindingContext for MainPage
  4. Add DatePicker with these bindings to MainPage
  5. Run App -> Select DatePicker -> Go to next month
    Then there should be selected our date and same date in next month

Link to public reproduction project repository

https://github.com/michalpobuta/DatePickerIssue

Version with bug

9.0.10 SR1

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 14

Did you find any workaround?

public partial class CustomDatePickerHandler
{
    private static readonly DateTime _unixTimeBeginning = new (1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
    private readonly TimeSpan _clickThrottle = TimeSpan.FromMilliseconds(500);
    private DateTime _lastClickTime = DateTime.MinValue;

    public void Show()
    {
        ShowDatePickerPopup();
    }

    protected override void ConnectHandler(MauiDatePicker platformView)
    {
        platformView.Touch += OnTouch;
        base.ConnectHandler(platformView);
    }

    protected override void DisconnectHandler(MauiDatePicker platformView)
    {
        platformView.Touch -= OnTouch;
        base.DisconnectHandler(platformView);
    }

    private void OnTouch(object? sender, View.TouchEventArgs e)
    {
        if (e.Event is not { } motionEvent)
        {
            return;
        }

        e.Handled = true;

        if (motionEvent.Action != MotionEventActions.Up
            && motionEvent.Action != MotionEventActions.PointerUp)
        {
            return;
        }

        if (DateTime.Now < _lastClickTime + _clickThrottle)
        {
            return;
        }

        ShowDatePickerPopup();
    }

    private void ShowDatePickerPopup()
    {
        _lastClickTime = DateTime.Now;

        var datePickerDialog = new DatePickerDialog(Context, OnDateSet, VirtualView.Date.Year, VirtualView.Date.Month - 1, VirtualView.Date.Day);
        datePickerDialog.DatePicker.MinDate = (long)(VirtualView.MinimumDate.Date.ToUniversalTime() - _unixTimeBeginning).TotalMilliseconds;
        datePickerDialog.DatePicker.MaxDate = (long)(VirtualView.MaximumDate.Date.ToUniversalTime() - _unixTimeBeginning).TotalMilliseconds;

        datePickerDialog.Show();
    }

    private void OnDateSet(object? sender, DatePickerDialog.DateSetEventArgs args)
    {
        VirtualView.Date = args.Date;
    }
}

Relevant log output

@michalpobuta michalpobuta added the t/bug Something isn't working label Nov 19, 2024
@michalpobuta michalpobuta changed the title DatePicker Graphical Bug on Android [Android] DatePicker Graphical Bug Nov 19, 2024
@PureWeen PureWeen added this to the Backlog milestone Nov 19, 2024
@PureWeen PureWeen added the p/2 Work that is important, but is currently not scheduled for release label Nov 19, 2024
@vishnumenon2684 vishnumenon2684 self-assigned this Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-picker Picker p/2 Work that is important, but is currently not scheduled for release platform/android 🤖 t/bug Something isn't working
Projects
None yet
4 participants