Index: ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrome.h |
diff --git a/ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrome.h b/ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrome.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a06fc18d6522e71a6b53f7f2268a728f7387c955 |
--- /dev/null |
+++ b/ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrome.h |
@@ -0,0 +1,46 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef IOS_CHROME_BROWSER_UI_COLLECTION_VIEW_CELLS_MDCCOLLECTIONVIEWCELL_CHROME_H_ |
+#define IOS_CHROME_BROWSER_UI_COLLECTION_VIEW_CELLS_MDCCOLLECTIONVIEWCELL_CHROME_H_ |
+ |
+#import <CoreGraphics/CoreGraphics.h> |
+ |
+#import "ios/third_party/material_components_ios/src/components/CollectionCells/src/MaterialCollectionCells.h" |
+ |
+@class CollectionViewItem; |
+ |
+// Augments MDCCollectionViewCell for use in conjunction with |
+// CollectionViewItem. |
+@interface MDCCollectionViewCell (Chrome) |
+ |
+// Returns the height this class of cell would need to be to fit within |
+// |targetWidth|, configured by |item|. The returned height is calculated by |
+// Auto Layout so that the contents of the cell could fit within the |
+// |targetWidth|. |
+// If the cell contains multi-line labels, make sure to update the |
+// |preferredMaxLayoutWidth| in -layoutSubviews like so: |
+// |
+// @implementation MyCell |
+// |
+// - (void)layoutSubView { |
+// [super layoutSubviews]; |
+// |
+// // Adjust the text label preferredMaxLayoutWidth when the parent's width |
+// // changes, for instance on screen rotation. |
+// CGFloat parentWidth = CGRectGetWidth(self.contentView.bounds); |
+// _textLabel.preferredMaxLayoutWidth = parentWidth - 2 * kHorizontalPadding; |
+// |
+// // Re-layout with the new preferred width to allow the label to adjust its |
+// // height. |
+// [super layoutSubviews]; |
+// } |
+// |
+// @end |
++ (CGFloat)cr_preferredHeightForWidth:(CGFloat)targetWidth |
+ forItem:(CollectionViewItem*)item; |
+ |
+@end |
+ |
+#endif // IOS_CHROME_BROWSER_UI_COLLECTION_VIEW_CELLS_MDCCOLLECTIONVIEWCELL_CHROME_H_ |