Skip to content

Commit 0f99d29

Browse files
afweissmaterial-automation
authored andcommitted
Only initialize blur effect view if it is not hidden.
PiperOrigin-RevId: 363475874
1 parent bf65286 commit 0f99d29

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

components/BottomNavigation/src/MDCBottomNavigationBar.m

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,6 @@ - (void)commonMDCBottomNavigationBarInit {
117117
}
118118
}
119119

120-
UIBlurEffect *defaultBlurEffect = [UIBlurEffect effectWithStyle:_backgroundBlurEffectStyle];
121-
_blurEffectView = [[UIVisualEffectView alloc] initWithEffect:defaultBlurEffect];
122-
_blurEffectView.hidden = !_backgroundBlurEnabled;
123-
_blurEffectView.autoresizingMask =
124-
(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
125-
[self addSubview:_blurEffectView]; // Needs to always be at the bottom
126-
127120
_barView = [[UIView alloc] init];
128121
_barView.autoresizingMask =
129122
(UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin);
@@ -165,7 +158,9 @@ - (void)layoutSubviews {
165158
[super layoutSubviews];
166159

167160
CGRect standardBounds = CGRectStandardize(self.bounds);
168-
self.blurEffectView.frame = standardBounds;
161+
if (self.blurEffectView) {
162+
self.blurEffectView.frame = standardBounds;
163+
}
169164
self.barView.frame = standardBounds;
170165
self.layer.shadowColor = self.shadowColor.CGColor;
171166

@@ -775,7 +770,9 @@ - (void)setBackgroundBlurEffectStyle:(UIBlurEffectStyle)backgroundBlurEffectStyl
775770
return;
776771
}
777772
_backgroundBlurEffectStyle = backgroundBlurEffectStyle;
778-
self.blurEffectView.effect = [UIBlurEffect effectWithStyle:_backgroundBlurEffectStyle];
773+
if (self.blurEffectView) {
774+
self.blurEffectView.effect = [UIBlurEffect effectWithStyle:_backgroundBlurEffectStyle];
775+
}
779776
}
780777

781778
- (void)setBackgroundBlurEnabled:(BOOL)backgroundBlurEnabled {
@@ -784,7 +781,17 @@ - (void)setBackgroundBlurEnabled:(BOOL)backgroundBlurEnabled {
784781
}
785782
_backgroundBlurEnabled = backgroundBlurEnabled;
786783

787-
self.blurEffectView.hidden = !_backgroundBlurEnabled;
784+
if (_backgroundBlurEnabled & !self.blurEffectView) {
785+
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:_backgroundBlurEffectStyle];
786+
self.blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
787+
self.blurEffectView.hidden = !_backgroundBlurEnabled;
788+
self.blurEffectView.autoresizingMask =
789+
(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
790+
[self insertSubview:self.blurEffectView atIndex:0]; // Needs to always be at the bottom
791+
self.blurEffectView.frame = CGRectStandardize(self.bounds);
792+
} else if (self.blurEffectView) {
793+
self.blurEffectView.hidden = !_backgroundBlurEnabled;
794+
}
788795
}
789796

790797
- (void)setAlignment:(MDCBottomNavigationBarAlignment)alignment {

0 commit comments

Comments
 (0)