This new shift behavior mode enables the flexible header to mimic the behavior of UINavigationController's setNavigationBarHidden:. When the shift behavior is set to this new value, the flexible header can be hidden or shown using the shiftHeaderOnScreenAnimated: and shiftHeaderOffScreenAnimated: APIs, but user interactions will not affect the header's visibility.
Added an example to the configurator to demonstrate the behavior.
Part of https://github.com/material-components/material-components-ios/issues/5185
Closes https://github.com/material-components/material-components-ios/issues/5813
Problem:
Prior to this change, the shift phase values were nonsensical when a flexible header was a child of its tracking scroll view.
Root cause:
The scroll phase value logic was looking at self.frame, which is undefined if self.transform is not the identity. When a flexible header is a child of its tracking scroll view, we modify self.transform in order to keep it "pinned" to the top of the screen. This resulted in unpredictable values for self.frame in the phase calculation logic.
The fix:
Rather than rely on self.frame, we now inspect self.center which is unaffected by self.transform. We calculate what the "top edge" of the flexible header is and feed that value in to the phase calculation logic.
Tested:
Added new log statements to the flexible header configurator demo. Verified that the values output matched the documented behavior of the scroll phase properties.
Removes the need to copy-paste stanzas from other files anymore as we'll rely on #4478 to generate the correct stanza for us instead.
This was an automated change generated by running a find-and-replace regular expression:
```
/\*
Copyright ([0-9]+)-present the Material Components for iOS authors\. All Rights Reserved\.
Licensed under the Apache License, Version 2\.0 \(the "License"\);
you may not use this file except in compliance with the License\.
You may obtain a copy of the License at
http://www\.apache\.org/licenses/LICENSE-2\.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied\.
See the License for the specific language governing permissions and
limitations under the License\.
\*/
```
```
/\*
Copyright ([0-9]+)-present the Material Components for iOS authors\. All Rights Reserved\.
Licensed under the Apache License, Version 2\.0 \(the "License"\);
you may not use this file except in compliance with the License\.
You may obtain a copy of the License at
http://www\.apache\.org/licenses/LICENSE-2\.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied\.
See the License for the specific language governing permissions and
limitations under the License\.
\*/
```
```
/\*
Copyright ([0-9]+)-present the Material Components for iOS authors\. All Rights Reserved\.
Licensed under the Apache License, Version 2\.0 \(the "License"\);
you may not use this file except in compliance with the License\.
You may obtain a copy of the License at
http://www\.apache\.org/licenses/LICENSE-2\.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied\.
See the License for the specific language governing permissions and
limitations under the License\.
\*/
```
```
// Copyright $1-present the Material Components for iOS authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
```
### Release notes
`canAlwaysExpandToMaximumHeight` is a new behavior on the Flexible Header component that is available through an extension target, `FlexibleHeader+CanAlwaysExpandToMaximumHeight`.
Enabling this behavior on a flexible header instance will allow the flexible header to expand to its maximum height even when the flexible header is floating in front of its content.
---
We intend to keep usage of this API fairly restricted internally, so we have added the behavior as a separate target that we'll whitelist internally to clients. The API is still supported by the typical API contract for public clients.
The behavior is implemented using the same shift accumulator logic that enables header shifting. When the accumulator is positive, we're shifting off-screen. When the accumulator is negative, we're expanding the height of the flexible header.
Closes https://github.com/material-components/material-components-ios/issues/4393
This is the first part of a two-part change that addresses the behavior outlined in https://github.com/material-components/material-components-ios/issues/4104. The second part will expose a similar behavior in the AppBar component.
---
This PR introduces a new top safe area inset behavior to the flexible header view, gated behind the runtime flag `inferTopSafeAreaInsetFromViewController`.
When this behavior is enabled, the flexible header will no longer attempt to infer the top safe area inset from the device's insets using `MDCDeviceTopSafeAreaInset`. Instead, it will infer the top safe area inset from the view controller ancestry of the flexible header view controller.
This new behavior addresses a number of issues related to safe area insets, namely:
- https://github.com/material-components/material-components-ios/issues/4104 (incorrect insets when shown in a popover or modal dialog on iPad).
- Flexible headers can now be used in app extensions.
- The flexible header now properly reacts to status bar visibility changes.
### New feature: top safe area guide
This change introduces a new layout guide that can be used to position content within the flexible header view while respecting the top safe area insets. The `topSafeAreaGuide` API is available on the MDCHeaderView instance of the flexible header view controller and supports iOS 8 and up. An example of its usage to align a view to the bottom of the flexible header's top safe area guide:
```
[NSLayoutConstraint constraintWithItem:self.titleLabel
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:self.fhvc.headerView.topSafeAreaGuide
attribute:NSLayoutAttributeBottom
multiplier:1.0
constant:0]
```
The new layout guide works whether `inferTopSafeAreaInsetFromViewController` is enabled or disabled.
### Additional information
If using `MDCFlexibleHeaderContainerViewController`, this new behavior is now enabled by default.
The new behavior (and all of the other "new" behaviors) have been enabled on every FlexibleHeader example.
### Results
A screenshot of the result of this API once enabled on the App Bar:

