Skip to content

Commit

Permalink
[FlexibleHeader] Ensures the frame is correct under UIKit for Mac (#7668
Browse files Browse the repository at this point in the history
)

When running under UIKit for Mac, the window size may not match the value returned by `[UIScreen mainScreen].bounds` when `commonMDCFlexibleHeaderViewControllerInit` was called, so the width is updated when the view controller is added to a parent view controller.

This change is wrapped with a `#if` test so that it will only affect UIKit for Mac. It should never be necessary on iOS devices and it's possible that there are existing users who modify the frame and do not expect it to be changed after initialisation. If this (presumably unlikely) regression is acceptable then the platform tests could be removed.

closes #7667

Video showing corrected behaviour: https://www.dropbox.com/s/xc6mxofzey1m78q/FlexibleBarGood.mov?dl=0
  • Loading branch information
aufflick authored and featherless committed Jun 27, 2019
1 parent 2703d00 commit 3fa4749
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ - (void)willMoveToParentViewController:(UIViewController *)parent {
- (void)didMoveToParentViewController:(UIViewController *)parent {
[super didMoveToParentViewController:parent];

#if TARGET_OS_UIKITFORMAC
// When running under UIKit for Mac, the window size may not match the value returned by
// `[UIScreen mainScreen].bounds` when `commonMDCFlexibleHeaderViewControllerInit` was
// called, so the width will be updated here to match the hosting view.
CGRect headerFrame = _headerView.frame;
headerFrame.size.width = CGRectGetWidth(_headerView.superview.bounds);
_headerView.frame = headerFrame;
#endif

// The header depends on the tracking scroll view to know how tall it should be.
// If there is no tracking scroll view then we have to poke the header into sizing itself.
if (!_headerView.trackingScrollView) {
Expand Down

0 comments on commit 3fa4749

Please sign in to comment.