135 Commits

Author SHA1 Message Date
Galia Kaufman
9d9bd93847 [Dialogs] Adding accessoryViewHorizontalInset API
The API allows setting horizontal insets for the accessory view that are different from the message. This is most often used for dialogs that have both a message and an accessory view, as demonstrated in the attached example.

Additionally, this example demonstrates how to add an horizontal hairline as shown on the material.io spec for Confirmation Dialogs.

Note:
This new API is needed because clients do not always have control over the view that is being used as an accessory view, or that the view is used in multiple areas in the app, and cannot be customized.
Additionally, there's no way currently to set 0 insets for the accessory view, while still keeping the 24 value insets for the message, which is a relatively common scenario.
PiperOrigin-RevId: 334142026
2020-09-28 06:12:48 -07:00
Alyssa Weiss
bd6484925b Delete deprecated buttonFont for MDCAlert and make all appropriate changes following deletion
PiperOrigin-RevId: 333566191
2020-09-24 12:03:36 -07:00
Alyssa Weiss
8842f55760 Update the testing for the localization snapshot tests.
PiperOrigin-RevId: 332912160
2020-09-21 12:52:20 -07:00
Alyssa Weiss
d40c6d8608 Remove iOS 10+ checks now that the minimum support contract is iOS 10.
PiperOrigin-RevId: 332836975
2020-09-21 06:28:30 -07:00
Bryan Oltman
da4b8f7c7f Fix mdc_elevationDidChangeBlock block parameter types for Xcode 12
PiperOrigin-RevId: 331843566
2020-09-15 13:39:15 -07:00
Galia Kaufman
8bf81b7d0a [Dialogs] Testing trailing actions in reversed vertical order
When actions are vertically aligned, the first trailing or leading action is positioned incorrectly, hiding the second trailing/leading action. This is fixed in a followup change list.

PiperOrigin-RevId: 318875437
2020-06-29 12:59:03 -07:00
Wenyu Zhang
313135ece2 [Dialogs] Add visibleAreaInsets support.
PiperOrigin-RevId: 317137957
2020-06-18 11:01:22 -07:00
Galia Kaufman
ba359990d5 Setting orderVerticalActionsByEmphasis incorrectly calculates top and bottom insets for actions.
PiperOrigin-RevId: 314793489
2020-06-04 13:35:05 -07:00
Galia Kaufman
ea8887e284 [Dialogs] Adding attributed link color API and updating theming extension
PiperOrigin-RevId: 314453930
2020-06-02 20:00:28 -07:00
Galia Kaufman
6bb3ece393 [Dialogs] Adding tappable link support to the alert message
Adding an action API for notifying caller when a message link is tapped.

PiperOrigin-RevId: 314135831
2020-06-01 08:45:13 -07:00
Galia Kaufman
f4fd6d015f [Dialogs] replace the message UILabel type to UITextview
The type of the message in Material Dialogs was switched from UILabel to UITextView, That is done in order to support links in attributed text. We're seeing some differences in the text rendering in dialog snapshots. In some cases, the width of the dialog may also change, which can result in some other elements moving to maintain required spacing from the edges. Based on our testing, we're not expecting any other changes, so please let us know if you find anything unusual.

This change set includes:
* `messageLabel` was renamed to `messageTextView`.
* The UITextView has its editable flag set to false, and all internal padding set to
  zero, to ensure spacing remain the same as it was with UILabel.
* `scrollEnabled` was set to false to ensure text does't scroll when not needed (it
  still enables scrolling when needed: when there's more text than the visible area.)
* `backgroundColor` was set to `clear`. It seems UITextView's default is white, which
   breaks inverted/dark mode support.

Noticeable differences:
* `sizeThatFits` occasionally returns different width for some texts:
   -- Some texts result in a wider layout (ie: dialogs-presented-with-emphasis-buttons.png)
   -- Empty text views may have a non-zero height. Determining zero
      size based on `hasText` before calling `sizeThatFits` resolved the issue.
* Text rendering is slightly different in almost all snapshots.
* Links in attributed texts are rendered differently then before (ie: color).
* In a couple of RTL snapshot tests, I needed to set the RTL test direction before
  setting the message alignment for the test to work properly.

