We recommend using `initWithDefaults` and we should follow the recommendation. This change removes all usage of `init` within MDC components in order to let us remove that initializer from the public surface.
PiperOrigin-RevId: 302958447
After this change, the default behavior for MDCNavigationBar's titleInsets property will be dynamic. In leading mode, the default insets will be 0,0,0,0, while in centered mode the title insets will continue to be 0,16,0,16. If the titleInsets property is explicitly set then the explicitly set value will be preferred indefinitely.
PiperOrigin-RevId: 301632853
The navigation bar needs an API so clients can hook-in to trait collection changes. This additionally passes the navigation bar as a parameter so clients can modify the flexible header within the block.
Closes#7919
The `titleFontForState:` API did not correctly reflect the rendered font
when no explicit fonts were set via the MDCButton APIs. As a result,
calling `updateTitleFont` internally could result in a different font
being returned than what was displayed.
Moving the "fall back" and Dynamic Type behavior into the
`titleFontForState:` method allows more consistent behavior (reduces the
risk of deviations) and corrects the APIs to reflect what is rendered.
This change should result in no visible changes to clients (the rendered
fonts should remain the same), but will result in non-`nil` results
being returned from `titleFontForState:` to correctly reflect the
rendered font for a given state.
Part of #7492
These two new APIs make it possible to get the frame of the leading and trailing item views in a navigation bar. These APIs are primarily intended for use when needing to present popover or contextual elements that point to the views for individual navigation bar items.
Closes https://github.com/material-components/material-components-ios/issues/7248
Closes https://github.com/material-components/material-components-ios/issues/7207
Context
-------
UINavigationBar will attempt to steal a navigationItem's titleView property for its own use, even if the navigation bar is not visible. Our own MDCNavigationBar also wants to show the titleView instance but we can't stop UINavigationBar from stealing the titleView.
To protect against this behavior, MDCNavigationBar implements a "sandbag swap" of the titleView when it's assigned. UINavigationBar ends up stealing the sandbag away, while our MDCNavigationBar keeps an internal reference to the desired titleView.
Before this fix
---------------
The sandbag view would be swapped the first time titleView is assigned. If the same titleView was assigned to the navigationItem again, however, we would not swap it with a sandbag. The result is that navigationItem.titleView would be pointing at the actual view (not the sandbag) when UINavigationBar comes around to steal the titleView. The result is that the titleView would disappear from MDCNavigationBar.
After this fix
--------------
We now assign the sandbag view on every assignment, regardless of whether the view is the same or not.
I wrote a test to simulate the theft behavior of UINavigationBar. I verified that the test failed before this patch and that it passes after this patch. I also verified the original bug with the internal client's code and example.
Next iteration of our Dynamic Type.
Mimics Apple's new APIs. (UIFontMetrics)
Adds MDCFontScalar to attach curves.
Adds UIFont category to expose fontScaledForCategory methods.
Adds new MDCTypographyScheme with scalable fonts.
Adds sample to demonstrate new curves.
### Context
In working on #6118 I noticed some of the test had the same setup in the _Given_ section. This duplication of code reduces the readability of the code and the test added in #6118 will also use this function to further reduce the duplication of _Given_ in the tests.
### The problem
Some of the test had the same _Given_.
### The fix
Move the duplicate code to it's own function to improve readability and make it so test later can be simpler.
### Related bug
This was noticed when working on #6133
### Context
Currently navigation bar has the horizontal padding of 16 on both sides as a constant. A client may meed to have a spacing of 8 on both sides, 24 on both sides or 20 on one side and 0 on the other. Currently the docs say "_The title view's width will equal the navigation bar's width minus any space consumed by the leading and trailing buttons._" - MDCTitleViewLayoutBehaviorFill but if the titleBehavior is set to this value then it fills the navigation bar's width _minus 32_ minus any space consumed by the leading and trailing buttons.
### The problem
In MDCTitleViewLayoutBehaviorFill it doesn't _Fill_ the navigation bar and isn't customizable.
### The fix
Expose the UIEdgeInset value that is used to layout the titleView.
### Related bug
Closes#6133
Replacing all non-integral, single-precision floating point literals with double-precision values explicitly cast to CGFloat. For example, `0.1f` should become `(CGFloat)0.1`.
Regex used:
```
([0-9]*\.)([0-9]*?)([1-9]+)([0-9]*?)[fF]
```
PiperOrigin-RevId: 220683126
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.
```
This new flag allows a client to remove the 20pt font size restriction on MDCNavigationBar. This restriction was somewhat arbitrary and could cause problems with accessibility for certain font families.
Prior to this change, any font set on MDCNavigationBar would be restricted to 20pt size.
After this change, if the allowAnyTitleFontSize property is enabled on an MDCNavigationBar instance, then the font will be used directly and no sizes will be enforced.
This is required to support internal needs to set a navigation bar title font size of 18.
This restriction is somewhat arbitrary and could cause problems with accessibility for certain font families.
Prior to this change, any font set on MDCNavigationBar would be restricted to 20pt size.
After this change, the font will be used directly and no sizes will be enforced.
This is required to support internal needs to set a navigation bar title font size of 18.
### Context
When setting a font on MDCNavigationBar, we force the font to have a size of 20.
### Prior to this change
We were enforcing the font size by using an older UIFont API - fontWithName:size:. This API does not preserve font descriptor attributes from the provided font, it only preserves the font name and size.
This was resulting in the loss of an important system font descriptor attribute, namely `NSCTFontUIFontDesignTrait` which was set to `NSCTFontUIFontDesignDefault`. This font attribute affects the kerning of fonts when displayed on screen.
### After this change
We are now using the iOS 7 API - fontWithDescriptor:size:. This API preserves all of the underlying font descriptor attributes.
The result of this change is an intentional visual change.
As part of this behavioral change, I've also updated the related unit tests to enforce this behavior in the future.
To see a visual depiction of the change in behavior, open the following two screenshots and flip between them:
Before this fix:

After this fix:

Visual delta:

* Forcing Font size now does save the right FontName for every case.
* typo.
* can't expose a private header.
* mdc_weight should not be used.
* tests are up and running.
* fixing the tests. no support for weight on iOS 8.
* Document why we switched to fontWithName:size.
* Extracting Accessibility out of FeatureHighlightViewController to a mutator.
Tests added.
Example updated.
* Revert "Extracting Accessibility out of FeatureHighlightViewController to a mutator."
This reverts commit 0b5433ebf86366087b240c4dc4992a0603fa73e0.
* Expose title font as a property.
* Updating the documentation.
* Deprecating titleTextAttributes since we are using titleFont property now.
* Add tests for title font property.
* revert deprecation for this PR., update the doc to explain the behavior when using both titleFont and titleTextAttributes.
* Adding more documentation for the behavior of titleTextAttributes and titleFont together.
* Note for deprecation.
* documentation tweeks.
* [NavBar, ButtonBar] Add NavBar tests, fix ButtonBar KVO
ButtonBar was not correctly setting up KVO when it was created with an NSCoder (restored from an
archive). In that case, dealloc would generate an exception and crash. Instead of writing to the
backing iVar during initWithCoder:, the ButtonBar should call through to its setter instead. This
is less safe (because the subclass may not be initialized) but guarantees observing the objects it
is restoring.
Added a simple NavBar encoding test.