-
Notifications
You must be signed in to change notification settings - Fork 946
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Initial import of our modal presentation controller and transition controller. The interfaces have been previously reviewed in our API Review process. This will land on the branch feature-dialog. Test Plan: Example added to catalog. Reviewers: randallli, cjcox, ajsecord, O1 Material components iOS Reviewed By: ajsecord, O1 Material components iOS Subscribers: samnm, randallli Tags: #material_components_ios Differential Revision: http://codereview.cc/D1066
- Loading branch information
Ian Gordon
committed
Jul 14, 2016
1 parent
a82bd86
commit 3742dd4
Showing
22 changed files
with
1,193 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
Copyright 2016-present Google Inc. 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 <UIKit/UIKit.h> | ||
|
||
#import "MDCCatalogTileData.h" | ||
|
||
// TODO: Consider updated naming. | ||
// https://github.com/google/material-components-ios/issues/620 | ||
@interface MDCCatalogTileDataDialogs : MDCCatalogTileData | ||
|
||
+ (UIImage *)drawTileImage:(CGRect)frame; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
Copyright 2016-present Google Inc. 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 "MDCCatalogTileDataDialogs.h" | ||
|
||
@implementation MDCCatalogTileDataDialogs | ||
|
||
+ (UIImage*)drawTileImage:(CGRect)frame { | ||
void (^drawBlock)(CGRect) = ^(CGRect drawBlockFrame) { | ||
[self draw:CGRectMake(0, 0, drawBlockFrame.size.width, drawBlockFrame.size.height)]; | ||
}; | ||
return [self drawImageWithFrame:frame drawBlock:drawBlock]; | ||
} | ||
|
||
// TODO: Replace with Dialog-specific Tile drawing code | ||
/* Auto-generated code using PaintCode and formatted with clang-format. */ | ||
#pragma clang diagnostic push | ||
#pragma clang diagnostic ignored "-Wconversion" | ||
+ (void)draw:(CGRect)frame { | ||
CGContextRef context = UIGraphicsGetCurrentContext(); | ||
|
||
UIColor* fillColor = [UIColor colorWithRed:0.077 green:0.591 blue:0.945 alpha:1]; | ||
|
||
CGRect group = CGRectMake( | ||
CGRectGetMinX(frame) + floor((CGRectGetWidth(frame) - 77.75) * 0.22200 + 0.02) + 0.48, | ||
CGRectGetMinY(frame) + floor((CGRectGetHeight(frame) - 24.25) * 0.30382 + 0.47) + 0.03, 77.75, | ||
24.25); | ||
{ | ||
CGContextSaveGState(context); | ||
CGContextSetAlpha(context, 0.95); | ||
CGContextBeginTransparencyLayer(context, NULL); | ||
|
||
UIBezierPath* rectanglePath = | ||
[UIBezierPath bezierPathWithRoundedRect:CGRectMake(CGRectGetMinX(group), | ||
CGRectGetMinY(group), 77.75, 24.25) | ||
cornerRadius:3.4]; | ||
[fillColor setFill]; | ||
[rectanglePath fill]; | ||
|
||
CGContextEndTransparencyLayer(context); | ||
CGContextRestoreGState(context); | ||
} | ||
|
||
UIBezierPath* ovalPath = [UIBezierPath | ||
bezierPathWithOvalInRect:CGRectMake( | ||
CGRectGetMinX(frame) + | ||
floor((CGRectGetWidth(frame) - 49.8) * 0.82308 - 0.25) + | ||
0.75, | ||
CGRectGetMinY(frame) + | ||
floor((CGRectGetHeight(frame) - 49.7) * 0.25641 + 0.2) + 0.3, | ||
49.8, 49.7)]; | ||
[fillColor setFill]; | ||
[ovalPath fill]; | ||
} | ||
#pragma clang diagnostic pop | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
--- | ||
title: "Dialogs" | ||
layout: detail | ||
section: components | ||
excerpt: "The Dialogs component implements the Material Design specifications for modal presentations." | ||
--- | ||
|
||
# Dialogs | ||
|
||
Dialogs provides a presentation controller that will display a modal dialog according to the | ||
material spec. | ||
|
||
### Material Design Specifications | ||
|
||
<ul class="icon-list"> | ||
<li class="icon-link"><a href="https://material.google.com/components/dialogs.html">Dialogs</a></li> | ||
</ul> | ||
|
||
### Dialogs Classes | ||
|
||
#### Dialogs Presentation Controller and Transition Controller | ||
|
||
Dialogs is comprised of two classes: MDCDialogPresentationController and | ||
MDCDialogTransitionController. These allow the presentation of view controllers in a material | ||
specificed manner. MDCDialogPresentationController is a subclass of UIPresentationController | ||
that observes the presented view controller for preferred content size. | ||
MDCDialogTransitionController implements UIViewControllerAnimatedTransitioning and | ||
UIViewControllerTransitioningDelegate to vend the presentation controller during the transition. | ||
|
||
## Installation | ||
|
||
### Requirements | ||
|
||
- Xcode 7.0 or higher. | ||
- iOS SDK version 8.0 or higher. | ||
|
||
### Installation with CocoaPods | ||
|
||
To add this component to your Xcode project using CocoaPods, add the following to your `Podfile`: | ||
|
||
~~~ | ||
pod 'MaterialComponents/Dialogs' | ||
~~~ | ||
|
||
Then, run the following command: | ||
|
||
~~~ bash | ||
pod install | ||
~~~ | ||
|
||
- - - | ||
|
||
## Usage | ||
|
||
To display a modal using MaterialDialogs you set two properties on the view controller to be | ||
presentented. Set modalPresentationStyle to UIModalPresentationCustom and set | ||
transitioningDelegate to and instance of MDCDialogTransitionController. Then you present the | ||
view controller from the root controller to display it as a modal dialog. | ||
|
||
### Importing | ||
|
||
Before using Dialogs, you'll need to import it: | ||
|
||
#### Objective-C | ||
|
||
~~~ objc | ||
#import "MaterialDialogs.h" | ||
~~~ | ||
|
||
#### Swift | ||
|
||
~~~ swift | ||
import MaterialComponents | ||
~~~ | ||
|
||
## Examples | ||
|
||
### Display a modal dialog | ||
|
||
#### Objective-C | ||
|
||
~~~ objc | ||
// self is the presenting view controller and which has the following property | ||
// defined to keep a reference to the transition controller. | ||
@property(nonatomic, strong) MDCDialogTransitionController *dialogTransitionController; | ||
|
||
// To present the dialog | ||
self.dialogTransitionController = [[MDCDialogTransitionController alloc] init]; | ||
modalDialogViewController.modalPresentationStyle = UIModalPresentationCustom; | ||
modalDialogViewController.transitioningDelegate = self.dialogTransitionController; | ||
[self presentViewController:myDialogViewController animated:YES completion:...]; | ||
|
||
~~~ | ||
#### Swift | ||
~~~ swift | ||
// The following is called from the presenting view controller and has the | ||
// following variable defined to keep a reference to the presentation | ||
// controller. | ||
strong var dialogTransitionController: MDCDialogTransitionController | ||
// To present the dialog | ||
dialogTransitionController = MDCDialogTransitionController() | ||
modalDialogViewController.modalPresentationStyle = UIModalPresentationCustom | ||
modalDialogViewController.transitioningDelegate = dialogTransitionController | ||
presentViewController(myDialogViewController animated:YES ...) | ||
~~~ |
60 changes: 60 additions & 0 deletions
60
components/Dialogs/examples/DialogsTypicalUseViewController.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
Copyright 2016-present Google Inc. 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 "DialogsTypicalUseSupplemental.h" | ||
|
||
#import "MaterialButtons.h" | ||
#import "MaterialDialogs.h" | ||
|
||
@interface DialogsTypicalUseViewController () | ||
|
||
@property(nonatomic, strong) MDCDialogTransitionController *transitionController; | ||
|
||
@end | ||
|
||
@implementation DialogsTypicalUseViewController | ||
|
||
- (void)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]; | ||
} | ||
|
||
- (IBAction)didTapProgrammatic:(id)sender { | ||
UIViewController *viewController = | ||
[[ProgrammaticViewController alloc] initWithNibName:nil bundle:nil]; | ||
viewController.modalPresentationStyle = UIModalPresentationCustom; | ||
viewController.transitioningDelegate = self.transitionController; | ||
|
||
[self presentViewController:viewController animated:YES completion:NULL]; | ||
} | ||
|
||
- (IBAction)didTapStoryboard:(id)sender { | ||
// If you are using this code outside of the MDCCatalog in your own app, your bundle may be nil. | ||
NSBundle *bundle = [NSBundle bundleForClass:[self class]]; | ||
UIStoryboard *storyboard = | ||
[UIStoryboard storyboardWithName:@"DialogWithPreferredContentSize" bundle:bundle]; | ||
NSString *identifier = @"DialogID"; | ||
|
||
UIViewController *viewController = | ||
[storyboard instantiateViewControllerWithIdentifier:identifier]; | ||
viewController.modalPresentationStyle = UIModalPresentationCustom; | ||
viewController.transitioningDelegate = self.transitionController; | ||
|
||
[self presentViewController:viewController animated:YES completion:NULL]; | ||
} | ||
|
||
@end |
Oops, something went wrong.