Skip to content

Conversation

HarishwaranVijayakumar
Copy link
Contributor

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Issue Details

  • On Android, when opening a TimePicker and then rotating the device, the picker dialog doesn’t seem to redraw itself to match the new screen dimensions.

Root Cause of the issue

  • TimePicker lacks orientation change detection entirely. When the device rotates while the dialog is open, TimePicker has no mechanism to dismiss and re-show the dialog with updated layout, unlike DatePicker which detects orientation changes and refreshes the dialog display.

Description of Change

  • Added ConnectHandler and related event subscriptions (ViewAttachedToWindow/ViewDetachedFromWindow) to manage display info changes and cleanup when the view is attached or detached. This helps ensure the time picker dialog responds to device orientation changes and releases resources properly.

  • Implemented OnMainDisplayInfoChanged to dismiss and recreate the time picker dialog with the current time when the device orientation changes, preserving user selection progress.

Issues Fixed

Fixes #31658

Reference

Tested the behaviour in the following platforms

  • - Windows
  • - Android
  • - Mac
  • - iOS

Output

Before After
Screen.Recording.2025-10-08.at.4.50.08.pm.mov
Screen.Recording.2025-10-08.at.4.47.47.pm.mov

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Oct 8, 2025
Copy link
Contributor

Hey there @@HarishwaranVijayakumar! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@dotnet-policy-service dotnet-policy-service bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Oct 8, 2025
Copy link
Contributor

@jsuarezruiz jsuarezruiz left a comment

Choose a reason for hiding this comment

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

Could include a test?


void OnMainDisplayInfoChanged(object? sender, DisplayInfoChangedEventArgs e)
{
TimePickerDialog? currentDialog = _dialog;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could include a null-check for _dialog before attempting to use it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jsuarezruiz, I have made the suggested change.

@HarishwaranVijayakumar
Copy link
Contributor Author

Could include a test?

@jsuarezruiz, The fix involves OnMainDisplayInfoChanged, which is only triggered when the device is rotated. However, SetOrientationLandscape does not actually rotate the device, so OnMainDisplayInfoChanged is not triggered, and the test still fails.

@HarishwaranVijayakumar HarishwaranVijayakumar marked this pull request as ready for review October 10, 2025 13:01
@Copilot Copilot AI review requested due to automatic review settings October 10, 2025 13:01
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an issue where the TimePicker dialog on Android doesn't update its layout when the device is rotated while the dialog is open. The solution adds orientation change detection to automatically dismiss and recreate the dialog with the correct dimensions.

Key Changes

  • Added orientation change detection via DeviceDisplay.MainDisplayInfoChanged event subscription
  • Implemented dialog recreation when orientation changes to preserve user input
  • Added proper lifecycle management for event subscriptions and dialog cleanup

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
TimePickerHandler.Android.cs Added orientation change handling, dialog lifecycle management, and proper event subscription cleanup
PublicAPI.Unshipped.txt Added new public API entry for the ConnectHandler override method

void ShowPickerDialog()
{
if (VirtualView == null)
if (VirtualView is null)
Copy link

Copilot AI Oct 10, 2025

Choose a reason for hiding this comment

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

Inconsistent null checking pattern. The existing code uses VirtualView == null on line 75, but this change uses VirtualView is null. For consistency, maintain the same null checking pattern throughout the file.

Suggested change
if (VirtualView is null)
if (VirtualView == null)

Copilot uses AI. Check for mistakes.

Comment on lines +150 to +160
if (_dialog is null)
{
_dialog = CreateTimePickerDialog(hour, minute);
}
else
{
// Update the dialog with new values (for orientation changes)
_dialog.Dispose();
_dialog = CreateTimePickerDialog(hour, minute);
}

Copy link

Copilot AI Oct 10, 2025

Choose a reason for hiding this comment

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

The logic in both branches creates a new dialog. This can be simplified by disposing the existing dialog first (if it exists) and then creating a new one, eliminating code duplication.

Suggested change
if (_dialog is null)
{
_dialog = CreateTimePickerDialog(hour, minute);
}
else
{
// Update the dialog with new values (for orientation changes)
_dialog.Dispose();
_dialog = CreateTimePickerDialog(hour, minute);
}
// Always dispose the existing dialog before creating a new one
_dialog?.Dispose();
_dialog = CreateTimePickerDialog(hour, minute);

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-controls-datetimepicker DatePicker, TimePicker community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/android

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android] TimePicker Dialog doesn't update the layout when rotating the device with dialog open

2 participants