PiperOrigin-RevId: 313607718
2020-05-28 10:03:43 -07:00
Jake Rockland
776d028861 [Dialogs] Allow MDCAlertController to become first responder via its view.
PiperOrigin-RevId: 310506900
2020-05-07 23:07:58 -07:00
Galia Kaufman
b3bf62df4e [Dialogs] Include insets in alignment calculations of long actions
Include insets in horizontal calculations when determining if all buttons fit horizontally. This will allow actions whose title is nearly half of the dialog to be aligned horizontally.

PiperOrigin-RevId: 310331603
2020-05-07 04:10:24 -07:00
Galia Kaufman
67cb856040 [Dialogs] Fixing broken unit test
Fixing the error:
`error: implicit conversion from enumeration type 'enum MDCContentHorizontalAlignment' to different enumeration type 'NSTextAlignment' (aka 'enum NSTextAlignment') [-Werror,-Wenum-conversion]`

PiperOrigin-RevId: 310164335
2020-05-06 09:16:47 -07:00
Galia Kaufman
b3cf4e42e6 Consider the size of the longest action in horizontally justified action alignment - testing if it can fit the available horizontal space to determine if the actions should be aligned vertically.
PiperOrigin-RevId: 309943747
2020-05-05 07:45:14 -07:00
Wenyu Zhang
da54c6f67a [Dialogs] Allow MDCAlertController to become first responder.
PiperOrigin-RevId: 309437429
2020-05-01 11:06:19 -07:00
Iryna Berezan
99d6facc5b No public changes, just a test that reproduces the issue.
PiperOrigin-RevId: 309425831
2020-05-01 10:07:22 -07:00
Galia Kaufman
bffc2c3d07 [Dialogs] Fix incorrect initialization of properties
Three MDCAlertController properties were not initialized during object initialization.
Their initialization during viewDidLoad caused values previously assigned to them to be reverted to default during presentation or theming.
Adding unit tests that reproduce the issue.

PiperOrigin-RevId: 308075191
2020-04-23 10:05:34 -07:00
Galia Kaufman
b98d977309 [Dialogs] Add manual and auto layout accessory view tests.
This CL demonstrates three different ways to present a message with a "Learn More" button under it in an alert. It also demonstrates accessory views with manual and auto layouts.

The 2 auto-layout tests create a view with a label and a button as subviews, and lay them out using constraints. One of them is testing a subclass, while the other adds the button/text directly to the accessory view.

The manual layout test uses the alert's default message property, and uses a button for the accessory view. It then uses the new 'accessoryViewVerticalInset' to customize the space between the message and the button.

Note: Using `sizeToFitContentInBounds:` for snapshot tests is now correctly resizing snapshot tests that were previously too wide (including the snapshot in b/147241131).
PiperOrigin-RevId: 307884732
2020-04-22 13:27:38 -07:00
Galia Kaufman
f7d799a9cf [Dialogs] Using the new Testing target in accessory snapshots.
A followup for cl/305814799 - replacing calls to all private APIs in MDCAlertControllerAccessoryTests.m with the new testing utilities in MDCAlertController+Testing.h

PiperOrigin-RevId: 305878401
2020-04-13 09:22:00 -04:00
Wenyu Zhang
d36b5e8f3d [Dialogs] Add UIPointerInteraction support for buttons..
PiperOrigin-RevId: 305871918
2020-04-10 07:20:14 -07:00
Galia Kaufman
e48d79a9cc [Dialogs] Using the new Testing target in actions snapshots.
A followup for cl/305814799 - replacing calls to all private APIs in MDCAlertControllerActionsTests.m with the new testing utilities in MDCAlertController+Testing.h

Removing the private header since it's no longer needed for testing.

PiperOrigin-RevId: 305865529
2020-04-10 06:11:33 -07:00
Galia Kaufman
666ed14ba0 [Dialogs] Using the new Testing target in insets snapshots.
A followup for cl/305814799 - replacing calls to all private APIs in MDCAlertControllerInsetsTests.m with the new testing utilities in MDCAlertController+Testing.h

PiperOrigin-RevId: 305864413
2020-04-10 06:01:10 -07:00
Galia Kaufman
7346de3ce0 [Dialogs] Using the new Testing target in insets unit tests.
A followup for cl/305814799 - replacing calls to all private APIs in MDCAlertControllerInsetsTests.m with the new testing utilities in MDCAlertController+Testing.h

