Skip to content

Commit

Permalink
[List] Support vertically centered image views in MDCSelfSizingStereo…
Browse files Browse the repository at this point in the history
…Cell

PiperOrigin-RevId: 349420776
  • Loading branch information
andrewoverton authored and material-automation committed Dec 29, 2020
1 parent 8bd8b29 commit bdeb1f7
Show file tree
Hide file tree
Showing 7 changed files with 247 additions and 109 deletions.
13 changes: 13 additions & 0 deletions components/List/src/MDCSelfSizingStereoCell.h
Expand Up @@ -15,6 +15,7 @@
#import <UIKit/UIKit.h>

#import "MDCBaseCell.h"
#import "MDCSelfSizingStereoCellImageViewVerticalPosition.h"

/**
MDCSelfSizingStereoCell is intended to be an easy to use readymade implementation of a basic
Expand Down Expand Up @@ -42,11 +43,23 @@ __attribute__((objc_subclassing_restricted)) @interface MDCSelfSizingStereoCell
*/
@property(nonatomic, strong, readonly) UIImageView *leadingImageView;

/**
This property influences the positioning of @c leadingImageView. The default value is @c .top.
*/
@property(nonatomic, assign)
MDCSelfSizingStereoCellImageViewVerticalPosition leadingImageViewVerticalPosition;

/**
The UIImageView responsible for displaying the trailing image.
*/
@property(nonatomic, strong, readonly) UIImageView *trailingImageView;

/**
This property influences the positioning of @c trailingImageView. The default value is @c .top.
*/
@property(nonatomic, assign)
MDCSelfSizingStereoCellImageViewVerticalPosition trailingImageViewVerticalPosition;

/**
The UILabel responsible for displaying the title text. By default, `numberOfLines` is set to 0 so
the label wraps and the self-sizing capabilities of the cell are best utilized.
Expand Down
15 changes: 9 additions & 6 deletions components/List/src/MDCSelfSizingStereoCell.m
Expand Up @@ -172,12 +172,15 @@ - (MDCSelfSizingStereoCellLayout *)layoutForCellWidth:(CGFloat)cellWidth {
CGFloat flooredCellWidth = floor(cellWidth);
MDCSelfSizingStereoCellLayout *layout = self.cachedLayouts[@(flooredCellWidth)];
if (!layout) {
layout = [[MDCSelfSizingStereoCellLayout alloc] initWithLeadingImageView:self.leadingImageView
trailingImageView:self.trailingImageView
textContainer:self.textContainer
titleLabel:self.titleLabel
detailLabel:self.detailLabel
cellWidth:flooredCellWidth];
layout = [[MDCSelfSizingStereoCellLayout alloc]
initWithLeadingImageView:self.leadingImageView
leadingImageViewVerticalPosition:self.leadingImageViewVerticalPosition
trailingImageView:self.trailingImageView
trailingImageViewVerticalPosition:self.trailingImageViewVerticalPosition
textContainer:self.textContainer
titleLabel:self.titleLabel
detailLabel:self.detailLabel
cellWidth:flooredCellWidth];
self.cachedLayouts[@(flooredCellWidth)] = layout;
}
return layout;
Expand Down
@@ -0,0 +1,31 @@
// Copyright 2020-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 <UIKit/UIKit.h>

/**
This enum represents different positions for the side image views in an @c
MDCSelfSizingStereoCell.
*/
typedef NS_ENUM(NSUInteger, MDCSelfSizingStereoCellImageViewVerticalPosition) {
/**
This value results in the image view being positioned at the top of the cell.
*/
MDCSelfSizingStereoCellImageViewVerticalPositionTop,
/**
This value results in the image view being positioned in the vertical center of the
cell.
*/
MDCSelfSizingStereoCellImageViewVerticalPositionCenter,
};
1 change: 1 addition & 0 deletions components/List/src/MaterialList.h
Expand Up @@ -15,3 +15,4 @@
#import "MDCBaseCell.h"
#import "MDCSelfSizingLayoutAttributes.h"
#import "MDCSelfSizingStereoCell.h"
#import "MDCSelfSizingStereoCellImageViewVerticalPosition.h"
6 changes: 6 additions & 0 deletions components/List/src/private/MDCSelfSizingStereoCellLayout.h
Expand Up @@ -17,6 +17,8 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

#import "MDCSelfSizingStereoCellImageViewVerticalPosition.h"

@interface MDCSelfSizingStereoCellLayout : NSObject

@property(nonatomic, assign, readonly) CGFloat cellWidth;
Expand All @@ -28,7 +30,11 @@
@property(nonatomic, assign, readonly) CGRect trailingImageViewFrame;

- (instancetype)initWithLeadingImageView:(UIImageView *)leadingImageView
leadingImageViewVerticalPosition:
(MDCSelfSizingStereoCellImageViewVerticalPosition)leadingImageViewVerticalPosition
trailingImageView:(UIImageView *)trailingImageView
trailingImageViewVerticalPosition:
(MDCSelfSizingStereoCellImageViewVerticalPosition)trailingImageViewVerticalPosition
textContainer:(UIView *)textContainer
titleLabel:(UILabel *)titleLabel
detailLabel:(UILabel *)detailLabel
Expand Down

0 comments on commit bdeb1f7

Please sign in to comment.