### Architecture
This change builds off of the foundation introduced in 80fd217f766e0f5be6a3bc6bef5923f231721f9d. As part of that change, we made it possible to modify a given view controller's top layout guide such that it equalled the top safe area insets + the flexible header height. Unfortunately, that change was still limited by the fact that the flexible header always assumed that it was placed as a full-screen view.
With the new `inferTopSafeAreaInsetFromViewController` behavior, we are able to extract the top safe area inset from our view controller ancestry instead. We can then combine this extracted value with our flexible header's height before ultimately writing that to the target top layout guide. This flow is roughly shown in the following diagram:

In order to implement this flow we needed to implement two things:
1. A mechanism by which we could infer the root-most ancestral view controller from which we could extract safe area insets.
2. A mechanism by which we could be notified every time that root view controller's safe area insets changed.
The first mechanism is implemented by `fhv_inferTopSafeAreaSourceViewController` as a simple ancestral traversal. We walk up the view controller tree from the flexible header's parent until we run out of ancestors. There is some nuance to this algorithm, in that we need to ensure that our ancestor isn't our `topLayoutGuideViewController` or we risk creating an infinite loop. If we encounter such a situation we attempt to break the loop by walking up the topLayoutGuideViewController's ancestry instead, but at this point it's very likely we won't have a viable ancestor and we'll throw an assertion if/when we can't find a viable ancester.
With an ancestor in hand, we then determine whether to KVO observe `topLayoutGuide` or `safeAreaInsets` based on whether we're running pre-iOS 11 or iOS 11+, respectively.
KVO then informs us of any changes to the top safe area insets, which we can then propagate through the flexible header view and eventually on to the top layout guide (if `topLayoutGuideAdjustmentEnabled` is also enabled).
We can credit any contributor who would like to be credited this way, by adding them on request to the AUTHORS file. The copyright statement changes are required for this to work. Note that this has...
Summary:
We can credit any contributor who would like to be credited this way, by adding them on request to the AUTHORS file. The copyright statement changes are required for this to work. Note that this has no legal change, since the contributors always retained their copyright despite the copyright notice, but it's a nice acknowledgement.
Changed copyright statement to include non-Google authors.
Command run:
find * \( -name '*\.m' -or -name '*\.h' -or -name '*\.swift' \) -and -not \( -path 'scripts/external*' -name Pods \) -print0 | xargs -0 sed -i '' 's/Copyright \(.*\) Google Inc/Copyright \1 the Material Components for iOS authors/'
Added non-source files.
Command run:
grep -Rl 'Copyright .* Google Inc' * --exclude-dir scripts/external --null | xargs -0 sed -i '' 's/Copyright \(.*\) Google Inc/Copyright \1 the Material Components for iOS authors/'
Reviewers: featherless, O1 Material components iOS, randallli
Reviewed By: O1 Material components iOS, randallli
Tags: #material_components_ios
Differential Revision: http://codereview.cc/D1415
Summary:
This property makes it possible to use Flexible Header in popovers and non-fullscreen modals.
Closes https://github.com/google/material-components-ios/issues/349.
Reviewers: ajsecord, #mdc_ios_owners
Reviewed By: ajsecord, #mdc_ios_owners
Subscribers: ajsecord
Projects: #material_components_ios
Differential Revision: http://codereview.cc/D673
Summary: [Examples: NavigationBar] Added nav bar example and small fix to flexible header examples.
Reviewers: featherless, #mdc_ios_owners
Reviewed By: featherless, #mdc_ios_owners
Subscribers: featherless
Projects: #material_components_ios
Differential Revision: http://codereview.cc/D492
Summary: Recreated and updated 'Configurator' example for new example schemes and did some cleanup on 'Typical Use'
Reviewers: #mdc_ios_owners, featherless
Reviewed By: #mdc_ios_owners, featherless
Subscribers: featherless
Projects: #material_components_ios
Differential Revision: http://codereview.cc/D460