Skip to content

Commit

Permalink
REGRESSION (268069@main): [iOS] Rotating from landscape to portrait c…
Browse files Browse the repository at this point in the history
…auses date picker to run off screen

https://bugs.webkit.org/show_bug.cgi?id=267397
rdar://118972687

Reviewed by Wenson Hsieh.

268069@main modified date picker presentation to use
`UIPopoverPresentationController`, rather than `_UIDatePickerOverlayPresentation`.

`_UIDatePickerOverlayPresentation` automatically handled dismissing the picker
on rotation and view size changes, but `UIPopoverPresentationController` does not.
This results in the date picker being presented at an incorrect location after
rotation, as the view remains presented, and the old layout information is still
used.

Fix by explicitly dismissing the picker on rotation and view size changes, matching
system date/time pickers.

* LayoutTests/fast/forms/ios/dismiss-date-picker-on-rotation-expected.txt: Added.
* LayoutTests/fast/forms/ios/dismiss-date-picker-on-rotation.html: Added.
* Source/WebKit/UIProcess/ios/forms/WKDatePickerPopoverController.mm:
(-[WKDatePickerPopoverController dismissDatePickerAnimated:]):
(-[WKDatePickerPopoverController dismissDatePicker]):
(-[WKDatePickerPopoverController viewWillTransitionToSize:withTransitionCoordinator:]):

Only dismiss the date picker if it is already presented by checking for
`isBeingPresented` and `isBeingDismissed`.

Canonical link: https://commits.webkit.org/272922@main
  • Loading branch information
pxlcoder committed Jan 11, 2024
1 parent 936310f commit ea28020
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
This test verifies that rotation dismisses a presented date picker.

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".


PASS Presented date picker
PASS Dismissed date picker on rotation
PASS successfullyParsed is true

TEST COMPLETE

31 changes: 31 additions & 0 deletions LayoutTests/fast/forms/ios/dismiss-date-picker-on-rotation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] -->
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="../../../resources/ui-helper.js"></script>
<script src="../../../resources/js-test.js"></script>
</head>
<body>
<input type="date"></input>
<script>
jsTestIsAsync = true;

addEventListener("load", async () => {
description("This test verifies that rotation dismisses a presented date picker.");

await UIHelper.activateElement(document.querySelector("input"));
await UIHelper.waitForContextMenuToShow();
testPassed("Presented date picker");

await UIHelper.rotateDevice("landscape-right");
await UIHelper.ensurePresentationUpdate();

await UIHelper.waitForContextMenuToHide();
testPassed("Dismissed date picker on rotation");

await UIHelper.rotateDevice("portrait");
finishJSTest();
});
</script>
</body>
</html>
17 changes: 15 additions & 2 deletions Source/WebKit/UIProcess/ios/forms/WKDatePickerPopoverController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,18 @@ - (void)assertAccessoryViewCanBeHitTestedForTesting
RELEASE_ASSERT(hitTestedToAccessoryView);
}

- (void)dismissDatePicker
- (void)dismissDatePickerAnimated:(BOOL)animated
{
[self.presentingViewController dismissViewControllerAnimated:YES completion:[strongSelf = retainPtr(self)] {
[self.presentingViewController dismissViewControllerAnimated:animated completion:[strongSelf = retainPtr(self)] {
[strongSelf _dispatchPopoverControllerDidDismissIfNeeded];
}];
}

- (void)dismissDatePicker
{
[self dismissDatePickerAnimated:YES];
}

- (void)viewDidLoad
{
[super viewDidLoad];
Expand Down Expand Up @@ -223,6 +228,14 @@ - (void)viewWillLayoutSubviews
[self _scaleDownToFitHeightIfNeeded];
}

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];

if (!self.isBeingPresented && !self.isBeingDismissed)
[self dismissDatePickerAnimated:NO];
}

- (void)_scaleDownToFitHeightIfNeeded
{
auto viewBounds = self.view.bounds;
Expand Down

0 comments on commit ea28020

Please sign in to comment.