Skip to content

Commit

Permalink
[Dialogs] Initial Import
Browse files Browse the repository at this point in the history
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
Show file tree
Hide file tree
Showing 22 changed files with 1,193 additions and 3 deletions.
10 changes: 10 additions & 0 deletions MaterialComponents.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ Pod::Spec.new do |s|
ss.dependency "MaterialComponents/Typography"
end

s.subspec "Dialogs" do |ss|
ss.public_header_files = "components/#{ss.base_name}/src/*.h"
ss.source_files = "components/#{ss.base_name}/src/*.{h,m}", "components/#{ss.base_name}/src/private/*.{h,m}"
ss.header_mappings_dir = "components/#{ss.base_name}/src"

ss.dependency "MaterialComponents/Buttons"
ss.dependency "MaterialComponents/ShadowElevations"
ss.dependency "MaterialComponents/ShadowLayer"
end

s.subspec "FlexibleHeader" do |ss|
ss.public_header_files = "components/#{ss.base_name}/src/*.h"
ss.source_files = "components/#{ss.base_name}/src/*.{h,m}", "components/#{ss.base_name}/src/private/*.{h,m}"
Expand Down
6 changes: 6 additions & 0 deletions catalog/MDCCatalog.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
0B4A5E6D1CC9307A00D2AC5D /* MDCCatalogWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B4A5E6C1CC9307A00D2AC5D /* MDCCatalogWindow.swift */; };
403860EF1D24328A00FB8216 /* MDCCatalogTileDataDialogs.m in Sources */ = {isa = PBXBuildFile; fileRef = 403860EE1D24328A00FB8216 /* MDCCatalogTileDataDialogs.m */; };
5D090E571C9AEB8D0061344A /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 5D090E341C9AEB8C0061344A /* Localizable.strings */; };
664524B71C6BA62A001ADBF8 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 664524B61C6BA62A001ADBF8 /* AppDelegate.swift */; };
664524B91C6BA62A001ADBF8 /* MDCNodeListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 664524B81C6BA62A001ADBF8 /* MDCNodeListViewController.swift */; };
Expand Down Expand Up @@ -41,6 +42,8 @@
/* Begin PBXFileReference section */
0B4A5E6C1CC9307A00D2AC5D /* MDCCatalogWindow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MDCCatalogWindow.swift; sourceTree = "<group>"; };
1A55EA1CC69E40D5EF866144 /* Pods_MDCCatalog.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_MDCCatalog.framework; sourceTree = BUILT_PRODUCTS_DIR; };
403860ED1D24328A00FB8216 /* MDCCatalogTileDataDialogs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MDCCatalogTileDataDialogs.h; sourceTree = "<group>"; };
403860EE1D24328A00FB8216 /* MDCCatalogTileDataDialogs.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MDCCatalogTileDataDialogs.m; sourceTree = "<group>"; };
5D090E351C9AEB8C0061344A /* ar */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ar; path = ar.lproj/Localizable.strings; sourceTree = "<group>"; };
5D090E361C9AEB8C0061344A /* ca */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ca; path = ca.lproj/Localizable.strings; sourceTree = "<group>"; };
5D090E371C9AEB8C0061344A /* cs */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = cs; path = cs.lproj/Localizable.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -218,6 +221,8 @@
DE19446E1CBD9E40009E0321 /* MDCCatalogTileDataButtons.m */,
DE7A17C61CCAC1F700B66230 /* MDCCatalogTileDataCollections.h */,
DE7A17C41CCAC1EA00B66230 /* MDCCatalogTileDataCollections.m */,
403860ED1D24328A00FB8216 /* MDCCatalogTileDataDialogs.h */,
403860EE1D24328A00FB8216 /* MDCCatalogTileDataDialogs.m */,
DE19446F1CBD9E40009E0321 /* MDCCatalogTileDataFlexibleHeader.h */,
DE1944701CBD9E40009E0321 /* MDCCatalogTileDataFlexibleHeader.m */,
DE1944711CBD9E40009E0321 /* MDCCatalogTileDataHeaderStackView.h */,
Expand Down Expand Up @@ -435,6 +440,7 @@
664524B71C6BA62A001ADBF8 /* AppDelegate.swift in Sources */,
DE1944941CBD9E40009E0321 /* MDCCatalogTileDataTypography.m in Sources */,
DEF64EA41C8DEE83007C4EA0 /* MDCCatalogCollectionViewCell.swift in Sources */,
403860EF1D24328A00FB8216 /* MDCCatalogTileDataDialogs.m in Sources */,
DE1944861CBD9E40009E0321 /* MDCCatalogTileData.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
27 changes: 27 additions & 0 deletions catalog/MDCCatalog/MDCCatalogTileDataDialogs.h
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
70 changes: 70 additions & 0 deletions catalog/MDCCatalog/MDCCatalogTileDataDialogs.m
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
7 changes: 6 additions & 1 deletion catalog/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ PODS:
- MaterialComponents/CollectionCells (= 12.0.1)
- MaterialComponents/CollectionLayoutAttributes (= 12.0.1)
- MaterialComponents/Collections (= 12.0.1)
- MaterialComponents/Dialogs (= 12.0.1)
- MaterialComponents/FlexibleHeader (= 12.0.1)
- MaterialComponents/FontDiskLoader (= 12.0.1)
- MaterialComponents/HeaderStackView (= 12.0.1)
Expand Down Expand Up @@ -63,6 +64,10 @@ PODS:
- MaterialComponents/ShadowElevations
- MaterialComponents/ShadowLayer
- MaterialComponents/Typography
- MaterialComponents/Dialogs (12.0.1):
- MaterialComponents/Buttons
- MaterialComponents/ShadowElevations
- MaterialComponents/ShadowLayer
- MaterialComponents/FlexibleHeader (12.0.1)
- MaterialComponents/FontDiskLoader (12.0.1)
- MaterialComponents/HeaderStackView (12.0.1)
Expand Down Expand Up @@ -155,7 +160,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
CatalogByConvention: 0137d280781667dd3d856a14cdf507f5ac8eedc0
MaterialComponents: ed704822f99f7286a3e5d2d4cc7ffdeac044c211
MaterialComponents: 3afee35d1cd8bc2196922dd9e5f33bdb89a18cd3
MaterialComponentsCatalog: c2911e8ad9f380350107f124f88a43b9fe012d19
MaterialComponentsUnitTests: 03755d2a184c1d21a66c86c0e333d7b087e2f662

Expand Down
109 changes: 109 additions & 0 deletions components/Dialogs/README.md
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 components/Dialogs/examples/DialogsTypicalUseViewController.m
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
Loading

0 comments on commit 3742dd4

Please sign in to comment.