PiperOrigin-RevId: 305863373
2020-04-10 05:46:11 -07:00
Jeff Verkoeyen
9c32878a48 [Dialogs] Disable broken test.
b/153457451 tracking fix of the test.

PiperOrigin-RevId: 305861929
2020-04-10 05:26:51 -07:00
Galia Kaufman
2e19a8aa7e [Dialogs] Using Testing target in configuration snapshots.
A followup for cl/305814799 - replacing calls to all private APIs in MDCAlertControllerConfigurationsTests.m with the new testing utilities in MDCAlertController+Testing.h

Note: Snapshot diffs affecting the width of snapshot are expected for tests that used non-standard sizing logic and were migrated to use the new sizing API.
PiperOrigin-RevId: 305861786
2020-04-10 05:23:38 -07:00
Galia Kaufman
969f6f5546 [Dialogs] Adding accessory view tests
Adding tests for various views that may be used as a Dialogs accessory view.
The textfield test is not showing a textfield because of issue b/153181102.

PiperOrigin-RevId: 305808160
2020-04-09 19:20:50 -07:00
Iryna Berezan
4a53cc44c2 Add a minimum dialog width.
PiperOrigin-RevId: 304494482
2020-04-02 15:54:16 -07:00
Galia Kaufman
e5b43d2e72 [Dialogs] Size justified-aligned title-icons to fit the alert's width.
To allow a meaningful contentMode setting for the titleIcon image view, the title icon image is sized to fit the alert's width. The height is then adjusted proportionally.

To maintain backward compatibility (and minimize client UI changes), the icon frame size is not adjusted for non-justified alignments.

This is a potential breaking change for clients that use Justified title, however it is unlikely that many clients (if any) would do that, since it's in most cases a bad UI/UX.

PiperOrigin-RevId: 304213073
2020-04-01 10:31:53 -07:00
Vladimir Pomsztein
19a973ff44 [Dialogs] Add support for attributed dialog message text
## Description

Adds attributed text support for the message inside dialogs in order to provide further customizability and allow for a more liberal use of the component

Closes https://github.com/material-components/material-components-ios/pull/9937

COPYBARA_INTEGRATE_REVIEW=https://github.com/material-components/material-components-ios/pull/9937 from blastervla:feature/attributed-dialog-text d271cea6e37319c95dcef22e65182abdc3e4241c
PiperOrigin-RevId: 303768487
2020-03-30 10:23:51 -07:00
Galia Kaufman
a4d690cb1c [Dialogs] Support custom alignment for the title image (independent of title)
Adding support for customizing the alignment of the title icon, independently of the alignment of the title.

To preserve backward compatibility, the default title-icon alignment is the same as the title. We're using the internal _alignIconWithTitle flag to track if the alignment had been implicitly assigned. Once the value is implicitly assigned, the title icon alignment is independent from the title.

## Issues
Closes #9545, #9824.

PiperOrigin-RevId: 303748434
2020-03-30 08:47:44 -07:00
Galia Kaufman
144b2f61dc [Dialogs] Calculate title Insets independently of content insets
## (Visually) Breaking Changes

The padding between the title or title icon, and the actions, when there is no message is now determined by titleInsets.bottom instead of contentInsets.top (no sense in using contentInsets when there is no content).  The actual inset value has is different, and is now 20 (changed from 24), which caused some client scuba diffs.

## Background

Insets calculations of the title and content panes in dialogs were using the same insets values, causing various misalignments.  This is fixed by ensuring that title calculations are using the titleInsets and that content calculations (of the message or accessory view) are using the content insets.

## Additional (non-breaking) misalignment fixes

