mirror of
https://github.com/material-components/material-components-ios.git
synced 2026-02-20 08:27:32 +08:00
Closes https://github.com/material-components/material-components-ios/issues/7062 Reference: cl/241537224 Layout MDC Dialogs correctly for tall fonts The MDC Dialog layout code had some hard coded assumptions about the amount of vertical space to allocate for action buttons that were violated when using taller fonts such as Urdu with large Dynamic Type sizes. There was also a related bug where vertical vs. horizontal action button layout was calculated in two different places. Snapshot test before change: <img width="569" alt="snapshot_test_goldens_goldens_64_MDCAlertControllerLocalizationSnapshotTests_testPreferredContentSizeWithNotoNastaliqUrdu_11_2@2x_Before_01dd7fb1a36bc24b27e05c1079c6420994c9f904" src="https://user-images.githubusercontent.com/8836258/56166158-dc7c8700-5fa2-11e9-8fa1-ed4dbfdc947b.png"> Snapshot test result after change: <img width="569" alt="snapshot_test_goldens_goldens_64_MDCAlertControllerLocalizationSnapshotTests_testPreferredContentSizeWithNotoNastaliqUrdu_11_2@2x_After_78d3fd9172a202641400c0536a9c2e3a33b0455b" src="https://user-images.githubusercontent.com/8836258/56166182-e7371c00-5fa2-11e9-976e-4f9c93efc98f.png"> Example screenshot before change:  Example screenshot after change: 
100 lines
4.0 KiB
Objective-C
100 lines
4.0 KiB
Objective-C
// Copyright 2019-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.
|
|
|
|
#import "MaterialButtons.h"
|
|
#import "MaterialDialogs.h"
|
|
|
|
@interface DialogsTallTextAlertExampleViewController : UIViewController
|
|
|
|
@end
|
|
|
|
@interface DialogsTallTextAlertExampleViewController () <MDCDialogPresentationControllerDelegate>
|
|
|
|
@property(nonatomic, strong) MDCDialogTransitionController *transitionController;
|
|
|
|
@end
|
|
@implementation DialogsTallTextAlertExampleViewController
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
|
|
// We must create and store a strong reference to the transitionController.
|
|
// A presented view controller will set this object as its transitioning delegate.
|
|
self.transitionController = [[MDCDialogTransitionController alloc] init];
|
|
|
|
MDCButton *presentButton = [[MDCButton alloc] initWithFrame:CGRectZero];
|
|
[presentButton setTitle:[NSString stringWithFormat:@"Dialog with large Urdu text"]
|
|
forState:UIControlStateNormal];
|
|
[presentButton addTarget:self
|
|
action:@selector(didTapPresent:)
|
|
forControlEvents:UIControlEventTouchUpInside];
|
|
[self.view addSubview:presentButton];
|
|
presentButton.translatesAutoresizingMaskIntoConstraints = NO;
|
|
|
|
[self.view addConstraints:@[
|
|
[NSLayoutConstraint constraintWithItem:self.view
|
|
attribute:NSLayoutAttributeCenterX
|
|
relatedBy:NSLayoutRelationEqual
|
|
toItem:presentButton
|
|
attribute:NSLayoutAttributeCenterX
|
|
multiplier:1
|
|
constant:0],
|
|
[NSLayoutConstraint constraintWithItem:self.view
|
|
attribute:NSLayoutAttributeCenterY
|
|
relatedBy:NSLayoutRelationEqual
|
|
toItem:presentButton
|
|
attribute:NSLayoutAttributeCenterY
|
|
multiplier:1
|
|
constant:0],
|
|
]];
|
|
}
|
|
|
|
- (IBAction)didTapPresent:(id)sender {
|
|
NSString *networkFailureInUrdu = @"براہ کرم اپنا نیٹ ورک کنکشن چیک کریں اور دوبارہ کوشش کریں۔";
|
|
MDCAlertController *alert = [MDCAlertController alertControllerWithTitle:nil
|
|
message:networkFailureInUrdu];
|
|
NSString *urduFontName = @"NotoNastaliqUrdu";
|
|
UIFont *dialogBodyFont;
|
|
UIFont *dialogButtonFont;
|
|
if (@available(iOS 11, *)) {
|
|
// Noto Nastaliq Urdu was added in iOS 11, and is an extremely tall
|
|
// font for any given nominal point size.
|
|
dialogBodyFont = [UIFont fontWithName:urduFontName size:20.0];
|
|
dialogButtonFont = [UIFont fontWithName:urduFontName size:20.0];
|
|
} else {
|
|
dialogBodyFont = [UIFont systemFontOfSize:20.0];
|
|
dialogButtonFont = [UIFont systemFontOfSize:20.0];
|
|
}
|
|
alert.messageFont = dialogBodyFont;
|
|
alert.buttonFont = dialogButtonFont;
|
|
|
|
MDCAlertAction *retryAction = [MDCAlertAction actionWithTitle:@"دوبارہ کوشش کریں" handler:nil];
|
|
MDCAlertAction *cancelAction = [MDCAlertAction actionWithTitle:@"منسوخ کریں" handler:nil];
|
|
[alert addAction:retryAction];
|
|
[alert addAction:cancelAction];
|
|
[self presentViewController:alert animated:YES completion:nil];
|
|
}
|
|
|
|
#pragma mark - CatalogByConvention
|
|
|
|
+ (NSDictionary *)catalogMetadata {
|
|
return @{
|
|
@"breadcrumbs" : @[ @"Dialogs", @"Dialog with Tall Text" ],
|
|
@"primaryDemo" : @NO,
|
|
@"presentable" : @NO,
|
|
};
|
|
}
|
|
|
|
@end
|