Skip to content

Commit

Permalink
[Dialogs] Adding customized interface orientations and transition sty…
Browse files Browse the repository at this point in the history
…le support to the alert dialog.

Adding APIs to customize interface orientations and transition style.

PiperOrigin-RevId: 352847879
  • Loading branch information
Nobody authored and material-automation committed Jan 20, 2021
1 parent e76f674 commit a9b6ca1
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 14 deletions.
34 changes: 31 additions & 3 deletions components/Dialogs/src/MDCAlertController.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#import <CoreGraphics/CoreGraphics.h>
#import <UIKit/UIKit.h>

#import "MaterialButtons.h"
// TODO(b/151929968): Delete import of delegate headers when client code has been migrated to no
// longer import delegates as transitive dependencies.
#import "MDCAlertControllerDelegate.h"
#import "MaterialElevation.h"
#import "MaterialShadowElevations.h"

#import <CoreGraphics/CoreGraphics.h>
#import <UIKit/UIKit.h>

@class MDCAlertAction;
@class MDCAlertController;
@protocol MDCAlertControllerDelegate;
Expand Down Expand Up @@ -388,6 +388,34 @@ typedef NS_ENUM(NSInteger, MDCContentHorizontalAlignment) {
*/
@property(nonatomic, assign) BOOL orderVerticalActionsByEmphasis;

/**
A Boolean value that indicates whether the alert's contents autorotates.
Defaults to UIKit's shouldAutorotate.
*/
@property(nonatomic) BOOL shouldAutorotateOverride;

/**
A bit mask that specifies which orientations the view controller supports.
Defaults to UIKit's supportedInterfaceOrientations.
*/
@property(nonatomic) UIInterfaceOrientationMask supportedInterfaceOrientationsOverride;

/**
The interface orientation to use when presenting the alert.
Defaults to UIKit's preferredInterfaceOrientationForPresentation.
*/
@property(nonatomic) UIInterfaceOrientation preferredInterfaceOrientationForPresentationOverride;

/**
The transition style to use when presenting the view controller override.
Defaults to UIKit's modalTransitionStyle.
*/
@property(nonatomic) UIModalTransitionStyle modalTransitionStyleOverride;

@end

#pragma mark - MDCAlertAction
Expand Down
36 changes: 25 additions & 11 deletions components/Dialogs/src/MDCAlertController.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#import "MDCAlertController.h"

#import "MaterialButtons.h"
#import "MDCAlertController+Customize.h"
#import "MDCAlertControllerDelegate.h"
#import "MDCAlertControllerView.h"
#import "MDCDialogPresentationController.h"
#import "MDCDialogTransitionController.h"
#import "UIViewController+MaterialDialogs.h"
#import "MaterialTypography.h"
#import "MaterialMath.h"
#import <MDFInternationalization/MDFInternationalization.h>

#import "private/MDCAlertActionManager.h"
#import "private/MDCAlertControllerView+Private.h"
#import "private/MaterialDialogsStrings.h"
#import "private/MaterialDialogsStrings_table.h"
#import "MaterialDialogs.h"
#import "MaterialElevation.h"
#import "MaterialShadowElevations.h"
#import "MaterialMath.h"

// The Bundle for string resources.
static NSString *const kMaterialDialogsBundle = @"MaterialDialogs.bundle";
Expand Down Expand Up @@ -180,6 +173,11 @@ - (nonnull instancetype)initWithTitle:(nullable NSString *)title {
_adjustsFontForContentSizeCategoryWhenScaledFontIsUnavailable = YES;
_shadowColor = UIColor.blackColor;
_mdc_overrideBaseElevation = -1;
_shouldAutorotateOverride = super.shouldAutorotate;
_supportedInterfaceOrientationsOverride = super.supportedInterfaceOrientations;
_preferredInterfaceOrientationForPresentationOverride =
super.preferredInterfaceOrientationForPresentation;
_modalTransitionStyleOverride = super.modalTransitionStyle;

super.transitioningDelegate = _transitionController;
super.modalPresentationStyle = UIModalPresentationCustom;
Expand Down Expand Up @@ -740,6 +738,22 @@ - (void)viewWillTransitionToSize:(CGSize)size
completion:nil];
}

- (BOOL)shouldAutorotate {
return _shouldAutorotateOverride;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return _supportedInterfaceOrientationsOverride;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return _preferredInterfaceOrientationForPresentationOverride;
}

- (UIModalTransitionStyle)modalTransitionStyle {
return _modalTransitionStyleOverride;
}

#pragma mark - Resource bundle

+ (NSBundle *)bundle {
Expand Down

0 comments on commit a9b6ca1

Please sign in to comment.