#### The title Label stretches too long (pink title has no right inset):
```
titletInsets = UIEdgeInsetsMake(24.f, 24.f, 24.f, 24.f);
contentInsets = UIEdgeInsetsMake(10.f, 10.f, 10.f, 10.f);
```
![image](https://user-images.githubusercontent.com/2329102/76694455-6a487280-6649-11ea-96e9-5eca7f37b86d.png)

#### The title label is too short (pink title right inset is too large):
```
titleInsets = UIEdgeInsetsMake(12.f, 12.f, 12.f, 12.f);
```
![image](https://user-images.githubusercontent.com/2329102/76694524-391c7200-664a-11ea-9f81-47389711af7f.png)

#### A dialog with no message has a message pane (yellow):
![image](https://user-images.githubusercontent.com/2329102/76694587-f4dda180-664a-11ea-979f-ecc45b28966e.png)

#### A dialog with no title has a title pane (pink):
![image](https://user-images.githubusercontent.com/2329102/76694595-12127000-664b-11ea-8d22-9d954ad7570b.png)

## Issues
Fixes #9545, #9824.
b/133006455, b/148572399

PiperOrigin-RevId: 303368923
2020-03-27 11:31:24 -07:00
Galia Kaufman
8c7be049e9 [Dialogs] Moving static c helper functions outside of test classes.
PiperOrigin-RevId: 303289751
2020-03-27 02:46:49 -07:00
Galia Kaufman
2a0d0febc5 [Dialogs] Publish Customize API
Publishing titleIcon's customization APIs by moving MDCAlertController+Customize.h from the private/ folder to src/.

PiperOrigin-RevId: 303284455
2020-03-27 01:58:05 -07:00
Galia Kaufman
6b790fe2e1 [Dialogs] Calculate title Insets independently of content insets (resolve scuba diff)
Insets calculations of the title and content panes in dialogs were using the same insets values, causing various misalignments.  This is fixed by ensuring that title calculations are using the titleInsets and that content calculations (of the message or accessory view) are using the content insets.

PiperOrigin-RevId: 303166366
2020-03-26 12:16:07 -07:00
Galia Kaufman
0c1910ec64 [Dialogs] snapshot test for custom insets.
This CL adds a baseline snapshot for how the current dialog works.

The original layout of the Dialogs components used private insets that had all the same value, so many of the insets were used interchangeably. After creating separate insets for different sections, these issues because visible.
The goal of this CL is to demonstrate the issue of accessory view alignment (which is affected by content, title and actions insets). This issue is fixed in a followup cl.

PiperOrigin-RevId: 302970679
2020-03-25 14:32:57 -07:00
Cody Weaver
fdf87c5995 [MDC/ColorScheme] Remove usage of init within MDC.
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
2020-03-25 13:36:51 -07:00
Galia Kaufman
e79828dc5b [Dialogs] Add TitleIcon snapshot tests.
Testing different combinations of configurations that affect the appearance of the title icon:
- title alignment.
- Long, wide & square images.
- Insets.
- LTR/RTL

## Issues
#9824 and #9545.

PiperOrigin-RevId: 302419683
2020-03-23 06:23:27 -07:00
Galia Kaufman
73582da9d8 [Dialogs] Support title icon content mode through custom titleIconImageView.
To setup appearance of `titleIcon`, clients need to setup properties like `contentMode` or `clipsToBound`. Instead of adding individual APIs for these customizations, and since these customizations are not the common case, we're exposing the image view that is backing the `title icon` in the customize header.

* Issues
b/133006455, b/148572399

PiperOrigin-RevId: 302031346
2020-03-20 08:27:14 -07:00
Galia Kaufman
5c24a5dcc6 # Problem
The current snapshot is inaccurate because there is not enough room to layout all the dialog's elements, so spaces between the elements are inaccurate for many snapshots.

# Solution
Applying `sizeAlertToFitContent` before taking a snapshot of all dialogs. This method uses `calculatePreferredContentSizeForBounds:` to let the dialog layout itself correctly, within the given width, and to determine the height it needs to display itself.    The new snapshots have a more realistic layout that is closer to how dialogs should be presented.

PiperOrigin-RevId: 301862389
2020-03-19 11:50:16 -07:00
Galia Kaufman
e2267236b0 [Dialogs] Fix layout of configuration snapshot test.
Sizing dialogs snapshots to correct size in order to better simulate sizing of dialogs on a device.
The previous implementation used `preferredContentSize` which was not updated with the actual size of the snapshot after the dialog has been configured, causing most snapshot to be sized too wide.

This fix is implemented using the `calculatePreferredContentSizeForBounds:` API, which recalculates the dialog height based on the actual snapshot width, resulting in accurate width & height.

PiperOrigin-RevId: 301607700
2020-03-18 09:50:32 -07:00
Galia Kaufman
acdfee53fd
[Dialogs] Fix incorrect vertical layout for uppercase buttons (#9877)
#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
2020-03-16 08:05:07 -04:00
Galia Kaufman
c66e0c307c
[Dialogs] Add snapshots tests for adjustable insets (#9899)
Creating snapshot tests to test the adjustable insets API: titleInsets, titleIconInsets, contentInsets and actionsInsets (Closes #6289).
2020-03-15 19:09:19 -04:00
Galia Kaufman
6ec85ffb6d
[Dialogs] Add a snapshot test for extea long buttons (#9897)
# Description

Adding a snapshot test to demonstrate the truncation of extra long buttons (buttons that are longer than the title). This issue is fixed in PR #9878.

![image](https://user-images.githubusercontent.com/2329102/76674303-3a836700-6584-11ea-87f7-040fcf12bc82.png)

## Issues
Closes #8434
b/137070719, cl/299735845
2020-03-15 12:11:43 -04:00
Galia Kaufman
4c601a5004
Adding a snapshot test to verify correct layout of actions in edge cases found in issue: #8434. (#9875)
Adding a snapshot test to verify correct layout of actions in edge cases found in issue: #8434.
PiperOrigin-RevId: 299739784
2020-03-12 17:57:06 -04:00
Galia Kaufman
9febb9de30
[Dialogs] Refactoring alert actions test (#9886)
Simplifying names of action methods.
PiperOrigin-RevId: 299739784
2020-03-12 14:08:45 -04:00
Galia Kaufman
42584f3f1e
[Dialogs] Allow setting text alignment for alert message text (#9839)
Using NSTextAlignment to customize alignment of the alert's message (Closes #5602).
PiperOrigin-RevId: 298994401
2020-03-12 05:42:18 -04:00
Andrew Overton
1f0f03526d
[Dialogs] Try to fix testActionsAreOrderedByEmphasis snapshot (#9862)
I just tried checking out develop and I got this, which I've seen many times before:
```
Encountered 1 file(s) that should have been pointers, but weren't:
snapshot_test_goldens/goldens_64/MDCAlertControllerActionsTests/testActionsAreOrderedByEmphasis_11_2@2x.png
```
I tried regenerating the snapshot and looking at the comparison on GitHub. I couldn't preview the snapshot. I can't remember if you're supposed to be able to preview the snapshot after _replacing_ a binary file with a Git LFS file...

I looked at [the PR](https://github.com/material-components/material-components-ios/pull/9829/files?short_path=7652328#diff-7652328521a2f11db26e3ab6838365e6) the problematic snapshot was added in and saw that I was able to preview it there. I wasn't expecting this, because up to this point I thought that if you could preview the snapshot in the PR that meant everything was good. I guess not? It said it was a binary file, and not a git LFS file. I also noticed the PR was exported from an internal CL. So I guess if you export a CL to a PR and it has a binary snapshot you can preview it, but that doesn't mean it should be merged.

I tried issuing the following command to fix it:
```
git lfs migrate import --no-rewrite snapshot_test_goldens/goldens_64/MDCAlertControllerActionsTests/testActionsAreOrderedByEmphasis_11_2@2x.png
```
That resulted in 224a322. The commit message said it converted the binary file to a Git LFS file, which is good. However, I still couldn't preview it, and I'm used to using that as a test to make sure I've done it correctly, for better or worse. I decided to just rename the test and generate a new snapshot. That's in 10b7b37. Now GitHub says it's a Git LFS file, and I can preview it, so I think this should solve the issue.
2020-03-09 10:20:34 -04:00
Galia Kaufman
42b2e1ec69
[Dialogs] Adding actions order tests (#9829)
Testing the orderVerticalActionsByEmphasis flag, which determines actions order in vertical layout (b/122654717).

PiperOrigin-RevId: 297348035
2020-03-05 14:15:17 -05:00
Galia Kaufman
64a79b29bf
[Dialogs] Adding alignment snapshot tests (#9801)
PiperOrigin-RevId: 297337448
2020-02-27 12:09:48 -05:00