|
26 | 26 | #import "MDCBottomNavigationBarDelegate.h"
|
27 | 27 | #import "MaterialPalettes.h"
|
28 | 28 | #import "MaterialRipple.h"
|
| 29 | +#import "MaterialShadow.h" |
29 | 30 | #import "MaterialShadowElevations.h"
|
30 | 31 | #import "MaterialShadowLayer.h"
|
31 | 32 | #import "MaterialTypography.h"
|
@@ -72,8 +73,13 @@ @interface MDCBottomNavigationBar () <MDCInkTouchControllerDelegate,
|
72 | 73 | @end
|
73 | 74 |
|
74 | 75 | @implementation MDCBottomNavigationBar
|
| 76 | + |
| 77 | +static BOOL gEnablePerformantShadow = NO; |
| 78 | + |
75 | 79 | @synthesize mdc_overrideBaseElevation = _mdc_overrideBaseElevation;
|
76 | 80 | @synthesize mdc_elevationDidChangeBlock = _mdc_elevationDidChangeBlock;
|
| 81 | +@synthesize shadowsCollection = _shadowsCollection; |
| 82 | +@synthesize elevation = _elevation; |
77 | 83 |
|
78 | 84 | - (instancetype)initWithFrame:(CGRect)frame {
|
79 | 85 | self = [super initWithFrame:frame];
|
@@ -134,11 +140,8 @@ - (void)commonMDCBottomNavigationBarInit {
|
134 | 140 | [_barView addSubview:_itemsLayoutView];
|
135 | 141 |
|
136 | 142 | _itemsLayoutView.accessibilityTraits = UIAccessibilityTraitTabBar;
|
137 |
| - _elevation = MDCShadowElevationBottomNavigationBar; |
138 |
| - [(MDCShadowLayer *)self.layer setElevation:_elevation]; |
139 |
| - UIColor *defaultShadowColor = UIColor.blackColor; |
140 |
| - _shadowColor = defaultShadowColor; |
141 |
| - self.layer.shadowColor = defaultShadowColor.CGColor; |
| 143 | + self.elevation = MDCShadowElevationBottomNavigationBar; |
| 144 | + self.shadowColor = gEnablePerformantShadow ? MDCShadowColor() : UIColor.blackColor; |
142 | 145 | _itemViews = [NSMutableArray array];
|
143 | 146 | _itemTitleFont = [UIFont mdc_standardFontForMaterialTextStyle:MDCFontTextStyleCaption];
|
144 | 147 |
|
@@ -171,6 +174,10 @@ - (void)layoutSubviews {
|
171 | 174 | [self sizeItemsLayoutViewItemsDistributed:YES withBottomNavSize:size containerWidth:size.width];
|
172 | 175 | }
|
173 | 176 | [self layoutItemViews];
|
| 177 | + |
| 178 | + if (gEnablePerformantShadow) { |
| 179 | + [self updateShadow]; |
| 180 | + } |
174 | 181 | }
|
175 | 182 |
|
176 | 183 | - (void)safeAreaInsetsDidChange {
|
@@ -205,16 +212,31 @@ - (CGSize)sizeThatFits:(CGSize)size {
|
205 | 212 | }
|
206 | 213 |
|
207 | 214 | + (Class)layerClass {
|
208 |
| - return [MDCShadowLayer class]; |
| 215 | + if (gEnablePerformantShadow) { |
| 216 | + return [super layerClass]; |
| 217 | + } else { |
| 218 | + return [MDCShadowLayer class]; |
| 219 | + } |
209 | 220 | }
|
210 | 221 |
|
211 | 222 | - (void)setElevation:(MDCShadowElevation)elevation {
|
212 |
| - BOOL elevationChanged = !MDCCGFloatEqual(_elevation, elevation); |
| 223 | + if (MDCCGFloatEqual(_elevation, elevation)) { |
| 224 | + return; |
| 225 | + } |
213 | 226 | _elevation = elevation;
|
214 |
| - [(MDCShadowLayer *)self.layer setElevation:elevation]; |
215 |
| - if (elevationChanged) { |
216 |
| - [self mdc_elevationDidChange]; |
| 227 | + if (gEnablePerformantShadow) { |
| 228 | + [self updateShadow]; |
| 229 | + } else { |
| 230 | + MDCShadowLayer *shadowLayer = (MDCShadowLayer *)self.layer; |
| 231 | + shadowLayer.elevation = elevation; |
217 | 232 | }
|
| 233 | + [self mdc_elevationDidChange]; |
| 234 | +} |
| 235 | + |
| 236 | +- (void)updateShadow { |
| 237 | + MDCConfigureShadowForView(self, |
| 238 | + [self.shadowsCollection shadowForElevation:self.mdc_currentElevation], |
| 239 | + self.shadowColor); |
218 | 240 | }
|
219 | 241 |
|
220 | 242 | - (void)setShadowColor:(UIColor *)shadowColor {
|
@@ -843,6 +865,19 @@ - (CGFloat)mdc_currentElevation {
|
843 | 865 | return self.elevation;
|
844 | 866 | }
|
845 | 867 |
|
| 868 | +- (MDCShadowsCollection *)shadowsCollection { |
| 869 | + if (!_shadowsCollection) { |
| 870 | + _shadowsCollection = MDCShadowsCollectionDefault(); |
| 871 | + } |
| 872 | + return _shadowsCollection; |
| 873 | +} |
| 874 | + |
| 875 | +- (void)setShadowsCollection:(MDCShadowsCollection *)shadowsCollection { |
| 876 | + _shadowsCollection = shadowsCollection; |
| 877 | + |
| 878 | + [self updateShadow]; |
| 879 | +} |
| 880 | + |
846 | 881 | - (void)cancelRippleInItemView:(MDCBottomNavigationItemView *)itemView animated:(BOOL)animated {
|
847 | 882 | if (self.enableRippleBehavior) {
|
848 | 883 | if (animated) {
|
@@ -942,4 +977,14 @@ - (UIPointerStyle *)pointerInteraction:(UIPointerInteraction *)interaction
|
942 | 977 | }
|
943 | 978 | #endif
|
944 | 979 |
|
| 980 | +#pragma mark - Performant Shadow Toggle |
| 981 | + |
| 982 | ++ (void)setEnablePerformantShadow:(BOOL)enable { |
| 983 | + gEnablePerformantShadow = enable; |
| 984 | +} |
| 985 | + |
| 986 | ++ (BOOL)enablePerformantShadow { |
| 987 | + return gEnablePerformantShadow; |
| 988 | +} |
| 989 | + |
945 | 990 | @end
|
0 commit comments