Skip to content

Commit

Permalink
[Dialogs] Fix incorrect vertical layout for uppercase buttons (materi…
Browse files Browse the repository at this point in the history
…al-components#9877)

material-components#9411 Description

Making sure layout subviews calculates content size based on the available size, not based on the size of the previous layout calculations. This fixes an issue in which the dialog unexpectedly changed vertical vs horizontal actions layout after the first layout pass (see issue #8434 - b/137070719).

## Before
Actions are laid out vertically - when loaded for the first time, and horizontally thereafter (for instance: after orientation changed, app is sent to the background, etc):

![dialog - actions - uppercase - BEFORE](https://user-images.githubusercontent.com/2329102/76383815-6bb92880-6333-11ea-984d-0e392d433ed4.png)

## After
Actions are laid out horizontally on all layout passes - including the first:

![dialog - actions - uppercase - AFTER](https://user-images.githubusercontent.com/2329102/76383817-6c51bf00-6333-11ea-9892-828abc3d7854.png)

## Issues
Closes #8434 (b/137070719).
PiperOrigin-RevId: 299735842
  • Loading branch information
galiak11 authored Mar 16, 2020
1 parent c66e0c3 commit acdfee5
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion components/Dialogs/src/MDCAlertController.m
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ - (void)viewWillLayoutSubviews {
if (CGRectGetWidth(self.view.bounds) != _previousLayoutSize.width ||
CGRectGetHeight(self.view.bounds) != _previousLayoutSize.height) {
CGSize currentPreferredContentSize = self.preferredContentSize;
CGSize contentSize = CGRectStandardize(self.alertView.bounds).size;
CGSize contentSize = CGRectInfinite.size;
CGSize calculatedPreferredContentSize =
[self.alertView calculatePreferredContentSizeForBounds:contentSize];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ - (void)tearDown {
- (void)sizeTofitContent {
// Ensure snapshot view size matches actual runtime size of alert
MDCAlertControllerView *alertView = (MDCAlertControllerView *)self.alertController.view;
CGSize preferredContentSize = self.alertController.preferredContentSize;
CGSize preferredContentSize = CGRectInfinite.size;
CGSize bounds = [alertView calculatePreferredContentSizeForBounds:preferredContentSize];
self.alertController.view.bounds = CGRectMake(0.f, 0.f, bounds.width, bounds.height);
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit acdfee5

Please sign in to comment.